diff options
Diffstat (limited to 'vendor/github.com/tetratelabs/wazero/internal/engine/wazevo/frontend')
4 files changed, 12 insertions, 38 deletions
diff --git a/vendor/github.com/tetratelabs/wazero/internal/engine/wazevo/frontend/frontend.go b/vendor/github.com/tetratelabs/wazero/internal/engine/wazevo/frontend/frontend.go index 42cc21dcd..eebdba034 100644 --- a/vendor/github.com/tetratelabs/wazero/internal/engine/wazevo/frontend/frontend.go +++ b/vendor/github.com/tetratelabs/wazero/internal/engine/wazevo/frontend/frontend.go @@ -275,7 +275,7 @@ func (c *Compiler) LowerToSSA() { builder.DefineVariable(variable, value, entryBlock) c.setWasmLocalVariable(wasm.Index(i), variable) } - c.declareWasmLocals(entryBlock) + c.declareWasmLocals() c.declareNecessaryVariables() c.lowerBody(entryBlock) @@ -295,7 +295,7 @@ func (c *Compiler) setWasmLocalVariable(index wasm.Index, variable ssa.Variable) } // declareWasmLocals declares the SSA variables for the Wasm locals. -func (c *Compiler) declareWasmLocals(entry ssa.BasicBlock) { +func (c *Compiler) declareWasmLocals() { localCount := wasm.Index(len(c.wasmFunctionTyp.Params)) for i, typ := range c.wasmFunctionLocalTypes { st := WasmTypeToSSAType(typ) @@ -543,11 +543,11 @@ func (c *Compiler) initializeCurrentBlockKnownBounds() { cb := &c.bounds[i][c.pointers[i]] if cb.id != smallestID { same = false - break } else { if cb.bound < minBound { minBound = cb.bound } + c.pointers[i]++ } } @@ -555,14 +555,6 @@ func (c *Compiler) initializeCurrentBlockKnownBounds() { // Absolute address cannot be used in the intersection since the value might be only defined in one of the predecessors. c.recordKnownSafeBound(smallestID, minBound, ssa.ValueInvalid) } - - // Move pointer(s) for the smallest ID forward (if same, move all). - for i := 0; i < preds; i++ { - cb := &c.bounds[i][c.pointers[i]] - if cb.id == smallestID { - c.pointers[i]++ - } - } } } } diff --git a/vendor/github.com/tetratelabs/wazero/internal/engine/wazevo/frontend/lower.go b/vendor/github.com/tetratelabs/wazero/internal/engine/wazevo/frontend/lower.go index ff963e605..e73debbd1 100644 --- a/vendor/github.com/tetratelabs/wazero/internal/engine/wazevo/frontend/lower.go +++ b/vendor/github.com/tetratelabs/wazero/internal/engine/wazevo/frontend/lower.go @@ -1538,8 +1538,7 @@ func (c *Compiler) lowerCurrentOpcode() { builder.SetCurrentBlock(elseBlk) case wasm.OpcodeBrTable: - labels := state.tmpForBrTable - labels = labels[:0] + labels := state.tmpForBrTable[:0] labelCount := c.readI32u() for i := 0; i < int(labelCount); i++ { labels = append(labels, c.readI32u()) @@ -1557,6 +1556,7 @@ func (c *Compiler) lowerCurrentOpcode() { } else { c.lowerBrTable(labels, index) } + state.tmpForBrTable = labels // reuse the temporary slice for next use. state.unreachable = true case wasm.OpcodeNop: @@ -4068,13 +4068,14 @@ func (c *Compiler) lowerBrTable(labels []uint32, index ssa.Value) { numArgs = len(f.blockType.Results) } - targets := make([]ssa.BasicBlock, len(labels)) + varPool := builder.VarLengthPool() + trampolineBlockIDs := varPool.Allocate(len(labels)) // We need trampoline blocks since depending on the target block structure, we might end up inserting moves before jumps, // which cannot be done with br_table. Instead, we can do such per-block moves in the trampoline blocks. // At the linking phase (very end of the backend), we can remove the unnecessary jumps, and therefore no runtime overhead. currentBlk := builder.CurrentBlock() - for i, l := range labels { + for _, l := range labels { // Args are always on the top of the stack. Note that we should not share the args slice // among the jump instructions since the args are modified during passes (e.g. redundant phi elimination). args := c.nPeekDup(numArgs) @@ -4082,17 +4083,17 @@ func (c *Compiler) lowerBrTable(labels []uint32, index ssa.Value) { trampoline := builder.AllocateBasicBlock() builder.SetCurrentBlock(trampoline) c.insertJumpToBlock(args, targetBlk) - targets[i] = trampoline + trampolineBlockIDs = trampolineBlockIDs.Append(builder.VarLengthPool(), ssa.Value(trampoline.ID())) } builder.SetCurrentBlock(currentBlk) // If the target block has no arguments, we can just jump to the target block. brTable := builder.AllocateInstruction() - brTable.AsBrTable(index, targets) + brTable.AsBrTable(index, trampolineBlockIDs) builder.InsertInstruction(brTable) - for _, trampoline := range targets { - builder.Seal(trampoline) + for _, trampolineID := range trampolineBlockIDs.View() { + builder.Seal(builder.BasicBlock(ssa.BasicBlockID(trampolineID))) } } diff --git a/vendor/github.com/tetratelabs/wazero/internal/engine/wazevo/frontend/sort_id.go b/vendor/github.com/tetratelabs/wazero/internal/engine/wazevo/frontend/sort_id.go index 1296706f5..5b055d127 100644 --- a/vendor/github.com/tetratelabs/wazero/internal/engine/wazevo/frontend/sort_id.go +++ b/vendor/github.com/tetratelabs/wazero/internal/engine/wazevo/frontend/sort_id.go @@ -1,5 +1,3 @@ -//go:build go1.21 - package frontend import ( diff --git a/vendor/github.com/tetratelabs/wazero/internal/engine/wazevo/frontend/sort_id_old.go b/vendor/github.com/tetratelabs/wazero/internal/engine/wazevo/frontend/sort_id_old.go deleted file mode 100644 index 2e786a160..000000000 --- a/vendor/github.com/tetratelabs/wazero/internal/engine/wazevo/frontend/sort_id_old.go +++ /dev/null @@ -1,17 +0,0 @@ -//go:build !go1.21 - -// TODO: delete after the floor Go version is 1.21 - -package frontend - -import ( - "sort" - - "github.com/tetratelabs/wazero/internal/engine/wazevo/ssa" -) - -func sortSSAValueIDs(IDs []ssa.ValueID) { - sort.SliceStable(IDs, func(i, j int) bool { - return int(IDs[i]) < int(IDs[j]) - }) -} |