summaryrefslogtreecommitdiff
path: root/vendor/github.com/tetratelabs/wazero/internal/engine/wazevo/ssa/instructions.go
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/github.com/tetratelabs/wazero/internal/engine/wazevo/ssa/instructions.go')
-rw-r--r--vendor/github.com/tetratelabs/wazero/internal/engine/wazevo/ssa/instructions.go47
1 files changed, 28 insertions, 19 deletions
diff --git a/vendor/github.com/tetratelabs/wazero/internal/engine/wazevo/ssa/instructions.go b/vendor/github.com/tetratelabs/wazero/internal/engine/wazevo/ssa/instructions.go
index 3e3482efc..9a3d1da6e 100644
--- a/vendor/github.com/tetratelabs/wazero/internal/engine/wazevo/ssa/instructions.go
+++ b/vendor/github.com/tetratelabs/wazero/internal/engine/wazevo/ssa/instructions.go
@@ -25,11 +25,13 @@ type Instruction struct {
v3 Value
vs Values
typ Type
- blk BasicBlock
- targets []BasicBlock
prev, next *Instruction
- rValue Value
+ // rValue is the (first) return value of this instruction.
+ // For branching instructions except for OpcodeBrTable, they hold BlockID to jump cast to Value.
+ rValue Value
+ // rValues are the rest of the return values of this instruction.
+ // For OpcodeBrTable, it holds the list of BlockID to jump cast to Value.
rValues Values
gid InstructionGroupID
sourceOffset SourceOffset
@@ -105,6 +107,9 @@ type InstructionGroupID uint32
// Returns Value(s) produced by this instruction if any.
// The `first` is the first return value, and `rest` is the rest of the values.
func (i *Instruction) Returns() (first Value, rest []Value) {
+ if i.IsBranching() {
+ return ValueInvalid, nil
+ }
return i.rValue, i.rValues.View()
}
@@ -2077,7 +2082,7 @@ func (i *Instruction) InvertBrx() {
}
// BranchData returns the branch data for this instruction necessary for backends.
-func (i *Instruction) BranchData() (condVal Value, blockArgs []Value, target BasicBlock) {
+func (i *Instruction) BranchData() (condVal Value, blockArgs []Value, target BasicBlockID) {
switch i.opcode {
case OpcodeJump:
condVal = ValueInvalid
@@ -2087,17 +2092,17 @@ func (i *Instruction) BranchData() (condVal Value, blockArgs []Value, target Bas
panic("BUG")
}
blockArgs = i.vs.View()
- target = i.blk
+ target = BasicBlockID(i.rValue)
return
}
// BrTableData returns the branch table data for this instruction necessary for backends.
-func (i *Instruction) BrTableData() (index Value, targets []BasicBlock) {
+func (i *Instruction) BrTableData() (index Value, targets Values) {
if i.opcode != OpcodeBrTable {
panic("BUG: BrTableData only available for OpcodeBrTable")
}
index = i.v
- targets = i.targets
+ targets = i.rValues
return
}
@@ -2105,7 +2110,7 @@ func (i *Instruction) BrTableData() (index Value, targets []BasicBlock) {
func (i *Instruction) AsJump(vs Values, target BasicBlock) *Instruction {
i.opcode = OpcodeJump
i.vs = vs
- i.blk = target
+ i.rValue = Value(target.ID())
return i
}
@@ -2130,7 +2135,7 @@ func (i *Instruction) AsBrz(v Value, args Values, target BasicBlock) {
i.opcode = OpcodeBrz
i.v = v
i.vs = args
- i.blk = target
+ i.rValue = Value(target.ID())
}
// AsBrnz initializes this instruction as a branch-if-not-zero instruction with OpcodeBrnz.
@@ -2138,15 +2143,16 @@ func (i *Instruction) AsBrnz(v Value, args Values, target BasicBlock) *Instructi
i.opcode = OpcodeBrnz
i.v = v
i.vs = args
- i.blk = target
+ i.rValue = Value(target.ID())
return i
}
// AsBrTable initializes this instruction as a branch-table instruction with OpcodeBrTable.
-func (i *Instruction) AsBrTable(index Value, targets []BasicBlock) {
+// targets is a list of basic block IDs cast to Values.
+func (i *Instruction) AsBrTable(index Value, targets Values) {
i.opcode = OpcodeBrTable
i.v = index
- i.targets = targets
+ i.rValues = targets
}
// AsCall initializes this instruction as a call instruction with OpcodeCall.
@@ -2531,7 +2537,8 @@ func (i *Instruction) Format(b Builder) string {
if i.IsFallthroughJump() {
vs[0] = " fallthrough"
} else {
- vs[0] = " " + i.blk.(*basicBlock).Name()
+ blockId := BasicBlockID(i.rValue)
+ vs[0] = " " + b.BasicBlock(blockId).Name()
}
for idx := range view {
vs[idx+1] = view[idx].Format(b)
@@ -2542,7 +2549,8 @@ func (i *Instruction) Format(b Builder) string {
view := i.vs.View()
vs := make([]string, len(view)+2)
vs[0] = " " + i.v.Format(b)
- vs[1] = i.blk.(*basicBlock).Name()
+ blockId := BasicBlockID(i.rValue)
+ vs[1] = b.BasicBlock(blockId).Name()
for idx := range view {
vs[idx+2] = view[idx].Format(b)
}
@@ -2551,8 +2559,8 @@ func (i *Instruction) Format(b Builder) string {
// `BrTable index, [label1, label2, ... labelN]`
instSuffix = fmt.Sprintf(" %s", i.v.Format(b))
instSuffix += ", ["
- for i, target := range i.targets {
- blk := target.(*basicBlock)
+ for i, target := range i.rValues.View() {
+ blk := b.BasicBlock(BasicBlockID(target))
if i == 0 {
instSuffix += blk.Name()
} else {
@@ -2621,11 +2629,12 @@ func (i *Instruction) Format(b Builder) string {
instr := i.opcode.String() + instSuffix
var rvs []string
- if rv := i.rValue; rv.Valid() {
- rvs = append(rvs, rv.formatWithType(b))
+ r1, rs := i.Returns()
+ if r1.Valid() {
+ rvs = append(rvs, r1.formatWithType(b))
}
- for _, v := range i.rValues.View() {
+ for _, v := range rs {
rvs = append(rvs, v.formatWithType(b))
}