Skip to content

Commit a0a68a5

Browse files
authored
Tighter array eltype for renumber_ssa (JuliaLang#37499)
Unlike `renumber_ssa2` in `compiler/ir.jl` which actually takes an array with elements of many different types, all callers of `renumber_ssa` (and `renumber_ssa!`) only ever assign `SSAValue` to the array. Also no one ever checks `isassigned` on this array so a `Vector{SSAValue}` should work just fine here. Try to maintain a similar level of error checking by replacing `#undef` with `SSAValue(-1)` (already used by `construct_ssa!`) and adding an assertion in `renumber_ssa` to check for cases that throws `UndefVarError` previously. Also removed an unused parameter.
1 parent 1ad4ada commit a0a68a5

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

base/compiler/ssair/slot2ssa.jl

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -57,21 +57,19 @@ function scan_slot_def_use(nargs::Int, ci::CodeInfo, code::Vector{Any})
5757
result
5858
end
5959

60-
function renumber_ssa(stmt::SSAValue, ssanums::Vector{Any}, new_ssa::Bool=false, used_ssa::Union{Nothing, Vector{Int}}=nothing)
60+
function renumber_ssa(stmt::SSAValue, ssanums::Vector{SSAValue}, new_ssa::Bool=false)
6161
id = stmt.id
6262
if id > length(ssanums)
6363
return stmt
6464
end
6565
val = ssanums[id]
66-
if isa(val, SSAValue) && used_ssa !== nothing
67-
used_ssa[val.id] += 1
68-
end
66+
@assert val.id > 0
6967
return val
7068
end
7169

72-
function renumber_ssa!(@nospecialize(stmt), ssanums::Vector{Any}, new_ssa::Bool=false, used_ssa::Union{Nothing, Vector{Int}}=nothing)
73-
isa(stmt, SSAValue) && return renumber_ssa(stmt, ssanums, new_ssa, used_ssa)
74-
return ssamap(val->renumber_ssa(val, ssanums, new_ssa, used_ssa), stmt)
70+
function renumber_ssa!(@nospecialize(stmt), ssanums::Vector{SSAValue}, new_ssa::Bool=false)
71+
isa(stmt, SSAValue) && return renumber_ssa(stmt, ssanums, new_ssa)
72+
return ssamap(val->renumber_ssa(val, ssanums, new_ssa), stmt)
7573
end
7674

7775
function make_ssa!(ci::CodeInfo, code::Vector{Any}, idx, slot, @nospecialize(typ))
@@ -428,8 +426,11 @@ function domsort_ssa!(ir::IRCode, domtree::DomTree)
428426
end
429427
end
430428
result = InstructionStream(nstmts + ncritbreaks + nnewfallthroughs)
431-
inst_rename = Vector{Any}(undef, length(ir.stmts) + length(ir.new_nodes))
432-
for i = 1:length(ir.new_nodes)
429+
inst_rename = Vector{SSAValue}(undef, length(ir.stmts) + length(ir.new_nodes))
430+
@inbounds for i = 1:length(ir.stmts)
431+
inst_rename[i] = SSAValue(-1)
432+
end
433+
@inbounds for i = 1:length(ir.new_nodes)
433434
inst_rename[i + length(ir.stmts)] = SSAValue(i + length(result))
434435
end
435436
bb_start_off = 0
@@ -802,7 +803,7 @@ function construct_ssa!(ci::CodeInfo, ir::IRCode, domtree::DomTree, defuse, narg
802803
# Convert into IRCode form
803804
nstmts = length(ir.stmts)
804805
new_code = Vector{Any}(undef, nstmts)
805-
ssavalmap = Any[SSAValue(-1) for _ in 0:length(ci.ssavaluetypes)]
806+
ssavalmap = fill(SSAValue(-1), length(ci.ssavaluetypes) + 1)
806807
result_types = Any[Any for _ in 1:nstmts]
807808
# Detect statement positions for assignments and construct array
808809
for (bb, idx) in bbidxiter(ir)

0 commit comments

Comments
 (0)