Skip to content

Commit a1b1435

Browse files
committed
use local cache for uncached inlining callsite
1 parent d2ad177 commit a1b1435

File tree

3 files changed

+29
-2
lines changed

3 files changed

+29
-2
lines changed

base/compiler/optimize.jl

+4-1
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,11 @@ function push!(et::EdgeTracker, ci::CodeInstance)
2121
push!(et, ci.def)
2222
end
2323

24-
struct InliningState{S <: Union{EdgeTracker, Nothing}, T, P}
24+
struct InliningState{S <: Union{EdgeTracker, Nothing}, T, P, U}
2525
params::OptimizationParams
2626
et::S
2727
mi_cache::T
28+
inf_cache::U
2829
policy::P
2930
end
3031

@@ -64,6 +65,7 @@ mutable struct OptimizationState
6465
inlining = InliningState(params,
6566
EdgeTracker(s_edges, frame.valid_worlds),
6667
WorldView(code_cache(interp), frame.world),
68+
get_inference_cache(interp),
6769
inlining_policy(interp))
6870
return new(frame.linfo,
6971
frame.src, nothing, frame.stmt_info, frame.mod, frame.nargs,
@@ -98,6 +100,7 @@ mutable struct OptimizationState
98100
inlining = InliningState(params,
99101
nothing,
100102
WorldView(code_cache(interp), get_world_counter()),
103+
get_inference_cache(interp),
101104
inlining_policy(interp))
102105
return new(linfo,
103106
src, nothing, stmt_info, inmodule, nargs,

base/compiler/ssair/inlining.jl

+18-1
Original file line numberDiff line numberDiff line change
@@ -722,7 +722,7 @@ function resolve_todo(todo::InliningTodo, state::InliningState, flag::UInt8)
722722
(; match) = todo.spec::DelayedInliningSpec
723723

724724
#XXX: update_valid_age!(min_valid[1], max_valid[1], sv)
725-
isconst, src = false, nothing
725+
isconst, src, argtypes = false, nothing, nothing
726726
if isa(match, InferenceResult)
727727
let inferred_src = match.src
728728
if isa(inferred_src, Const)
@@ -734,6 +734,9 @@ function resolve_todo(todo::InliningTodo, state::InliningState, flag::UInt8)
734734
isconst, src = false, inferred_src
735735
end
736736
end
737+
if is_stmt_inline(flag)
738+
argtypes = match.argtypes
739+
end
737740
else
738741
linfo = get(state.mi_cache, todo.mi, nothing)
739742
if linfo isa CodeInstance
@@ -746,6 +749,9 @@ function resolve_todo(todo::InliningTodo, state::InliningState, flag::UInt8)
746749
else
747750
isconst, src = false, linfo
748751
end
752+
if is_stmt_inline(flag)
753+
argtypes = collect(todo.mi.specTypes.parameters)::Vector{Any}
754+
end
749755
end
750756

751757
et = state.et
@@ -755,6 +761,17 @@ function resolve_todo(todo::InliningTodo, state::InliningState, flag::UInt8)
755761
return ConstantCase(src)
756762
end
757763

764+
if argtypes !== nothing && src === nothing
765+
inf_cache = state.inf_cache
766+
inf_result = cache_lookup(todo.mi, argtypes, inf_cache)
767+
if isa(inf_result, InferenceResult)
768+
src = inf_result.src
769+
if isa(src, OptimizationState)
770+
src = src.src
771+
end
772+
end
773+
end
774+
758775
src = state.policy(src, flag, match)
759776

760777
if src === nothing

test/compiler/inline.jl

+7
Original file line numberDiff line numberDiff line change
@@ -538,6 +538,9 @@ end
538538
return a, b
539539
end
540540
end
541+
542+
import Core.Compiler: isType
543+
limited(a) = @noinline(isType(a)) ? @inline(limited(a.parameters[1])) : rand(a)
541544
end
542545

543546
let ci = code_typed1(m.force_inline_explicit, (Int,))
@@ -586,6 +589,10 @@ end
586589
let ci = code_typed1(m.nested, (Int,Int))
587590
@test count(x->isinvoke(x, :notinlined), ci.code) == 1
588591
end
592+
593+
let ci = code_typed1(m.limited, (Any,))
594+
@test count(x->isinvoke(x, :isType), ci.code) == 2
595+
end
589596
end
590597

591598
# Issue #41299 - inlining deletes error check in :>

0 commit comments

Comments
 (0)