@@ -604,6 +604,7 @@ function rewrite_apply_exprargs!(ir::IRCode, todo::Vector{Pair{Int, Any}}, idx::
604604 argexprs:: Vector{Any} , atypes:: Vector{Any} , arginfos:: Vector{Any} ,
605605 arg_start:: Int , istate:: InliningState )
606606
607+ flag = ir. stmts[idx][:flag ]
607608 new_argexprs = Any[argexprs[arg_start]]
608609 new_atypes = Any[atypes[arg_start]]
609610 # loop over original arguments and flatten any known iterators
@@ -659,8 +660,9 @@ function rewrite_apply_exprargs!(ir::IRCode, todo::Vector{Pair{Int, Any}}, idx::
659660 info = call. info
660661 handled = false
661662 if isa (info, ConstCallInfo)
662- if maybe_handle_const_call! (ir, state1. id, new_stmt, info, new_sig,
663- call. rt, istate, false , todo)
663+ if ! is_stmt_noinline (flag) && maybe_handle_const_call! (
664+ ir, state1. id, new_stmt, info, new_sig,call. rt, istate, flag, false , todo)
665+
664666 handled = true
665667 else
666668 info = info. call
@@ -671,7 +673,7 @@ function rewrite_apply_exprargs!(ir::IRCode, todo::Vector{Pair{Int, Any}}, idx::
671673 MethodMatchInfo[info] : info. matches
672674 # See if we can inline this call to `iterate`
673675 analyze_single_call! (ir, todo, state1. id, new_stmt,
674- new_sig, call. rt, info, istate)
676+ new_sig, call. rt, info, istate, flag )
675677 end
676678 if i != length (thisarginfo. each)
677679 valT = getfield_tfunc (call. rt, Const (1 ))
@@ -719,16 +721,16 @@ function compileable_specialization(et::Union{EdgeTracker, Nothing}, (; linfo)::
719721 return mi
720722end
721723
722- function resolve_todo (todo:: InliningTodo , state:: InliningState )
723- spec = todo. spec:: DelayedInliningSpec
724+ function resolve_todo (todo:: InliningTodo , state:: InliningState , flag :: UInt8 )
725+ (; match) = todo. spec:: DelayedInliningSpec
724726
725727 # XXX : update_valid_age!(min_valid[1], max_valid[1], sv)
726728 isconst, src = false , nothing
727- if isa (spec . match, InferenceResult)
728- let inferred_src = spec . match. src
729+ if isa (match, InferenceResult)
730+ let inferred_src = match. src
729731 if isa (inferred_src, Const)
730732 if ! is_inlineable_constant (inferred_src. val)
731- return compileable_specialization (state. et, spec . match)
733+ return compileable_specialization (state. et, match)
732734 end
733735 isconst, src = true , quoted (inferred_src. val)
734736 else
@@ -756,12 +758,10 @@ function resolve_todo(todo::InliningTodo, state::InliningState)
756758 return ConstantCase (src)
757759 end
758760
759- if src != = nothing
760- src = state. policy (src)
761- end
761+ src = state. policy (src, flag, match)
762762
763763 if src === nothing
764- return compileable_specialization (et, spec . match)
764+ return compileable_specialization (et, match)
765765 end
766766
767767 if isa (src, IRCode)
@@ -772,9 +772,9 @@ function resolve_todo(todo::InliningTodo, state::InliningState)
772772 return InliningTodo (todo. mi, src)
773773end
774774
775- function resolve_todo (todo:: UnionSplit , state:: InliningState )
775+ function resolve_todo (todo:: UnionSplit , state:: InliningState , flag :: UInt8 )
776776 UnionSplit (todo. fully_covered, todo. atype,
777- Pair{Any,Any}[sig=> resolve_todo (item, state) for (sig, item) in todo. cases])
777+ Pair{Any,Any}[sig=> resolve_todo (item, state, flag ) for (sig, item) in todo. cases])
778778end
779779
780780function validate_sparams (sparams:: SimpleVector )
@@ -785,7 +785,7 @@ function validate_sparams(sparams::SimpleVector)
785785end
786786
787787function analyze_method! (match:: MethodMatch , atypes:: Vector{Any} ,
788- state:: InliningState , @nospecialize (stmttyp))
788+ state:: InliningState , @nospecialize (stmttyp), flag :: UInt8 )
789789 method = match. method
790790 methsig = method. sig
791791
@@ -805,7 +805,7 @@ function analyze_method!(match::MethodMatch, atypes::Vector{Any},
805805
806806 et = state. et
807807
808- if ! state. params. inlining
808+ if ! state. params. inlining || is_stmt_noinline (flag)
809809 return compileable_specialization (et, match)
810810 end
811811
@@ -819,7 +819,7 @@ function analyze_method!(match::MethodMatch, atypes::Vector{Any},
819819 # If we don't have caches here, delay resolving this MethodInstance
820820 # until the batch inlining step (or an external post-processing pass)
821821 state. mi_cache === nothing && return todo
822- return resolve_todo (todo, state)
822+ return resolve_todo (todo, state, flag )
823823end
824824
825825function InliningTodo (mi:: MethodInstance , ir:: IRCode )
@@ -1044,7 +1044,7 @@ is_builtin(s::Signature) =
10441044 s. ft ⊑ Builtin
10451045
10461046function inline_invoke! (ir:: IRCode , idx:: Int , sig:: Signature , (; match, result):: InvokeCallInfo ,
1047- state:: InliningState , todo:: Vector{Pair{Int, Any}} )
1047+ state:: InliningState , todo:: Vector{Pair{Int, Any}} , flag :: UInt8 )
10481048 stmt = ir. stmts[idx][:inst ]
10491049 calltype = ir. stmts[idx][:type ]
10501050
@@ -1058,17 +1058,17 @@ function inline_invoke!(ir::IRCode, idx::Int, sig::Signature, (; match, result):
10581058 atypes = atypes[4 : end ]
10591059 pushfirst! (atypes, atype0)
10601060
1061- if isa (result, InferenceResult)
1061+ if isa (result, InferenceResult) && ! is_stmt_noinline (flag)
10621062 (; mi) = item = InliningTodo (result, atypes, calltype)
10631063 validate_sparams (mi. sparam_vals) || return nothing
10641064 if argtypes_to_type (atypes) <: mi.def.sig
1065- state. mi_cache != = nothing && (item = resolve_todo (item, state))
1065+ state. mi_cache != = nothing && (item = resolve_todo (item, state, flag ))
10661066 handle_single_case! (ir, stmt, idx, item, true , todo)
10671067 return nothing
10681068 end
10691069 end
10701070
1071- result = analyze_method! (match, atypes, state, calltype)
1071+ result = analyze_method! (match, atypes, state, calltype, flag )
10721072 handle_single_case! (ir, stmt, idx, result, true , todo)
10731073 return nothing
10741074end
@@ -1163,7 +1163,7 @@ end
11631163
11641164function analyze_single_call! (ir:: IRCode , todo:: Vector{Pair{Int, Any}} , idx:: Int , @nospecialize (stmt),
11651165 sig:: Signature , @nospecialize (calltype), infos:: Vector{MethodMatchInfo} ,
1166- state:: InliningState )
1166+ state:: InliningState , flag :: UInt8 )
11671167 cases = Pair{Any, Any}[]
11681168 signature_union = Union{}
11691169 only_method = nothing # keep track of whether there is one matching method
@@ -1197,7 +1197,7 @@ function analyze_single_call!(ir::IRCode, todo::Vector{Pair{Int, Any}}, idx::Int
11971197 fully_covered = false
11981198 continue
11991199 end
1200- case = analyze_method! (match, sig. atypes, state, calltype)
1200+ case = analyze_method! (match, sig. atypes, state, calltype, flag )
12011201 if case === nothing
12021202 fully_covered = false
12031203 continue
@@ -1224,7 +1224,7 @@ function analyze_single_call!(ir::IRCode, todo::Vector{Pair{Int, Any}}, idx::Int
12241224 match = meth[1 ]
12251225 end
12261226 fully_covered = true
1227- case = analyze_method! (match, sig. atypes, state, calltype)
1227+ case = analyze_method! (match, sig. atypes, state, calltype, flag )
12281228 case === nothing && return
12291229 push! (cases, Pair {Any,Any} (match. spec_types, case))
12301230 end
@@ -1246,7 +1246,7 @@ end
12461246
12471247function maybe_handle_const_call! (ir:: IRCode , idx:: Int , stmt:: Expr ,
12481248 info:: ConstCallInfo , sig:: Signature , @nospecialize (calltype),
1249- state:: InliningState ,
1249+ state:: InliningState , flag :: UInt8 ,
12501250 isinvoke:: Bool , todo:: Vector{Pair{Int, Any}} )
12511251 # when multiple matches are found, bail out and later inliner will union-split this signature
12521252 # TODO effectively use multiple constant analysis results here
@@ -1258,7 +1258,7 @@ function maybe_handle_const_call!(ir::IRCode, idx::Int, stmt::Expr,
12581258 validate_sparams (mi. sparam_vals) || return true
12591259 mthd_sig = mi. def. sig
12601260 mistypes = mi. specTypes
1261- state. mi_cache != = nothing && (item = resolve_todo (item, state))
1261+ state. mi_cache != = nothing && (item = resolve_todo (item, state, flag ))
12621262 if sig. atype <: mthd_sig
12631263 handle_single_case! (ir, stmt, idx, item, isinvoke, todo)
12641264 return true
@@ -1296,6 +1296,8 @@ function assemble_inline_todo!(ir::IRCode, state::InliningState)
12961296 info = info. info
12971297 end
12981298
1299+ flag = ir. stmts[idx][:flag ]
1300+
12991301 # Inference determined this couldn't be analyzed. Don't question it.
13001302 if info === false
13011303 continue
@@ -1305,23 +1307,24 @@ function assemble_inline_todo!(ir::IRCode, state::InliningState)
13051307 # it'll have performed a specialized analysis for just this case. Use its
13061308 # result.
13071309 if isa (info, ConstCallInfo)
1308- if maybe_handle_const_call! (ir, idx, stmt, info, sig, calltype, state, sig. f === Core. invoke, todo)
1310+ if ! is_stmt_noinline (flag) && maybe_handle_const_call! (
1311+ ir, idx, stmt, info, sig, calltype, state, flag, sig. f === Core. invoke, todo)
13091312 continue
13101313 else
13111314 info = info. call
13121315 end
13131316 end
13141317
13151318 if isa (info, OpaqueClosureCallInfo)
1316- result = analyze_method! (info. match, sig. atypes, state, calltype)
1319+ result = analyze_method! (info. match, sig. atypes, state, calltype, flag )
13171320 handle_single_case! (ir, stmt, idx, result, false , todo)
13181321 continue
13191322 end
13201323
13211324 # Handle invoke
13221325 if sig. f === Core. invoke
13231326 if isa (info, InvokeCallInfo)
1324- inline_invoke! (ir, idx, sig, info, state, todo)
1327+ inline_invoke! (ir, idx, sig, info, state, todo, flag )
13251328 end
13261329 continue
13271330 end
@@ -1335,7 +1338,7 @@ function assemble_inline_todo!(ir::IRCode, state::InliningState)
13351338 continue
13361339 end
13371340
1338- analyze_single_call! (ir, todo, idx, stmt, sig, calltype, infos, state)
1341+ analyze_single_call! (ir, todo, idx, stmt, sig, calltype, infos, state, flag )
13391342 end
13401343 todo
13411344end
0 commit comments