Skip to content

Commit 25e4b37

Browse files
committed
fixup! fixup! fixup! fixup! optimizer: Add early finalize calls
1 parent a036815 commit 25e4b37

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

base/compiler/optimize.jl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,12 +120,20 @@ Analyzes `ir` for heap allocations which escape only via `FinalizerEscape`
120120
`finalize(obj)` just before any return where the allocation doesn't escape.
121121
"""
122122
function early_finalize!(ir::IRCode, estate::EscapeState, domtree::DomTree)
123+
EARLY_FINALIZE_VERBOSE[] && ccall(:jl_safe_printf, Cvoid, (Ptr{UInt8}, Int), "early_finalize!: Analyzing with nargs %d\n", estate.nargs)
123124
# Find all allocations that escape only through a finalizer
124125
isalloc(ir::IRCode, pc::Int) = isexpr(ir.stmts[pc][:inst], :new)
125126
to_finalize = Pair{Int,EscapeInfo}[]
127+
if length(estate.escapes) != estate.nargs+length(ir.stmts)
128+
#=EARLY_FINALIZE_VERBOSE[] &&=# ccall(:jl_safe_printf, Cvoid, (Ptr{UInt8}, Int, Int), "early_finalize!: Mismatched stmts (%d) with escape infos (%d)\n", length(ir.stmts), length(estate.escapes))
129+
end
126130
for idx in (estate.nargs+1):length(estate.escapes)
127131
info = estate.escapes[idx]
128132
pc = idx - estate.nargs
133+
if pc > length(ir.stmts)
134+
# FIXME
135+
continue
136+
end
129137
if has_finalizer_escape(info) && isalloc(ir, pc)
130138
EARLY_FINALIZE_VERBOSE[] && ccall(:jl_safe_printf, Cvoid, (Ptr{UInt8}, Int), "early_finalize!: Found finalizing alloc at %d\n", pc)
131139
push!(to_finalize, pc => info)
@@ -649,6 +657,7 @@ function run_passes(ci::CodeInfo, sv::OptimizationState, caller::InferenceResult
649657
# @timeit "verify 2" verify_ir(ir)
650658
@timeit "compact 2" ir = compact!(ir)
651659
@timeit "SROA" ir, memory_opt = linear_pass!(ir)
660+
@timeit "pre-EA compact" ir = compact!(ir)
652661
@timeit "Local EA" estate = analyze_escapes(ir, nargs, #=call_resolved=#true, null_escape_cache)
653662
if false #memory_opt
654663
@timeit "memory_opt_pass!" ir = memory_opt_pass!(ir, estate)

0 commit comments

Comments
 (0)