Skip to content

NFC: optimizer: eliminate allocations #42833

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 28, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 11 additions & 25 deletions base/compiler/ssair/passes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -76,24 +76,17 @@ end

function compute_value_for_use(ir::IRCode, domtree::DomTree, allblocks::Vector{Int}, du::SSADefUse, phinodes::IdDict{Int, SSAValue}, fidx::Int, use_idx::Int)
# Find the first dominating def
curblock = stmtblock = block_for_inst(ir.cfg, use_idx)
curblock = find_curblock(domtree, allblocks, curblock)
defblockdefs = let curblock = curblock
Int[stmt for stmt in du.defs if block_for_inst(ir.cfg, stmt) == curblock]
end
def = 0
if !isempty(defblockdefs)
if curblock != stmtblock
# Find the last def in this block
def = 0
for x in defblockdefs
def = max(def, x)
end
else
# Find the last def before our use
def = 0
for x in defblockdefs
def = max(def, x >= use_idx ? 0 : x)
stmtblock = block_for_inst(ir.cfg, use_idx)
curblock = find_curblock(domtree, allblocks, stmtblock)
local def = 0
for idx in du.defs
if block_for_inst(ir.cfg, idx) == curblock
if curblock != stmtblock
# Find the last def in this block
def = max(def, idx)
else
# Find the last def before our use
def = max(def, idx >= use_idx ? 0 : idx)
end
end
end
Expand Down Expand Up @@ -564,15 +557,10 @@ a result of dead code elimination.
"""
function getfield_elim_pass!(ir::IRCode)
compact = IncrementalCompact(ir)
insertions = Vector{Any}()
defuses = IdDict{Int, Tuple{IdSet{Int}, SSADefUse}}()
lifting_cache = IdDict{Pair{AnySSAValue, Any}, AnySSAValue}()
revisit_worklist = Int[]
#ndone, nmax = 0, 200
for ((_, idx), stmt) in compact
isa(stmt, Expr) || continue
#ndone >= nmax && continue
#ndone += 1
result_t = compact_exprtype(compact, SSAValue(idx))
is_getfield = is_setfield = false
field_ordering = :unspecified
Expand Down Expand Up @@ -998,8 +986,6 @@ function adce_pass!(ir::IRCode)
end

function type_lift_pass!(ir::IRCode)
type_ctx_uses = Vector{Vector{Int}}[]
has_non_type_ctx_uses = IdSet{Int}()
lifted_undef = IdDict{Int, Any}()
insts = ir.stmts
for idx in 1:length(insts)
Expand Down