From 5e92b7d92389b66408091ce228fffe8a3146d760 Mon Sep 17 00:00:00 2001 From: Ian Atol Date: Mon, 9 May 2022 17:00:01 -0700 Subject: [PATCH] Refactors and revert concrete spvals logic --- base/compiler/ssair/inlining.jl | 28 ++++++++++++++-------------- base/compiler/ssair/ir.jl | 29 ++++++++--------------------- 2 files changed, 22 insertions(+), 35 deletions(-) diff --git a/base/compiler/ssair/inlining.jl b/base/compiler/ssair/inlining.jl index 26a9435b29e7ab..bb87733385b72c 100644 --- a/base/compiler/ssair/inlining.jl +++ b/base/compiler/ssair/inlining.jl @@ -389,7 +389,7 @@ function ir_inline_item!(compact::IncrementalCompact, idx::Int, argexprs::Vector # face of rename_arguments! mutating in place - should figure out # something better eventually. inline_compact[idx′] = nothing - stmt′ = ssa_substitute!(idx′, stmt′, argexprs, sig, sparam_vals, item.mi.sparam_vals, linetable_offset, boundscheck, inline_compact) + stmt′ = ssa_substitute!(idx′, stmt′, argexprs, sig, sparam_vals, linetable_offset, boundscheck, inline_compact) if isa(stmt′, ReturnNode) val = stmt′.val return_value = SSAValue(idx′) @@ -414,7 +414,7 @@ function ir_inline_item!(compact::IncrementalCompact, idx::Int, argexprs::Vector inline_compact = IncrementalCompact(compact, spec.ir, compact.result_idx) for ((_, idx′), stmt′) in inline_compact inline_compact[idx′] = nothing - stmt′ = ssa_substitute!(idx′, stmt′, argexprs, sig, sparam_vals, item.mi.sparam_vals, linetable_offset, boundscheck, inline_compact) + stmt′ = ssa_substitute!(idx′, stmt′, argexprs, sig, sparam_vals, linetable_offset, boundscheck, inline_compact) if isa(stmt′, ReturnNode) if isdefined(stmt′, :val) val = stmt′.val @@ -1590,15 +1590,15 @@ function late_inline_special_case!( end function ssa_substitute!(idx::Int, @nospecialize(val), arg_replacements::Vector{Any}, - @nospecialize(spsig), spvals::Union{SimpleVector, SSAValue}, concrete_spvals::SimpleVector, + @nospecialize(spsig), spvals::Union{SimpleVector, SSAValue}, linetable_offset::Int32, boundscheck::Symbol, compact::IncrementalCompact) compact.result[idx][:flag] &= ~IR_FLAG_INBOUNDS compact.result[idx][:line] += linetable_offset - return ssa_substitute_op!(val, arg_replacements, spsig, spvals, concrete_spvals, boundscheck, compact, idx) + return ssa_substitute_op!(val, arg_replacements, spsig, spvals, boundscheck, compact, idx) end function ssa_substitute_op!(@nospecialize(val), arg_replacements::Vector{Any}, - @nospecialize(spsig), spvals::Union{SimpleVector, SSAValue}, concrete_spvals::SimpleVector, + @nospecialize(spsig), spvals::Union{SimpleVector, SSAValue}, boundscheck::Symbol, compact::IncrementalCompact, idx::Int) if isa(val, Argument) return arg_replacements[val.n] @@ -1614,20 +1614,20 @@ function ssa_substitute_op!(@nospecialize(val), arg_replacements::Vector{Any}, effect_free(NewInstruction(Expr(:call, Core._svec_ref, false, spvals, e.args[1]), Any))) return ret end - elseif head === :cfunction - @assert !isa(spsig, UnionAll) || !isempty(concrete_spvals) - e.args[3] = ccall(:jl_instantiate_type_in_env, Any, (Any, Any, Ptr{Any}), e.args[3], spsig, concrete_spvals) + elseif head === :cfunction && isa(spvals, SimpleVector) + @assert !isa(spsig, UnionAll) || !isempty(spvals) + e.args[3] = ccall(:jl_instantiate_type_in_env, Any, (Any, Any, Ptr{Any}), e.args[3], spsig, spvals) e.args[4] = svec(Any[ - ccall(:jl_instantiate_type_in_env, Any, (Any, Any, Ptr{Any}), argt, spsig, concrete_spvals) + ccall(:jl_instantiate_type_in_env, Any, (Any, Any, Ptr{Any}), argt, spsig, spvals) for argt in e.args[4]::SimpleVector ]...) - elseif head === :foreigncall - @assert !isa(spsig, UnionAll) || !isempty(concrete_spvals) + elseif head === :foreigncall && isa(spvals, SimpleVector) + @assert !isa(spsig, UnionAll) || !isempty(spvals) for i = 1:length(e.args) if i == 2 - e.args[2] = ccall(:jl_instantiate_type_in_env, Any, (Any, Any, Ptr{Any}), e.args[2], spsig, concrete_spvals) + e.args[2] = ccall(:jl_instantiate_type_in_env, Any, (Any, Any, Ptr{Any}), e.args[2], spsig, spvals) elseif i == 3 e.args[3] = svec(Any[ - ccall(:jl_instantiate_type_in_env, Any, (Any, Any, Ptr{Any}), argt, spsig, concrete_spvals) + ccall(:jl_instantiate_type_in_env, Any, (Any, Any, Ptr{Any}), argt, spsig, spvals) for argt in e.args[3]::SimpleVector ]...) end end @@ -1643,7 +1643,7 @@ function ssa_substitute_op!(@nospecialize(val), arg_replacements::Vector{Any}, end urs = userefs(val) for op in urs - op[] = ssa_substitute_op!(op[], arg_replacements, spsig, spvals, concrete_spvals, boundscheck, compact, idx) + op[] = ssa_substitute_op!(op[], arg_replacements, spsig, spvals, boundscheck, compact, idx) end return urs[] end diff --git a/base/compiler/ssair/ir.jl b/base/compiler/ssair/ir.jl index 9e5b4a4d1a0b4c..948a16783c8920 100644 --- a/base/compiler/ssair/ir.jl +++ b/base/compiler/ssair/ir.jl @@ -1474,25 +1474,14 @@ end function fixup_phinode_values!(compact::IncrementalCompact, old_values::Vector{Any}, reify_new_nodes::Bool) values = Vector{Any}(undef, length(old_values)) - needs_fixup = false + fixup = false for i = 1:length(old_values) isassigned(old_values, i) || continue - val = old_values[i] - if isa(val, OldSSAValue) - val = compact.ssa_rename[val.id] - if isa(val, SSAValue) - compact.used_ssas[val.id] += 1 - end - elseif isa(val, NewSSAValue) - if reify_new_nodes - val = SSAValue(length(compact.result) + val.id) - else - needs_fixup = true - end - end - values[i] = val + (; node, needs_fixup) = fixup_node(compact, old_values[i], reify_new_nodes) + fixup |= needs_fixup + values[i] = node end - return (values, needs_fixup) + return (values, fixup) end function fixup_node(compact::IncrementalCompact, @nospecialize(stmt), reify_new_nodes::Bool) @@ -1504,13 +1493,14 @@ function fixup_node(compact::IncrementalCompact, @nospecialize(stmt), reify_new_ return FixedNode(PhiCNode(node), needs_fixup) elseif isa(stmt, NewSSAValue) if reify_new_nodes - return FixedNode(SSAValue(length(compact.result) + stmt.id), false) + val = SSAValue(length(compact.result) + stmt.id) + return FixedNode(val, false) else return FixedNode(stmt, true) end elseif isa(stmt, OldSSAValue) val = compact.ssa_rename[stmt.id] - if isa(val, SSAValue) && val.id <= length(compact.used_ssas) + if isa(val, SSAValue) compact.used_ssas[val.id] += 1 end return FixedNode(val, false) @@ -1529,9 +1519,6 @@ function fixup_node(compact::IncrementalCompact, @nospecialize(stmt), reify_new_ val = compact.ssa_rename[val.id] end if isa(val, SSAValue) && val.id <= length(compact.used_ssas) - # If `val.id` is greater than the length of `compact.result` or - # `compact.used_ssas`, this SSA value is in `new_new_nodes`, so - # don't count the use compact.used_ssas[val.id] += 1 end ur[] = val