@@ -29,19 +29,21 @@ pass to apply its own inlining policy decisions.
2929struct DelayedInliningSpec
3030 match:: Union{MethodMatch, InferenceResult}
3131 argtypes:: Vector{Any}
32+ invokesig # either nothing or a signature (signature is for an `invoke` call)
3233end
34+ DelayedInliningSpec (match, argtypes) = DelayedInliningSpec (match, argtypes, nothing )
3335
3436struct InliningTodo
3537 # The MethodInstance to be inlined
3638 mi:: MethodInstance
3739 spec:: Union{ResolvedInliningSpec, DelayedInliningSpec}
3840end
3941
40- InliningTodo (mi:: MethodInstance , match:: MethodMatch , argtypes:: Vector{Any} ) =
41- InliningTodo (mi, DelayedInliningSpec (match, argtypes))
42+ InliningTodo (mi:: MethodInstance , match:: MethodMatch , argtypes:: Vector{Any} , invokesig = nothing ) =
43+ InliningTodo (mi, DelayedInliningSpec (match, argtypes, invokesig ))
4244
43- InliningTodo (result:: InferenceResult , argtypes:: Vector{Any} ) =
44- InliningTodo (result. linfo, DelayedInliningSpec (result, argtypes))
45+ InliningTodo (result:: InferenceResult , argtypes:: Vector{Any} , invokesig = nothing ) =
46+ InliningTodo (result. linfo, DelayedInliningSpec (result, argtypes, invokesig ))
4547
4648struct ConstantCase
4749 val:: Any
@@ -810,15 +812,15 @@ end
810812
811813function resolve_todo (todo:: InliningTodo , state:: InliningState , flag:: UInt8 )
812814 mi = todo. mi
813- (; match, argtypes) = todo. spec:: DelayedInliningSpec
815+ (; match, argtypes, invokesig ) = todo. spec:: DelayedInliningSpec
814816 et = state. et
815817
816818 # XXX : update_valid_age!(min_valid[1], max_valid[1], sv)
817819 if isa (match, InferenceResult)
818820 inferred_src = match. src
819821 if isa (inferred_src, ConstAPI)
820822 # use constant calling convention
821- et != = nothing && push ! (et, mi)
823+ et != = nothing && add_edge ! (et, invokesig , mi)
822824 return ConstantCase (quoted (inferred_src. val))
823825 else
824826 src = inferred_src # ::Union{Nothing,CodeInfo} for NativeInterpreter
@@ -829,7 +831,7 @@ function resolve_todo(todo::InliningTodo, state::InliningState, flag::UInt8)
829831 if code isa CodeInstance
830832 if use_const_api (code)
831833 # in this case function can be inlined to a constant
832- et != = nothing && push ! (et, mi)
834+ et != = nothing && add_edge ! (et, invokesig , mi)
833835 return ConstantCase (quoted (code. rettype_const))
834836 else
835837 src = @atomic :monotonic code. inferred
@@ -851,7 +853,7 @@ function resolve_todo(todo::InliningTodo, state::InliningState, flag::UInt8)
851853
852854 src === nothing && return compileable_specialization (et, match, effects)
853855
854- et != = nothing && push ! (et, mi)
856+ et != = nothing && add_edge ! (et, invokesig , mi)
855857 return InliningTodo (mi, retrieve_ir_for_inlining (mi, src), effects)
856858end
857859
@@ -873,7 +875,7 @@ function validate_sparams(sparams::SimpleVector)
873875 return true
874876end
875877
876- function analyze_method! (match:: MethodMatch , argtypes:: Vector{Any} ,
878+ function analyze_method! (match:: MethodMatch , argtypes:: Vector{Any} , invokesig,
877879 flag:: UInt8 , state:: InliningState )
878880 method = match. method
879881 spec_types = match. spec_types
@@ -905,7 +907,7 @@ function analyze_method!(match::MethodMatch, argtypes::Vector{Any},
905907 mi = specialize_method (match; preexisting= true ) # Union{Nothing, MethodInstance}
906908 isa (mi, MethodInstance) || return compileable_specialization (et, match, Effects ())
907909
908- todo = InliningTodo (mi, match, argtypes)
910+ todo = InliningTodo (mi, match, argtypes, invokesig )
909911 # If we don't have caches here, delay resolving this MethodInstance
910912 # until the batch inlining step (or an external post-processing pass)
911913 state. mi_cache === nothing && return todo
@@ -1100,17 +1102,18 @@ function inline_invoke!(
11001102 if isa (result, ConcreteResult)
11011103 item = concrete_result_item (result, state)
11021104 else
1105+ invokesig = invoke_signature (sig. argtypes)
11031106 argtypes = invoke_rewrite (sig. argtypes)
11041107 if isa (result, ConstPropResult)
1105- (; mi) = item = InliningTodo (result. result, argtypes)
1108+ (; mi) = item = InliningTodo (result. result, argtypes, invokesig )
11061109 validate_sparams (mi. sparam_vals) || return nothing
11071110 if argtypes_to_type (argtypes) <: mi.def.sig
11081111 state. mi_cache != = nothing && (item = resolve_todo (item, state, flag))
11091112 handle_single_case! (ir, idx, stmt, item, todo, state. params, true )
11101113 return nothing
11111114 end
11121115 end
1113- item = analyze_method! (match, argtypes, flag, state)
1116+ item = analyze_method! (match, argtypes, invokesig, flag, state)
11141117 end
11151118 handle_single_case! (ir, idx, stmt, item, todo, state. params, true )
11161119 return nothing
@@ -1328,7 +1331,7 @@ function handle_match!(
13281331 # during abstract interpretation: for the purpose of inlining, we can just skip
13291332 # processing this dispatch candidate
13301333 _any (case-> case. sig === spec_types, cases) && return true
1331- item = analyze_method! (match, argtypes, flag, state)
1334+ item = analyze_method! (match, argtypes, nothing , flag, state)
13321335 item === nothing && return false
13331336 push! (cases, InliningCase (spec_types, item))
13341337 return true
@@ -1475,7 +1478,7 @@ function assemble_inline_todo!(ir::IRCode, state::InliningState)
14751478 if isa (result, ConcreteResult)
14761479 item = concrete_result_item (result, state)
14771480 else
1478- item = analyze_method! (info. match, sig. argtypes, flag, state)
1481+ item = analyze_method! (info. match, sig. argtypes, nothing , flag, state)
14791482 end
14801483 handle_single_case! (ir, idx, stmt, item, todo, state. params)
14811484 end
0 commit comments