Skip to content

Commit 03e5379

Browse files
aviateskLilithHafner
authored andcommitted
optimizer: eliminate allocations (JuliaLang#42833)
1 parent bdd36c4 commit 03e5379

File tree

1 file changed

+11
-25
lines changed

1 file changed

+11
-25
lines changed

base/compiler/ssair/passes.jl

Lines changed: 11 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -76,24 +76,17 @@ end
7676

7777
function compute_value_for_use(ir::IRCode, domtree::DomTree, allblocks::Vector{Int}, du::SSADefUse, phinodes::IdDict{Int, SSAValue}, fidx::Int, use_idx::Int)
7878
# Find the first dominating def
79-
curblock = stmtblock = block_for_inst(ir.cfg, use_idx)
80-
curblock = find_curblock(domtree, allblocks, curblock)
81-
defblockdefs = let curblock = curblock
82-
Int[stmt for stmt in du.defs if block_for_inst(ir.cfg, stmt) == curblock]
83-
end
84-
def = 0
85-
if !isempty(defblockdefs)
86-
if curblock != stmtblock
87-
# Find the last def in this block
88-
def = 0
89-
for x in defblockdefs
90-
def = max(def, x)
91-
end
92-
else
93-
# Find the last def before our use
94-
def = 0
95-
for x in defblockdefs
96-
def = max(def, x >= use_idx ? 0 : x)
79+
stmtblock = block_for_inst(ir.cfg, use_idx)
80+
curblock = find_curblock(domtree, allblocks, stmtblock)
81+
local def = 0
82+
for idx in du.defs
83+
if block_for_inst(ir.cfg, idx) == curblock
84+
if curblock != stmtblock
85+
# Find the last def in this block
86+
def = max(def, idx)
87+
else
88+
# Find the last def before our use
89+
def = max(def, idx >= use_idx ? 0 : idx)
9790
end
9891
end
9992
end
@@ -564,15 +557,10 @@ a result of dead code elimination.
564557
"""
565558
function getfield_elim_pass!(ir::IRCode)
566559
compact = IncrementalCompact(ir)
567-
insertions = Vector{Any}()
568560
defuses = IdDict{Int, Tuple{IdSet{Int}, SSADefUse}}()
569561
lifting_cache = IdDict{Pair{AnySSAValue, Any}, AnySSAValue}()
570-
revisit_worklist = Int[]
571-
#ndone, nmax = 0, 200
572562
for ((_, idx), stmt) in compact
573563
isa(stmt, Expr) || continue
574-
#ndone >= nmax && continue
575-
#ndone += 1
576564
result_t = compact_exprtype(compact, SSAValue(idx))
577565
is_getfield = is_setfield = false
578566
field_ordering = :unspecified
@@ -998,8 +986,6 @@ function adce_pass!(ir::IRCode)
998986
end
999987

1000988
function type_lift_pass!(ir::IRCode)
1001-
type_ctx_uses = Vector{Vector{Int}}[]
1002-
has_non_type_ctx_uses = IdSet{Int}()
1003989
lifted_undef = IdDict{Int, Any}()
1004990
insts = ir.stmts
1005991
for idx in 1:length(insts)

0 commit comments

Comments
 (0)