@@ -120,12 +120,20 @@ Analyzes `ir` for heap allocations which escape only via `FinalizerEscape`
120
120
`finalize(obj)` just before any return where the allocation doesn't escape.
121
121
"""
122
122
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)
123
124
# Find all allocations that escape only through a finalizer
124
125
isalloc (ir:: IRCode , pc:: Int ) = isexpr (ir. stmts[pc][:inst ], :new )
125
126
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
126
130
for idx in (estate. nargs+ 1 ): length (estate. escapes)
127
131
info = estate. escapes[idx]
128
132
pc = idx - estate. nargs
133
+ if pc > length (ir. stmts)
134
+ # FIXME
135
+ continue
136
+ end
129
137
if has_finalizer_escape (info) && isalloc (ir, pc)
130
138
EARLY_FINALIZE_VERBOSE[] && ccall (:jl_safe_printf , Cvoid, (Ptr{UInt8}, Int), " early_finalize!: Found finalizing alloc at %d\n " , pc)
131
139
push! (to_finalize, pc => info)
@@ -649,6 +657,7 @@ function run_passes(ci::CodeInfo, sv::OptimizationState, caller::InferenceResult
649
657
# @timeit "verify 2" verify_ir(ir)
650
658
@timeit " compact 2" ir = compact! (ir)
651
659
@timeit " SROA" ir, memory_opt = linear_pass! (ir)
660
+ @timeit " pre-EA compact" ir = compact! (ir)
652
661
@timeit " Local EA" estate = analyze_escapes (ir, nargs, #= call_resolved=# true , null_escape_cache)
653
662
if false # memory_opt
654
663
@timeit " memory_opt_pass!" ir = memory_opt_pass! (ir, estate)
0 commit comments