Skip to content

Commit 3b7c5d8

Browse files
author
Ian Atol
committed
Refactors and revert concrete spvals logic
1 parent 0d6db0e commit 3b7c5d8

File tree

2 files changed

+22
-35
lines changed

2 files changed

+22
-35
lines changed

base/compiler/ssair/inlining.jl

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,7 @@ function ir_inline_item!(compact::IncrementalCompact, idx::Int, argexprs::Vector
389389
# face of rename_arguments! mutating in place - should figure out
390390
# something better eventually.
391391
inline_compact[idx′] = nothing
392-
stmt′ = ssa_substitute!(idx′, stmt′, argexprs, sig, sparam_vals, item.mi.sparam_vals, linetable_offset, boundscheck, inline_compact)
392+
stmt′ = ssa_substitute!(idx′, stmt′, argexprs, sig, sparam_vals, linetable_offset, boundscheck, inline_compact)
393393
if isa(stmt′, ReturnNode)
394394
val = stmt′.val
395395
return_value = SSAValue(idx′)
@@ -414,7 +414,7 @@ function ir_inline_item!(compact::IncrementalCompact, idx::Int, argexprs::Vector
414414
inline_compact = IncrementalCompact(compact, spec.ir, compact.result_idx)
415415
for ((_, idx′), stmt′) in inline_compact
416416
inline_compact[idx′] = nothing
417-
stmt′ = ssa_substitute!(idx′, stmt′, argexprs, sig, sparam_vals, item.mi.sparam_vals, linetable_offset, boundscheck, inline_compact)
417+
stmt′ = ssa_substitute!(idx′, stmt′, argexprs, sig, sparam_vals, linetable_offset, boundscheck, inline_compact)
418418
if isa(stmt′, ReturnNode)
419419
if isdefined(stmt′, :val)
420420
val = stmt′.val
@@ -1590,15 +1590,15 @@ function late_inline_special_case!(
15901590
end
15911591

15921592
function ssa_substitute!(idx::Int, @nospecialize(val), arg_replacements::Vector{Any},
1593-
@nospecialize(spsig), spvals::Union{SimpleVector, SSAValue}, concrete_spvals::SimpleVector,
1593+
@nospecialize(spsig), spvals::Union{SimpleVector, SSAValue},
15941594
linetable_offset::Int32, boundscheck::Symbol, compact::IncrementalCompact)
15951595
compact.result[idx][:flag] &= ~IR_FLAG_INBOUNDS
15961596
compact.result[idx][:line] += linetable_offset
1597-
return ssa_substitute_op!(val, arg_replacements, spsig, spvals, concrete_spvals, boundscheck, compact, idx)
1597+
return ssa_substitute_op!(val, arg_replacements, spsig, spvals, boundscheck, compact, idx)
15981598
end
15991599

16001600
function ssa_substitute_op!(@nospecialize(val), arg_replacements::Vector{Any},
1601-
@nospecialize(spsig), spvals::Union{SimpleVector, SSAValue}, concrete_spvals::SimpleVector,
1601+
@nospecialize(spsig), spvals::Union{SimpleVector, SSAValue},
16021602
boundscheck::Symbol, compact::IncrementalCompact, idx::Int)
16031603
if isa(val, Argument)
16041604
return arg_replacements[val.n]
@@ -1614,20 +1614,20 @@ function ssa_substitute_op!(@nospecialize(val), arg_replacements::Vector{Any},
16141614
effect_free(NewInstruction(Expr(:call, Core._svec_ref, false, spvals, e.args[1]), Any)))
16151615
return ret
16161616
end
1617-
elseif head === :cfunction
1618-
@assert !isa(spsig, UnionAll) || !isempty(concrete_spvals)
1619-
e.args[3] = ccall(:jl_instantiate_type_in_env, Any, (Any, Any, Ptr{Any}), e.args[3], spsig, concrete_spvals)
1617+
elseif head === :cfunction && isa(spvals, SimpleVector)
1618+
@assert !isa(spsig, UnionAll) || !isempty(spvals)
1619+
e.args[3] = ccall(:jl_instantiate_type_in_env, Any, (Any, Any, Ptr{Any}), e.args[3], spsig, spvals)
16201620
e.args[4] = svec(Any[
1621-
ccall(:jl_instantiate_type_in_env, Any, (Any, Any, Ptr{Any}), argt, spsig, concrete_spvals)
1621+
ccall(:jl_instantiate_type_in_env, Any, (Any, Any, Ptr{Any}), argt, spsig, spvals)
16221622
for argt in e.args[4]::SimpleVector ]...)
1623-
elseif head === :foreigncall
1624-
@assert !isa(spsig, UnionAll) || !isempty(concrete_spvals)
1623+
elseif head === :foreigncall isa(spvals, SimpleVector)
1624+
@assert !isa(spsig, UnionAll) || !isempty(spvals)
16251625
for i = 1:length(e.args)
16261626
if i == 2
1627-
e.args[2] = ccall(:jl_instantiate_type_in_env, Any, (Any, Any, Ptr{Any}), e.args[2], spsig, concrete_spvals)
1627+
e.args[2] = ccall(:jl_instantiate_type_in_env, Any, (Any, Any, Ptr{Any}), e.args[2], spsig, spvals)
16281628
elseif i == 3
16291629
e.args[3] = svec(Any[
1630-
ccall(:jl_instantiate_type_in_env, Any, (Any, Any, Ptr{Any}), argt, spsig, concrete_spvals)
1630+
ccall(:jl_instantiate_type_in_env, Any, (Any, Any, Ptr{Any}), argt, spsig, spvals)
16311631
for argt in e.args[3]::SimpleVector ]...)
16321632
end
16331633
end
@@ -1643,7 +1643,7 @@ function ssa_substitute_op!(@nospecialize(val), arg_replacements::Vector{Any},
16431643
end
16441644
urs = userefs(val)
16451645
for op in urs
1646-
op[] = ssa_substitute_op!(op[], arg_replacements, spsig, spvals, concrete_spvals, boundscheck, compact, idx)
1646+
op[] = ssa_substitute_op!(op[], arg_replacements, spsig, spvals, boundscheck, compact, idx)
16471647
end
16481648
return urs[]
16491649
end

base/compiler/ssair/ir.jl

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1474,25 +1474,14 @@ end
14741474

14751475
function fixup_phinode_values!(compact::IncrementalCompact, old_values::Vector{Any}, reify_new_nodes::Bool)
14761476
values = Vector{Any}(undef, length(old_values))
1477-
needs_fixup = false
1477+
fixup = false
14781478
for i = 1:length(old_values)
14791479
isassigned(old_values, i) || continue
1480-
val = old_values[i]
1481-
if isa(val, OldSSAValue)
1482-
val = compact.ssa_rename[val.id]
1483-
if isa(val, SSAValue)
1484-
compact.used_ssas[val.id] += 1
1485-
end
1486-
elseif isa(val, NewSSAValue)
1487-
if reify_new_nodes
1488-
val = SSAValue(length(compact.result) + val.id)
1489-
else
1490-
needs_fixup = true
1491-
end
1492-
end
1493-
values[i] = val
1480+
(; node, needs_fixup) = fixup_node(compact, old_values[i], reify_new_nodes)
1481+
fixup |= needs_fixup
1482+
values[i] = node
14941483
end
1495-
return (values, needs_fixup)
1484+
return (values, fixup)
14961485
end
14971486

14981487
function fixup_node(compact::IncrementalCompact, @nospecialize(stmt), reify_new_nodes::Bool)
@@ -1504,13 +1493,14 @@ function fixup_node(compact::IncrementalCompact, @nospecialize(stmt), reify_new_
15041493
return FixedNode(PhiCNode(node), needs_fixup)
15051494
elseif isa(stmt, NewSSAValue)
15061495
if reify_new_nodes
1507-
return FixedNode(SSAValue(length(compact.result) + stmt.id), false)
1496+
val = SSAValue(length(compact.result) + stmt.id)
1497+
return FixedNode(val, false)
15081498
else
15091499
return FixedNode(stmt, true)
15101500
end
15111501
elseif isa(stmt, OldSSAValue)
15121502
val = compact.ssa_rename[stmt.id]
1513-
if isa(val, SSAValue) && val.id <= length(compact.used_ssas)
1503+
if isa(val, SSAValue)
15141504
compact.used_ssas[val.id] += 1
15151505
end
15161506
return FixedNode(val, false)
@@ -1529,9 +1519,6 @@ function fixup_node(compact::IncrementalCompact, @nospecialize(stmt), reify_new_
15291519
val = compact.ssa_rename[val.id]
15301520
end
15311521
if isa(val, SSAValue) && val.id <= length(compact.used_ssas)
1532-
# If `val.id` is greater than the length of `compact.result` or
1533-
# `compact.used_ssas`, this SSA value is in `new_new_nodes`, so
1534-
# don't count the use
15351522
compact.used_ssas[val.id] += 1
15361523
end
15371524
ur[] = val

0 commit comments

Comments
 (0)