Skip to content

Commit

Permalink
Refactors and revert concrete spvals logic
Browse files Browse the repository at this point in the history
  • Loading branch information
Ian Atol committed May 10, 2022
1 parent 0d6db0e commit 3b7c5d8
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 35 deletions.
28 changes: 14 additions & 14 deletions base/compiler/ssair/inlining.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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′)
Expand All @@ -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
Expand Down Expand Up @@ -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]
Expand All @@ -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
Expand All @@ -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
29 changes: 8 additions & 21 deletions base/compiler/ssair/ir.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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
Expand Down

0 comments on commit 3b7c5d8

Please sign in to comment.