Skip to content

Commit

Permalink
Restore setindex!(::IRCode, ::SSAValue, ::SSAValue) (#45216)
Browse files Browse the repository at this point in the history
This particular method got removed in f67371d, but it's common
in RAUW-like patterns in external code. I think it is a sensible
method to have, because the metadata on such an instruction will
get deleted on the next compact anyway, so there's not much reason
to attempt to force the API user to pass complete metadata around.
It also enables useful patterns like:
```
ir[idx] = insert_node!(idx-2, NewInstruction(...))
```
  • Loading branch information
Keno authored May 8, 2022
1 parent d4acead commit f9bd142
Showing 1 changed file with 19 additions and 14 deletions.
33 changes: 19 additions & 14 deletions base/compiler/ssair/ir.jl
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,20 @@ function first_insert_for_bb(code, cfg::CFG, block::Int)
error("any insert position isn't found")
end

# SSA values that need renaming
struct OldSSAValue
id::Int
end

# SSA values that are in `new_new_nodes` of an `IncrementalCompact` and are to
# be actually inserted next time (they become `new_nodes` next time)
struct NewSSAValue
id::Int
end

const AnySSAValue = Union{SSAValue, OldSSAValue, NewSSAValue}


# SSA-indexed nodes

struct NewInstruction
Expand Down Expand Up @@ -253,6 +267,10 @@ function setindex!(is::InstructionStream, newval::Instruction, idx::Int)
is.flag[idx] = newval[:flag]
return is
end
function setindex!(is::InstructionStream, newval::AnySSAValue, idx::Int)
is.inst[idx] = newval
return is
end
function setindex!(node::Instruction, newval::Instruction)
node.data[node.idx] = newval
return node
Expand Down Expand Up @@ -312,7 +330,7 @@ function getindex(x::IRCode, s::SSAValue)
end
end

function setindex!(x::IRCode, repl::Instruction, s::SSAValue)
function setindex!(x::IRCode, repl::Union{Instruction, AnySSAValue}, s::SSAValue)
if s.id <= length(x.stmts)
x.stmts[s.id] = repl
else
Expand All @@ -321,19 +339,6 @@ function setindex!(x::IRCode, repl::Instruction, s::SSAValue)
return x
end

# SSA values that need renaming
struct OldSSAValue
id::Int
end

# SSA values that are in `new_new_nodes` of an `IncrementalCompact` and are to
# be actually inserted next time (they become `new_nodes` next time)
struct NewSSAValue
id::Int
end

const AnySSAValue = Union{SSAValue, OldSSAValue, NewSSAValue}

mutable struct UseRefIterator
stmt::Any
relevant::Bool
Expand Down

2 comments on commit f9bd142

@nanosoldier
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Executing the daily package evaluation, I will reply here when finished:

@nanosoldier runtests(ALL, isdaily = true)

@nanosoldier
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your package evaluation job has completed - possible new issues were detected. A full report can be found here.

Please sign in to comment.