Skip to content

Commit 65c1dde

Browse files
committed
update EA: fix conservative propagation
1 parent 447b8ac commit 65c1dde

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

base/compiler/ssair/EscapeAnalysis/EscapeAnalysis.jl

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -694,9 +694,7 @@ function analyze_escapes(ir::IRCode, nargs::Int)
694694
head === :gc_preserve_end # `GC.@preserve` expressions themselves won't be used anywhere
695695
continue
696696
else
697-
for x in stmt.args
698-
add_escape_change!(astate, x, ⊤)
699-
end
697+
add_conservative_changes!(astate, pc, stmt.args)
700698
end
701699
elseif isa(stmt, ReturnNode)
702700
if isdefined(stmt, :val)
@@ -1040,7 +1038,7 @@ function escape_invoke!(astate::AnalysisState, pc::Int, args::Vector{Any})
10401038
linfo = first(args)::MethodInstance
10411039
cache = get(GLOBAL_ESCAPE_CACHE, linfo, nothing)
10421040
if cache === nothing
1043-
add_fallback_changes!(astate, pc, args, 2)
1041+
add_conservative_changes!(astate, pc, args, 2)
10441042
else
10451043
argescapes = argescapes_from_cache(cache)
10461044
ret = SSAValue(pc)
@@ -1190,15 +1188,22 @@ function add_fallback_changes!(astate::AnalysisState, pc::Int, args::Vector{Any}
11901188
end
11911189
end
11921190

1191+
function add_conservative_changes!(astate::AnalysisState, pc::Int, args::Vector{Any},
1192+
first_idx::Int = 1, last_idx::Int = length(args))
1193+
for i in first_idx:last_idx
1194+
add_escape_change!(astate, args[i], ⊤)
1195+
end
1196+
add_escape_change!(astate, SSAValue(pc), ⊤) # it may return GlobalRef etc.
1197+
return nothing
1198+
end
1199+
11931200
# escape every argument `(args[6:length(args[3])])` and the name `args[1]`
11941201
# TODO: we can apply a similar strategy like builtin calls to specialize some foreigncalls
11951202
function escape_foreigncall!(astate::AnalysisState, pc::Int, args::Vector{Any})
11961203
nargs = length(args)
11971204
if nargs < 6
11981205
# invalid foreigncall, just escape everything
1199-
for i = 1:length(args)
1200-
add_escape_change!(astate, args[i], ⊤)
1201-
end
1206+
add_conservative_changes!(astate, pc, args)
12021207
return
12031208
end
12041209
argtypes = args[3]::SimpleVector
@@ -1271,10 +1276,7 @@ function escape_call!(astate::AnalysisState, pc::Int, args::Vector{Any})
12711276
if result === missing
12721277
# if this call hasn't been handled by any of pre-defined handlers,
12731278
# we escape this call conservatively
1274-
for i in 2:length(args)
1275-
add_escape_change!(astate, args[i], ⊤)
1276-
end
1277-
add_escape_change!(astate, SSAValue(pc), ⊤)
1279+
add_conservative_changes!(astate, pc, args)
12781280
return
12791281
elseif result === true
12801282
add_liveness_changes!(astate, pc, args, 2)

0 commit comments

Comments
 (0)