@@ -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 , info:: 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,7 +1054,7 @@ function inline_invoke!(ir::IRCode, idx::Int, sig::Signature, info::InvokeCallIn
1064
1054
atypes = atypes[4 : end ]
1065
1055
pushfirst! (atypes, atype0)
1066
1056
1067
- result = analyze_method! (info. match, atypes, state, calltype)
1057
+ result = analyze_method! (info. match, atypes, state, calltype, flag )
1068
1058
handle_single_case! (ir, stmt, idx, result, true , todo)
1069
1059
return nothing
1070
1060
end
@@ -1159,7 +1149,7 @@ end
1159
1149
1160
1150
function analyze_single_call! (ir:: IRCode , todo:: Vector{Pair{Int, Any}} , idx:: Int , @nospecialize (stmt),
1161
1151
sig:: Signature , @nospecialize (calltype), infos:: Vector{MethodMatchInfo} ,
1162
- state:: InliningState )
1152
+ state:: InliningState , flag :: UInt8 )
1163
1153
cases = Pair{Any, Any}[]
1164
1154
signature_union = Union{}
1165
1155
only_method = nothing # keep track of whether there is one matching method
@@ -1192,7 +1182,7 @@ function analyze_single_call!(ir::IRCode, todo::Vector{Pair{Int, Any}}, idx::Int
1192
1182
fully_covered = false
1193
1183
continue
1194
1184
end
1195
- case = analyze_method! (match, sig. atypes, state, calltype)
1185
+ case = analyze_method! (match, sig. atypes, state, calltype, flag )
1196
1186
if case === nothing
1197
1187
fully_covered = false
1198
1188
continue
@@ -1219,7 +1209,7 @@ function analyze_single_call!(ir::IRCode, todo::Vector{Pair{Int, Any}}, idx::Int
1219
1209
match = meth[1 ]
1220
1210
end
1221
1211
fully_covered = true
1222
- case = analyze_method! (match, sig. atypes, state, calltype)
1212
+ case = analyze_method! (match, sig. atypes, state, calltype, flag )
1223
1213
case === nothing && return
1224
1214
push! (cases, Pair {Any,Any} (match. spec_types, case))
1225
1215
end
@@ -1241,7 +1231,7 @@ end
1241
1231
1242
1232
function maybe_handle_const_call! (ir:: IRCode , idx:: Int , stmt:: Expr ,
1243
1233
info:: ConstCallInfo , sig:: Signature , @nospecialize (calltype),
1244
- state:: InliningState ,
1234
+ state:: InliningState , flag :: UInt8 ,
1245
1235
isinvoke:: Bool , todo:: Vector{Pair{Int, Any}} )
1246
1236
# when multiple matches are found, bail out and later inliner will union-split this signature
1247
1237
# TODO effectively use multiple constant analysis results here
@@ -1253,7 +1243,7 @@ function maybe_handle_const_call!(ir::IRCode, idx::Int, stmt::Expr,
1253
1243
validate_sparams (item. mi. sparam_vals) || return true
1254
1244
mthd_sig = item. mi. def. sig
1255
1245
mistypes = item. mi. specTypes
1256
- state. mi_cache != = nothing && (item = resolve_todo (item, state))
1246
+ state. mi_cache != = nothing && (item = resolve_todo (item, state, flag ))
1257
1247
if sig. atype <: mthd_sig
1258
1248
handle_single_case! (ir, stmt, idx, item, isinvoke, todo)
1259
1249
return true
@@ -1291,6 +1281,8 @@ function assemble_inline_todo!(ir::IRCode, state::InliningState)
1291
1281
info = info. info
1292
1282
end
1293
1283
1284
+ flag = ir. stmts[idx][:flag ]
1285
+
1294
1286
# Inference determined this couldn't be analyzed. Don't question it.
1295
1287
if info === false
1296
1288
continue
@@ -1300,23 +1292,24 @@ function assemble_inline_todo!(ir::IRCode, state::InliningState)
1300
1292
# it'll have performed a specialized analysis for just this case. Use its
1301
1293
# result.
1302
1294
if isa (info, ConstCallInfo)
1303
- if maybe_handle_const_call! (ir, idx, stmt, info, sig, calltype, state, sig. f === Core. invoke, todo)
1295
+ if ! is_stmt_noinline (flag) && maybe_handle_const_call! (
1296
+ ir, idx, stmt, info, sig, calltype, state, flag, sig. f === Core. invoke, todo)
1304
1297
continue
1305
1298
else
1306
1299
info = info. call
1307
1300
end
1308
1301
end
1309
1302
1310
1303
if isa (info, OpaqueClosureCallInfo)
1311
- result = analyze_method! (info. match, sig. atypes, state, calltype)
1304
+ result = analyze_method! (info. match, sig. atypes, state, calltype, flag )
1312
1305
handle_single_case! (ir, stmt, idx, result, false , todo)
1313
1306
continue
1314
1307
end
1315
1308
1316
1309
# Handle invoke
1317
1310
if sig. f === Core. invoke
1318
1311
if isa (info, InvokeCallInfo)
1319
- inline_invoke! (ir, idx, sig, info, state, todo)
1312
+ inline_invoke! (ir, idx, sig, info, state, todo, flag )
1320
1313
end
1321
1314
continue
1322
1315
end
@@ -1330,7 +1323,7 @@ function assemble_inline_todo!(ir::IRCode, state::InliningState)
1330
1323
continue
1331
1324
end
1332
1325
1333
- analyze_single_call! (ir, todo, idx, stmt, sig, calltype, infos, state)
1326
+ analyze_single_call! (ir, todo, idx, stmt, sig, calltype, infos, state, flag )
1334
1327
end
1335
1328
todo
1336
1329
end
0 commit comments