@@ -600,6 +600,7 @@ function rewrite_apply_exprargs!(ir::IRCode, todo::Vector{Pair{Int, Any}}, idx::
600
600
argexprs:: Vector{Any} , atypes:: Vector{Any} , arginfos:: Vector{Any} ,
601
601
arg_start:: Int , istate:: InliningState )
602
602
603
+ flag = ir. stmts[idx][:flag ]
603
604
new_argexprs = Any[argexprs[arg_start]]
604
605
new_atypes = Any[atypes[arg_start]]
605
606
# loop over original arguments and flatten any known iterators
@@ -655,8 +656,9 @@ function rewrite_apply_exprargs!(ir::IRCode, todo::Vector{Pair{Int, Any}}, idx::
655
656
info = call. info
656
657
handled = false
657
658
if isa (info, ConstCallInfo)
658
- if maybe_handle_const_call! (ir, state1. id, new_stmt, info, new_sig,
659
- call. rt, istate, false , todo)
659
+ if ! is_stmt_noinline (flag) && maybe_handle_const_call! (
660
+ ir, state1. id, new_stmt, info, new_sig,call. rt, istate, flag, false , todo)
661
+
660
662
handled = true
661
663
else
662
664
info = info. call
@@ -667,7 +669,7 @@ function rewrite_apply_exprargs!(ir::IRCode, todo::Vector{Pair{Int, Any}}, idx::
667
669
MethodMatchInfo[info] : info. matches
668
670
# See if we can inline this call to `iterate`
669
671
analyze_single_call! (ir, todo, state1. id, new_stmt,
670
- new_sig, call. rt, info, istate)
672
+ new_sig, call. rt, info, istate, flag )
671
673
end
672
674
if i != length (thisarginfo. each)
673
675
valT = getfield_tfunc (call. rt, Const (1 ))
@@ -716,16 +718,16 @@ function compileable_specialization(et::Union{EdgeTracker, Nothing}, result::Inf
716
718
return mi
717
719
end
718
720
719
- function resolve_todo (todo:: InliningTodo , state:: InliningState )
720
- spec = todo. spec:: DelayedInliningSpec
721
+ function resolve_todo (todo:: InliningTodo , state:: InliningState , flag :: UInt8 )
722
+ (; match) = todo. spec:: DelayedInliningSpec
721
723
722
724
# XXX : update_valid_age!(min_valid[1], max_valid[1], sv)
723
725
isconst, src = false , nothing
724
- if isa (spec . match, InferenceResult)
725
- let inferred_src = spec . match. src
726
+ if isa (match, InferenceResult)
727
+ let inferred_src = match. src
726
728
if isa (inferred_src, Const)
727
729
if ! is_inlineable_constant (inferred_src. val)
728
- return compileable_specialization (state. et, spec . match)
730
+ return compileable_specialization (state. et, match)
729
731
end
730
732
isconst, src = true , quoted (inferred_src. val)
731
733
else
@@ -753,12 +755,10 @@ function resolve_todo(todo::InliningTodo, state::InliningState)
753
755
return ConstantCase (src)
754
756
end
755
757
756
- if src != = nothing
757
- src = state. policy (src)
758
- end
758
+ src = state. policy (src, flag, match)
759
759
760
760
if src === nothing
761
- return compileable_specialization (et, spec . match)
761
+ return compileable_specialization (et, match)
762
762
end
763
763
764
764
if isa (src, IRCode)
@@ -769,17 +769,9 @@ function resolve_todo(todo::InliningTodo, state::InliningState)
769
769
return InliningTodo (todo. mi, src)
770
770
end
771
771
772
- function resolve_todo (todo:: UnionSplit , state:: InliningState )
772
+ function resolve_todo (todo:: UnionSplit , state:: InliningState , flag :: UInt8 )
773
773
UnionSplit (todo. fully_covered, todo. atype,
774
- Pair{Any,Any}[sig=> resolve_todo (item, state) for (sig, item) in todo. cases])
775
- end
776
-
777
- function resolve_todo! (todo:: Vector{Pair{Int, Any}} , state:: InliningState )
778
- for i = 1 : length (todo)
779
- idx, item = todo[i]
780
- todo[i] = idx=> resolve_todo (item, state)
781
- end
782
- todo
774
+ Pair{Any,Any}[sig=> resolve_todo (item, state, flag) for (sig, item) in todo. cases])
783
775
end
784
776
785
777
function validate_sparams (sparams:: SimpleVector )
@@ -790,7 +782,7 @@ function validate_sparams(sparams::SimpleVector)
790
782
end
791
783
792
784
function analyze_method! (match:: MethodMatch , atypes:: Vector{Any} ,
793
- state:: InliningState , @nospecialize (stmttyp))
785
+ state:: InliningState , @nospecialize (stmttyp), flag :: UInt8 )
794
786
method = match. method
795
787
methsig = method. sig
796
788
@@ -806,11 +798,9 @@ function analyze_method!(match::MethodMatch, atypes::Vector{Any},
806
798
end
807
799
808
800
# Bail out if any static parameters are left as TypeVar
809
- ok = true
810
801
validate_sparams (match. sparams) || return nothing
811
802
812
-
813
- if ! state. params. inlining
803
+ if ! state. params. inlining || is_stmt_noinline (flag)
814
804
return compileable_specialization (state. et, match)
815
805
end
816
806
@@ -824,7 +814,7 @@ function analyze_method!(match::MethodMatch, atypes::Vector{Any},
824
814
# If we don't have caches here, delay resolving this MethodInstance
825
815
# until the batch inlining step (or an external post-processing pass)
826
816
state. mi_cache === nothing && return todo
827
- return resolve_todo (todo, state)
817
+ return resolve_todo (todo, state, flag )
828
818
end
829
819
830
820
function InliningTodo (mi:: MethodInstance , ir:: IRCode )
@@ -1050,7 +1040,7 @@ is_builtin(s::Signature) =
1050
1040
s. ft ⊑ Builtin
1051
1041
1052
1042
function inline_invoke! (ir:: IRCode , idx:: Int , sig:: Signature , (; match, result):: InvokeCallInfo ,
1053
- state:: InliningState , todo:: Vector{Pair{Int, Any}} )
1043
+ state:: InliningState , todo:: Vector{Pair{Int, Any}} , flag :: UInt8 )
1054
1044
stmt = ir. stmts[idx][:inst ]
1055
1045
calltype = ir. stmts[idx][:type ]
1056
1046
@@ -1064,17 +1054,17 @@ function inline_invoke!(ir::IRCode, idx::Int, sig::Signature, (; match, result):
1064
1054
atypes = atypes[4 : end ]
1065
1055
pushfirst! (atypes, atype0)
1066
1056
1067
- if isa (result, InferenceResult)
1057
+ if isa (result, InferenceResult) && ! is_stmt_noinline (flag)
1068
1058
item = InliningTodo (result, atypes, calltype)
1069
1059
validate_sparams (item. mi. sparam_vals) || return nothing
1070
1060
if argtypes_to_type (atypes) <: item.mi.def.sig
1071
- state. mi_cache != = nothing && (item = resolve_todo (item, state))
1061
+ state. mi_cache != = nothing && (item = resolve_todo (item, state, flag ))
1072
1062
handle_single_case! (ir, stmt, idx, item, true , todo)
1073
1063
return nothing
1074
1064
end
1075
1065
end
1076
1066
1077
- result = analyze_method! (match, atypes, state, calltype)
1067
+ result = analyze_method! (match, atypes, state, calltype, flag )
1078
1068
handle_single_case! (ir, stmt, idx, result, true , todo)
1079
1069
return nothing
1080
1070
end
@@ -1169,7 +1159,7 @@ end
1169
1159
1170
1160
function analyze_single_call! (ir:: IRCode , todo:: Vector{Pair{Int, Any}} , idx:: Int , @nospecialize (stmt),
1171
1161
sig:: Signature , @nospecialize (calltype), infos:: Vector{MethodMatchInfo} ,
1172
- state:: InliningState )
1162
+ state:: InliningState , flag :: UInt8 )
1173
1163
cases = Pair{Any, Any}[]
1174
1164
signature_union = Union{}
1175
1165
only_method = nothing # keep track of whether there is one matching method
@@ -1202,7 +1192,7 @@ function analyze_single_call!(ir::IRCode, todo::Vector{Pair{Int, Any}}, idx::Int
1202
1192
fully_covered = false
1203
1193
continue
1204
1194
end
1205
- case = analyze_method! (match, sig. atypes, state, calltype)
1195
+ case = analyze_method! (match, sig. atypes, state, calltype, flag )
1206
1196
if case === nothing
1207
1197
fully_covered = false
1208
1198
continue
@@ -1229,7 +1219,7 @@ function analyze_single_call!(ir::IRCode, todo::Vector{Pair{Int, Any}}, idx::Int
1229
1219
match = meth[1 ]
1230
1220
end
1231
1221
fully_covered = true
1232
- case = analyze_method! (match, sig. atypes, state, calltype)
1222
+ case = analyze_method! (match, sig. atypes, state, calltype, flag )
1233
1223
case === nothing && return
1234
1224
push! (cases, Pair {Any,Any} (match. spec_types, case))
1235
1225
end
@@ -1251,7 +1241,7 @@ end
1251
1241
1252
1242
function maybe_handle_const_call! (ir:: IRCode , idx:: Int , stmt:: Expr ,
1253
1243
info:: ConstCallInfo , sig:: Signature , @nospecialize (calltype),
1254
- state:: InliningState ,
1244
+ state:: InliningState , flag :: UInt8 ,
1255
1245
isinvoke:: Bool , todo:: Vector{Pair{Int, Any}} )
1256
1246
# when multiple matches are found, bail out and later inliner will union-split this signature
1257
1247
# TODO effectively use multiple constant analysis results here
@@ -1263,7 +1253,7 @@ function maybe_handle_const_call!(ir::IRCode, idx::Int, stmt::Expr,
1263
1253
validate_sparams (item. mi. sparam_vals) || return true
1264
1254
mthd_sig = item. mi. def. sig
1265
1255
mistypes = item. mi. specTypes
1266
- state. mi_cache != = nothing && (item = resolve_todo (item, state))
1256
+ state. mi_cache != = nothing && (item = resolve_todo (item, state, flag ))
1267
1257
if sig. atype <: mthd_sig
1268
1258
handle_single_case! (ir, stmt, idx, item, isinvoke, todo)
1269
1259
return true
@@ -1301,6 +1291,8 @@ function assemble_inline_todo!(ir::IRCode, state::InliningState)
1301
1291
info = info. info
1302
1292
end
1303
1293
1294
+ flag = ir. stmts[idx][:flag ]
1295
+
1304
1296
# Inference determined this couldn't be analyzed. Don't question it.
1305
1297
if info === false
1306
1298
continue
@@ -1310,23 +1302,24 @@ function assemble_inline_todo!(ir::IRCode, state::InliningState)
1310
1302
# it'll have performed a specialized analysis for just this case. Use its
1311
1303
# result.
1312
1304
if isa (info, ConstCallInfo)
1313
- if maybe_handle_const_call! (ir, idx, stmt, info, sig, calltype, state, sig. f === Core. invoke, todo)
1305
+ if ! is_stmt_noinline (flag) && maybe_handle_const_call! (
1306
+ ir, idx, stmt, info, sig, calltype, state, flag, sig. f === Core. invoke, todo)
1314
1307
continue
1315
1308
else
1316
1309
info = info. call
1317
1310
end
1318
1311
end
1319
1312
1320
1313
if isa (info, OpaqueClosureCallInfo)
1321
- result = analyze_method! (info. match, sig. atypes, state, calltype)
1314
+ result = analyze_method! (info. match, sig. atypes, state, calltype, flag )
1322
1315
handle_single_case! (ir, stmt, idx, result, false , todo)
1323
1316
continue
1324
1317
end
1325
1318
1326
1319
# Handle invoke
1327
1320
if sig. f === Core. invoke
1328
1321
if isa (info, InvokeCallInfo)
1329
- inline_invoke! (ir, idx, sig, info, state, todo)
1322
+ inline_invoke! (ir, idx, sig, info, state, todo, flag )
1330
1323
end
1331
1324
continue
1332
1325
end
@@ -1340,7 +1333,7 @@ function assemble_inline_todo!(ir::IRCode, state::InliningState)
1340
1333
continue
1341
1334
end
1342
1335
1343
- analyze_single_call! (ir, todo, idx, stmt, sig, calltype, infos, state)
1336
+ analyze_single_call! (ir, todo, idx, stmt, sig, calltype, infos, state, flag )
1344
1337
end
1345
1338
todo
1346
1339
end
0 commit comments