874874
875875# the general resolver for usual and const-prop'ed calls
876876function resolve_todo (mi:: MethodInstance , result:: Union{Nothing,InferenceResult,VolatileInferenceResult} ,
877- argtypes :: Vector{Any} , @nospecialize (info:: CallInfo ), flag:: UInt32 , state:: InliningState ;
877+ @nospecialize (info:: CallInfo ), flag:: UInt32 , state:: InliningState ;
878878 invokesig:: Union{Nothing,Vector{Any}} = nothing )
879879 et = InliningEdgeTracker (state, invokesig)
880880
@@ -901,7 +901,7 @@ function resolve_todo(mi::MethodInstance, result::Union{Nothing,InferenceResult,
901901 compilesig_invokes= OptimizationParams (state. interp). compilesig_invokes)
902902 end
903903
904- src = inlining_policy (state. interp, src, info, flag, mi, argtypes )
904+ src = inlining_policy (state. interp, src, info, flag)
905905 src === nothing && return compileable_specialization (mi, effects, et, info;
906906 compilesig_invokes= OptimizationParams (state. interp). compilesig_invokes)
907907
@@ -911,8 +911,8 @@ function resolve_todo(mi::MethodInstance, result::Union{Nothing,InferenceResult,
911911end
912912
913913# the special resolver for :invoke-d call
914- function resolve_todo (mi:: MethodInstance , argtypes :: Vector{Any} ,
915- @nospecialize (info :: CallInfo ), flag :: UInt32 , state:: InliningState )
914+ function resolve_todo (mi:: MethodInstance , @nospecialize (info :: CallInfo ), flag :: UInt32 ,
915+ state:: InliningState )
916916 if ! OptimizationParams (state. interp). inlining || is_stmt_noinline (flag)
917917 return nothing
918918 end
@@ -926,7 +926,7 @@ function resolve_todo(mi::MethodInstance, argtypes::Vector{Any},
926926 end
927927 (; src, effects) = cached_result
928928
929- src = inlining_policy (state. interp, src, info, flag, mi, argtypes )
929+ src = inlining_policy (state. interp, src, info, flag)
930930
931931 src === nothing && return nothing
932932
@@ -981,7 +981,7 @@ function analyze_method!(match::MethodMatch, argtypes::Vector{Any},
981981 # Get the specialization for this method signature
982982 # (later we will decide what to do with it)
983983 mi = specialize_method (match)
984- return resolve_todo (mi, volatile_inf_result, argtypes, info, flag, state; invokesig)
984+ return resolve_todo (mi, volatile_inf_result, info, flag, state; invokesig)
985985end
986986
987987function retrieve_ir_for_inlining (mi:: MethodInstance , src:: String , :: Bool = true )
@@ -1204,26 +1204,21 @@ function handle_invoke_call!(todo::Vector{Pair{Int,Any}},
12041204 invokesig = sig. argtypes
12051205 if isa (result, ConcreteResult)
12061206 item = concrete_result_item (result, info, state; invokesig)
1207+ elseif isa (result, SemiConcreteResult)
1208+ item = semiconcrete_result_item (result, info, flag, state)
12071209 else
12081210 argtypes = invoke_rewrite (sig. argtypes)
1209- if isa (result, SemiConcreteResult)
1210- result = inlining_policy (state. interp, result, info, flag, result. mi, argtypes)
1211- end
1212- if isa (result, SemiConcreteResult)
1213- item = semiconcrete_result_item (result, info, flag, state)
1214- else
1215- if isa (result, ConstPropResult)
1216- mi = result. result. linfo
1217- validate_sparams (mi. sparam_vals) || return nothing
1218- if Union{} != = argtypes_to_type (argtypes) <: mi.def.sig
1219- item = resolve_todo (mi, result. result, argtypes, info, flag, state; invokesig)
1220- handle_single_case! (todo, ir, idx, stmt, item, true )
1221- return nothing
1222- end
1211+ if isa (result, ConstPropResult)
1212+ mi = result. result. linfo
1213+ validate_sparams (mi. sparam_vals) || return nothing
1214+ if Union{} != = argtypes_to_type (argtypes) <: mi.def.sig
1215+ item = resolve_todo (mi, result. result, info, flag, state; invokesig)
1216+ handle_single_case! (todo, ir, idx, stmt, item, true )
1217+ return nothing
12231218 end
1224- volatile_inf_result = result isa VolatileInferenceResult ? result : nothing
1225- item = analyze_method! (match, argtypes, info, flag, state; allow_typevars= false , invokesig, volatile_inf_result)
12261219 end
1220+ volatile_inf_result = result isa VolatileInferenceResult ? result : nothing
1221+ item = analyze_method! (match, argtypes, info, flag, state; allow_typevars= false , invokesig, volatile_inf_result)
12271222 end
12281223 handle_single_case! (todo, ir, idx, stmt, item, true )
12291224 return nothing
@@ -1352,15 +1347,10 @@ function handle_any_const_result!(cases::Vector{InliningCase},
13521347 allow_abstract:: Bool , allow_typevars:: Bool )
13531348 if isa (result, ConcreteResult)
13541349 return handle_concrete_result! (cases, result, info, state)
1355- end
1356- if isa (result, SemiConcreteResult)
1357- result = inlining_policy (state. interp, result, info, flag, result. mi, argtypes)
1358- if isa (result, SemiConcreteResult)
1359- return handle_semi_concrete_result! (cases, result, info, flag, state; allow_abstract)
1360- end
1361- end
1362- if isa (result, ConstPropResult)
1363- return handle_const_prop_result! (cases, result, argtypes, info, flag, state; allow_abstract, allow_typevars)
1350+ elseif isa (result, SemiConcreteResult)
1351+ return handle_semi_concrete_result! (cases, result, info, flag, state; allow_abstract)
1352+ elseif isa (result, ConstPropResult)
1353+ return handle_const_prop_result! (cases, result, info, flag, state; allow_abstract, allow_typevars)
13641354 else
13651355 @assert result === nothing || result isa VolatileInferenceResult
13661356 return handle_match! (cases, match, argtypes, info, flag, state; allow_abstract, allow_typevars, volatile_inf_result = result)
@@ -1507,16 +1497,15 @@ function handle_match!(cases::Vector{InliningCase},
15071497end
15081498
15091499function handle_const_prop_result! (cases:: Vector{InliningCase} ,
1510- result:: ConstPropResult , argtypes:: Vector{Any} , @nospecialize (info:: CallInfo ),
1511- flag:: UInt32 , state:: InliningState ;
1500+ result:: ConstPropResult , @nospecialize (info:: CallInfo ), flag:: UInt32 , state:: InliningState ;
15121501 allow_abstract:: Bool , allow_typevars:: Bool )
15131502 mi = result. result. linfo
15141503 spec_types = mi. specTypes
15151504 allow_abstract || isdispatchtuple (spec_types) || return false
15161505 if ! validate_sparams (mi. sparam_vals)
15171506 (allow_typevars && ! may_have_fcalls (mi. def:: Method )) || return false
15181507 end
1519- item = resolve_todo (mi, result. result, argtypes, info, flag, state)
1508+ item = resolve_todo (mi, result. result, info, flag, state)
15201509 item === nothing && return false
15211510 push! (cases, InliningCase (spec_types, item))
15221511 return true
@@ -1525,15 +1514,24 @@ end
15251514function semiconcrete_result_item (result:: SemiConcreteResult ,
15261515 @nospecialize (info:: CallInfo ), flag:: UInt32 , state:: InliningState )
15271516 mi = result. mi
1528- if ! OptimizationParams (state. interp). inlining || is_stmt_noinline (flag)
1529- et = InliningEdgeTracker (state)
1517+ et = InliningEdgeTracker (state)
1518+
1519+ if (! OptimizationParams (state. interp). inlining || is_stmt_noinline (flag) ||
1520+ # For `NativeInterpreter`, `SemiConcreteResult` may be produced for
1521+ # a `@noinline`-declared method when it's marked as `@constprop :aggressive`.
1522+ # Suppress the inlining here (unless inlining is requested at the callsite).
1523+ (is_declared_noinline (mi. def:: Method ) && ! is_stmt_inline (flag)))
15301524 return compileable_specialization (mi, result. effects, et, info;
15311525 compilesig_invokes= OptimizationParams (state. interp). compilesig_invokes)
1532- else
1533- preserve_local_sources = OptimizationParams (state. interp). preserve_local_sources
1534- ir = retrieve_ir_for_inlining (mi, result. ir, preserve_local_sources)
1535- return InliningTodo (mi, ir, result. effects)
15361526 end
1527+ ir = inlining_policy (state. interp, result. ir, info, flag)
1528+ ir === nothing && return compileable_specialization (mi, result. effects, et, info;
1529+ compilesig_invokes= OptimizationParams (state. interp). compilesig_invokes)
1530+
1531+ add_inlining_backedge! (et, mi)
1532+ preserve_local_sources = OptimizationParams (state. interp). preserve_local_sources
1533+ ir = retrieve_ir_for_inlining (mi, ir, preserve_local_sources)
1534+ return InliningTodo (mi, ir, result. effects)
15371535end
15381536
15391537function handle_semi_concrete_result! (cases:: Vector{InliningCase} , result:: SemiConcreteResult ,
@@ -1597,20 +1595,15 @@ function handle_opaque_closure_call!(todo::Vector{Pair{Int,Any}},
15971595 if isa (result, ConstPropResult)
15981596 mi = result. result. linfo
15991597 validate_sparams (mi. sparam_vals) || return nothing
1600- item = resolve_todo (mi, result. result, sig . argtypes, info, flag, state)
1598+ item = resolve_todo (mi, result. result, info, flag, state)
16011599 elseif isa (result, ConcreteResult)
16021600 item = concrete_result_item (result, info, state)
1601+ elseif isa (result, SemiConcreteResult)
1602+ item = item = semiconcrete_result_item (result, info, flag, state)
16031603 else
1604- if isa (result, SemiConcreteResult)
1605- result = inlining_policy (state. interp, result, info, flag, result. mi, sig. argtypes)
1606- end
1607- if isa (result, SemiConcreteResult)
1608- item = semiconcrete_result_item (result, info, flag, state)
1609- else
1610- @assert result === nothing || result isa VolatileInferenceResult
1611- volatile_inf_result = result
1612- item = analyze_method! (info. match, sig. argtypes, info, flag, state; allow_typevars= false , volatile_inf_result)
1613- end
1604+ @assert result === nothing || result isa VolatileInferenceResult
1605+ volatile_inf_result = result
1606+ item = analyze_method! (info. match, sig. argtypes, info, flag, state; allow_typevars= false , volatile_inf_result)
16141607 end
16151608 handle_single_case! (todo, ir, idx, stmt, item)
16161609 return nothing
@@ -1678,7 +1671,7 @@ end
16781671function handle_invoke_expr! (todo:: Vector{Pair{Int,Any}} , ir:: IRCode ,
16791672 idx:: Int , stmt:: Expr , @nospecialize (info:: CallInfo ), flag:: UInt32 , sig:: Signature , state:: InliningState )
16801673 mi = stmt. args[1 ]:: MethodInstance
1681- case = resolve_todo (mi, sig . argtypes, info, flag, state)
1674+ case = resolve_todo (mi, info, flag, state)
16821675 handle_single_case! (todo, ir, idx, stmt, case, false )
16831676 return nothing
16841677end
0 commit comments