Skip to content

Commit 72622d5

Browse files
author
Ian Atol
committed
Refactors and revert concrete spvals logic
1 parent 72e2263 commit 72622d5

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
@@ -404,7 +404,7 @@ function ir_inline_item!(compact::IncrementalCompact, idx::Int, argexprs::Vector
404404
# face of rename_arguments! mutating in place - should figure out
405405
# something better eventually.
406406
inline_compact[idx′] = nothing
407-
stmt′ = ssa_substitute!(idx′, stmt′, argexprs, sig, sparam_vals, item.mi.sparam_vals, linetable_offset, boundscheck, inline_compact)
407+
stmt′ = ssa_substitute!(idx′, stmt′, argexprs, sig, sparam_vals, linetable_offset, boundscheck, inline_compact)
408408
if isa(stmt′, ReturnNode)
409409
val = stmt′.val
410410
return_value = SSAValue(idx′)
@@ -431,7 +431,7 @@ function ir_inline_item!(compact::IncrementalCompact, idx::Int, argexprs::Vector
431431
inline_compact = IncrementalCompact(compact, spec.ir, compact.result_idx)
432432
for ((_, idx′), stmt′) in inline_compact
433433
inline_compact[idx′] = nothing
434-
stmt′ = ssa_substitute!(idx′, stmt′, argexprs, sig, sparam_vals, item.mi.sparam_vals, linetable_offset, boundscheck, inline_compact)
434+
stmt′ = ssa_substitute!(idx′, stmt′, argexprs, sig, sparam_vals, linetable_offset, boundscheck, inline_compact)
435435
if isa(stmt′, ReturnNode)
436436
if isdefined(stmt′, :val)
437437
val = stmt′.val
@@ -1664,15 +1664,15 @@ function late_inline_special_case!(
16641664
end
16651665

16661666
function ssa_substitute!(idx::Int, @nospecialize(val), arg_replacements::Vector{Any},
1667-
@nospecialize(spsig), spvals::Union{SimpleVector, SSAValue}, concrete_spvals::SimpleVector,
1667+
@nospecialize(spsig), spvals::Union{SimpleVector, SSAValue},
16681668
linetable_offset::Int32, boundscheck::Symbol, compact::IncrementalCompact)
16691669
compact.result[idx][:flag] &= ~IR_FLAG_INBOUNDS
16701670
compact.result[idx][:line] += linetable_offset
1671-
return ssa_substitute_op!(val, arg_replacements, spsig, spvals, concrete_spvals, boundscheck, compact, idx)
1671+
return ssa_substitute_op!(val, arg_replacements, spsig, spvals, boundscheck, compact, idx)
16721672
end
16731673

16741674
function ssa_substitute_op!(@nospecialize(val), arg_replacements::Vector{Any},
1675-
@nospecialize(spsig), spvals::Union{SimpleVector, SSAValue}, concrete_spvals::SimpleVector,
1675+
@nospecialize(spsig), spvals::Union{SimpleVector, SSAValue},
16761676
boundscheck::Symbol, compact::IncrementalCompact, idx::Int)
16771677
if isa(val, Argument)
16781678
return arg_replacements[val.n]
@@ -1688,20 +1688,20 @@ function ssa_substitute_op!(@nospecialize(val), arg_replacements::Vector{Any},
16881688
effect_free(NewInstruction(Expr(:call, Core._svec_ref, false, spvals, e.args[1]), Any)))
16891689
return ret
16901690
end
1691-
elseif head === :cfunction
1692-
@assert !isa(spsig, UnionAll) || !isempty(concrete_spvals)
1693-
e.args[3] = ccall(:jl_instantiate_type_in_env, Any, (Any, Any, Ptr{Any}), e.args[3], spsig, concrete_spvals)
1691+
elseif head === :cfunction && isa(spvals, SimpleVector)
1692+
@assert !isa(spsig, UnionAll) || !isempty(spvals)
1693+
e.args[3] = ccall(:jl_instantiate_type_in_env, Any, (Any, Any, Ptr{Any}), e.args[3], spsig, spvals)
16941694
e.args[4] = svec(Any[
1695-
ccall(:jl_instantiate_type_in_env, Any, (Any, Any, Ptr{Any}), argt, spsig, concrete_spvals)
1695+
ccall(:jl_instantiate_type_in_env, Any, (Any, Any, Ptr{Any}), argt, spsig, spvals)
16961696
for argt in e.args[4]::SimpleVector ]...)
1697-
elseif head === :foreigncall
1698-
@assert !isa(spsig, UnionAll) || !isempty(concrete_spvals)
1697+
elseif head === :foreigncall && isa(spvals, SimpleVector)
1698+
@assert !isa(spsig, UnionAll) || !isempty(spvals)
16991699
for i = 1:length(e.args)
17001700
if i == 2
1701-
e.args[2] = ccall(:jl_instantiate_type_in_env, Any, (Any, Any, Ptr{Any}), e.args[2], spsig, concrete_spvals)
1701+
e.args[2] = ccall(:jl_instantiate_type_in_env, Any, (Any, Any, Ptr{Any}), e.args[2], spsig, spvals)
17021702
elseif i == 3
17031703
e.args[3] = svec(Any[
1704-
ccall(:jl_instantiate_type_in_env, Any, (Any, Any, Ptr{Any}), argt, spsig, concrete_spvals)
1704+
ccall(:jl_instantiate_type_in_env, Any, (Any, Any, Ptr{Any}), argt, spsig, spvals)
17051705
for argt in e.args[3]::SimpleVector ]...)
17061706
end
17071707
end
@@ -1718,7 +1718,7 @@ function ssa_substitute_op!(@nospecialize(val), arg_replacements::Vector{Any},
17181718
isa(val, Union{SSAValue, NewSSAValue}) && return val # avoid infinite loop
17191719
urs = userefs(val)
17201720
for op in urs
1721-
op[] = ssa_substitute_op!(op[], arg_replacements, spsig, spvals, concrete_spvals, boundscheck, compact, idx)
1721+
op[] = ssa_substitute_op!(op[], arg_replacements, spsig, spvals, boundscheck, compact, idx)
17221722
end
17231723
return urs[]
17241724
end

base/compiler/ssair/ir.jl

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

14961496
function fixup_phinode_values!(compact::IncrementalCompact, old_values::Vector{Any}, reify_new_nodes::Bool)
14971497
values = Vector{Any}(undef, length(old_values))
1498-
needs_fixup = false
1498+
fixup = false
14991499
for i = 1:length(old_values)
15001500
isassigned(old_values, i) || continue
1501-
val = old_values[i]
1502-
if isa(val, OldSSAValue)
1503-
val = compact.ssa_rename[val.id]
1504-
if isa(val, SSAValue)
1505-
compact.used_ssas[val.id] += 1
1506-
end
1507-
elseif isa(val, NewSSAValue)
1508-
if reify_new_nodes
1509-
val = SSAValue(length(compact.result) + val.id)
1510-
else
1511-
needs_fixup = true
1512-
end
1513-
end
1514-
values[i] = val
1501+
(; node, needs_fixup) = fixup_node(compact, old_values[i], reify_new_nodes)
1502+
fixup |= needs_fixup
1503+
values[i] = node
15151504
end
1516-
return (values, needs_fixup)
1505+
return (values, fixup)
15171506
end
15181507

15191508
function fixup_node(compact::IncrementalCompact, @nospecialize(stmt), reify_new_nodes::Bool)
@@ -1525,13 +1514,14 @@ function fixup_node(compact::IncrementalCompact, @nospecialize(stmt), reify_new_
15251514
return FixedNode(PhiCNode(node), needs_fixup)
15261515
elseif isa(stmt, NewSSAValue)
15271516
if reify_new_nodes
1528-
return FixedNode(SSAValue(length(compact.result) + stmt.id), false)
1517+
val = SSAValue(length(compact.result) + stmt.id)
1518+
return FixedNode(val, false)
15291519
else
15301520
return FixedNode(stmt, true)
15311521
end
15321522
elseif isa(stmt, OldSSAValue)
15331523
val = compact.ssa_rename[stmt.id]
1534-
if isa(val, SSAValue) && val.id <= length(compact.used_ssas)
1524+
if isa(val, SSAValue)
15351525
compact.used_ssas[val.id] += 1
15361526
end
15371527
return FixedNode(val, false)
@@ -1550,9 +1540,6 @@ function fixup_node(compact::IncrementalCompact, @nospecialize(stmt), reify_new_
15501540
val = compact.ssa_rename[val.id]
15511541
end
15521542
if isa(val, SSAValue) && val.id <= length(compact.used_ssas)
1553-
# If `val.id` is greater than the length of `compact.result` or
1554-
# `compact.used_ssas`, this SSA value is in `new_new_nodes`, so
1555-
# don't count the use
15561543
compact.used_ssas[val.id] += 1
15571544
end
15581545
ur[] = val

0 commit comments

Comments
 (0)