Skip to content

Commit 60adc24

Browse files
Replace Sorted Vector with BitSet in optimization passes (#46587)
Co-authored-by: Jameson Nash <[email protected]>
1 parent 0d90a0a commit 60adc24

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

base/compiler/ssair/passes.jl

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ function try_compute_fieldidx_stmt(ir::Union{IncrementalCompact,IRCode}, stmt::E
7272
return try_compute_fieldidx(typ, field)
7373
end
7474

75-
function find_curblock(domtree::DomTree, allblocks::Vector{Int}, curblock::Int)
75+
function find_curblock(domtree::DomTree, allblocks::BitSet, curblock::Int)
7676
# TODO: This can be much faster by looking at current level and only
7777
# searching for those blocks in a sorted order
7878
while !(curblock in allblocks) && curblock !== 0
@@ -92,7 +92,7 @@ function val_for_def_expr(ir::IRCode, def::Int, fidx::Int)
9292
end
9393
end
9494

95-
function compute_value_for_block(ir::IRCode, domtree::DomTree, allblocks::Vector{Int}, du::SSADefUse, phinodes::IdDict{Int, SSAValue}, fidx::Int, curblock::Int)
95+
function compute_value_for_block(ir::IRCode, domtree::DomTree, allblocks::BitSet, du::SSADefUse, phinodes::IdDict{Int, SSAValue}, fidx::Int, curblock::Int)
9696
curblock = find_curblock(domtree, allblocks, curblock)
9797
def = 0
9898
for stmt in du.defs
@@ -103,7 +103,7 @@ function compute_value_for_block(ir::IRCode, domtree::DomTree, allblocks::Vector
103103
def == 0 ? phinodes[curblock] : val_for_def_expr(ir, def, fidx)
104104
end
105105

106-
function compute_value_for_use(ir::IRCode, domtree::DomTree, allblocks::Vector{Int},
106+
function compute_value_for_use(ir::IRCode, domtree::DomTree, allblocks::BitSet,
107107
du::SSADefUse, phinodes::IdDict{Int, SSAValue}, fidx::Int, use::Int)
108108
def, useblock, curblock = find_def_for_use(ir, domtree, allblocks, du, use)
109109
if def == 0
@@ -122,7 +122,7 @@ end
122122
# even when the allocation contains an uninitialized field, we try an extra effort to check
123123
# if this load at `idx` have any "safe" `setfield!` calls that define the field
124124
function has_safe_def(
125-
ir::IRCode, domtree::DomTree, allblocks::Vector{Int}, du::SSADefUse,
125+
ir::IRCode, domtree::DomTree, allblocks::BitSet, du::SSADefUse,
126126
newidx::Int, idx::Int)
127127
def, _, _ = find_def_for_use(ir, domtree, allblocks, du, idx)
128128
# will throw since we already checked this `:new` site doesn't define this field
@@ -157,7 +157,7 @@ end
157157

158158
# find the first dominating def for the given use
159159
function find_def_for_use(
160-
ir::IRCode, domtree::DomTree, allblocks::Vector{Int}, du::SSADefUse, use::Int, inclusive::Bool=false)
160+
ir::IRCode, domtree::DomTree, allblocks::BitSet, du::SSADefUse, use::Int, inclusive::Bool=false)
161161
useblock = block_for_inst(ir.cfg, use)
162162
curblock = find_curblock(domtree, allblocks, useblock)
163163
local def = 0
@@ -1320,7 +1320,7 @@ function sroa_mutables!(ir::IRCode, defuses::IdDict{Int, Tuple{SPCSet, SSADefUse
13201320
# but we should come up with semantics for well defined semantics
13211321
# for uninitialized fields first.
13221322
ndefuse = length(fielddefuse)
1323-
blocks = Vector{Tuple{#=phiblocks=# Vector{Int}, #=allblocks=# Vector{Int}}}(undef, ndefuse)
1323+
blocks = Vector{Tuple{#=phiblocks=# Vector{Int}, #=allblocks=# BitSet}}(undef, ndefuse)
13241324
for fidx in 1:ndefuse
13251325
du = fielddefuse[fidx]
13261326
isempty(du.uses) && continue
@@ -1331,7 +1331,7 @@ function sroa_mutables!(ir::IRCode, defuses::IdDict{Int, Tuple{SPCSet, SSADefUse
13311331
else
13321332
phiblocks = iterated_dominance_frontier(ir.cfg, ldu, get!(lazydomtree))
13331333
end
1334-
allblocks = sort!(vcat(phiblocks, ldu.def_bbs); alg=QuickSort)
1334+
allblocks = union!(BitSet(phiblocks), ldu.def_bbs)
13351335
blocks[fidx] = phiblocks, allblocks
13361336
if fidx + 1 > length(defexpr.args)
13371337
for i = 1:length(du.uses)

0 commit comments

Comments
 (0)