ssa

package
v1.0.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 28, 2023 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package ssa is used to construct SSA function. By nature this is free of Wasm specific thing and ISA.

We use the "block argument" variant of SSA: https://en.wikipedia.org/wiki/Static_single-assignment_form#Block_arguments which is equivalent to the traditional PHI function based one, but more convenient during optimizations. However, in this package's source code comment, we might use PHI whenever it seems necessary in order to be aligned with existing literatures, e.g. SSA level optimization algorithms are often described using PHI nodes.

The rationale doc for the choice of "block argument" by MLIR of LLVM is worth a read: https://mlir.llvm.org/docs/Rationale/Rationale/#block-arguments-vs-phi-nodes

The algorithm to resolve variable definitions used here is based on the paper "Simple and Efficient Construction of Static Single Assignment Form": https://link.springer.com/content/pdf/10.1007/978-3-642-37051-9_6.pdf.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BasicBlock

type BasicBlock interface {
	// ID returns the unique ID of this block.
	ID() BasicBlockID

	// Name returns the unique string ID of this block. e.g. blk0, blk1, ...
	Name() string

	// AddParam adds the parameter to the block whose type specified by `t`.
	AddParam(b Builder, t Type) Value

	// Params returns the number of parameters to this block.
	Params() int

	// Param returns (Variable, Value) which corresponds to the i-th parameter of this block.
	// The returned Value is the definition of the param in this block.
	Param(i int) Value

	// InsertInstruction inserts an instruction that implements Value into the tail of this block.
	InsertInstruction(raw *Instruction)

	// Root returns the root instruction of this block.
	Root() *Instruction

	// Tail returns the tail instruction of this block.
	Tail() *Instruction

	// EntryBlock returns true if this block represents the function entry.
	EntryBlock() bool

	// ReturnBlock returns ture if this block represents the function return.
	ReturnBlock() bool

	// FormatHeader returns the debug string of this block, not including instruction.
	FormatHeader(b Builder) string

	// Valid is true if this block is still valid even after optimizations.
	Valid() bool

	// BeginPredIterator returns the first predecessor of this block.
	BeginPredIterator() BasicBlock

	// NextPredIterator returns the next predecessor of this block.
	NextPredIterator() BasicBlock

	// Preds returns the number of predecessors of this block.
	Preds() int

	// Pred returns the i-th predecessor of this block.
	Pred(i int) BasicBlock

	// Succs returns the number of successors of this block.
	Succs() int

	// Succ returns the i-th successor of this block.
	Succ(i int) BasicBlock

	// LoopHeader returns true if this block is a loop header.
	LoopHeader() bool

	// LoopNestingForestChildren returns the children of this block in the loop nesting forest.
	LoopNestingForestChildren() []BasicBlock
}

BasicBlock represents the Basic Block of an SSA function. Each BasicBlock always ends with branching instructions (e.g. Branch, Return, etc.), and at most two branches are allowed. If there's two branches, these two are placed together at the end of the block. In other words, there's no branching instruction in the middle of the block.

Note: we use the "block argument" variant of SSA, instead of PHI functions. See the package level doc comments.

Note: we use "parameter/param" as a placeholder which represents a variant of PHI, and "argument/arg" as an actual Value passed to that "parameter/param".

type BasicBlockID

type BasicBlockID uint32

BasicBlockID is the unique ID of a basicBlock.

func (BasicBlockID) String

func (bid BasicBlockID) String() string

String implements fmt.Stringer for debugging.

type Builder

type Builder interface {
	// Init must be called to reuse this builder for the next function.
	Init(typ *Signature)

	// Signature returns the Signature of the currently-compiled function.
	Signature() *Signature

	// BlockIDMax returns the maximum value of BasicBlocksID existing in the currently-compiled function.
	BlockIDMax() BasicBlockID

	// AllocateBasicBlock creates a basic block in SSA function.
	AllocateBasicBlock() BasicBlock

	// CurrentBlock returns the currently handled BasicBlock which is set by the latest call to SetCurrentBlock.
	CurrentBlock() BasicBlock

	// EntryBlock returns the entry BasicBlock of the currently-compiled function.
	EntryBlock() BasicBlock

	// SetCurrentBlock sets the instruction insertion target to the BasicBlock `b`.
	SetCurrentBlock(b BasicBlock)

	// DeclareVariable declares a Variable of the given Type.
	DeclareVariable(Type) Variable

	// DefineVariable defines a variable in the `block` with value.
	// The defining instruction will be inserted into the `block`.
	DefineVariable(variable Variable, value Value, block BasicBlock)

	// DefineVariableInCurrentBB is the same as DefineVariable except the definition is
	// inserted into the current BasicBlock. Alias to DefineVariable(x, y, CurrentBlock()).
	DefineVariableInCurrentBB(variable Variable, value Value)

	// AllocateInstruction returns a new Instruction.
	AllocateInstruction() *Instruction

	// InsertInstruction executes BasicBlock.InsertInstruction for the currently handled basic block.
	InsertInstruction(raw *Instruction)

	// MustFindValue searches the latest definition of the given Variable and returns the result.
	MustFindValue(variable Variable) Value

	// FindValueInLinearPath tries to find the latest definition of the given Variable in the linear path to the current BasicBlock.
	// If it cannot find the definition, or it's not sealed yet, it returns ValueInvalid.
	FindValueInLinearPath(variable Variable) Value

	// Seal declares that we've known all the predecessors to this block and were added via AddPred.
	// After calling this, AddPred will be forbidden.
	Seal(blk BasicBlock)

	// AnnotateValue is for debugging purpose.
	AnnotateValue(value Value, annotation string)

	// DeclareSignature appends the *Signature to be referenced by various instructions (e.g. OpcodeCall).
	DeclareSignature(signature *Signature)

	// Signatures returns the slice of declared Signatures.
	Signatures() []*Signature

	// ResolveSignature returns the Signature which corresponds to SignatureID.
	ResolveSignature(id SignatureID) *Signature

	// RunPasses runs various passes on the constructed SSA function.
	RunPasses()

	// Format returns the debugging string of the SSA function.
	Format() string

	// BlockIteratorBegin initializes the state to iterate over all the valid BasicBlock(s) compiled.
	// Combined with BlockIteratorNext, we can use this like:
	//
	// 	for blk := builder.BlockIteratorBegin(); blk != nil; blk = builder.BlockIteratorNext() {
	// 		// ...
	//	}
	//
	// The returned blocks are ordered in the order of AllocateBasicBlock being called.
	BlockIteratorBegin() BasicBlock

	// BlockIteratorNext advances the state for iteration initialized by BlockIteratorBegin.
	// Returns nil if there's no unseen BasicBlock.
	BlockIteratorNext() BasicBlock

	// ValueRefCounts returns the map of ValueID to its reference count.
	// The returned slice must not be modified.
	ValueRefCounts() []int

	// LayoutBlocks layouts the BasicBlock(s) so that backend can easily generate the code.
	// During its process, it splits the critical edges in the function.
	// This must be called after RunPasses. Otherwise, it panics.
	//
	// The resulting order is available via BlockIteratorReversePostOrderBegin and BlockIteratorReversePostOrderNext.
	LayoutBlocks()

	// BlockIteratorReversePostOrderBegin is almost the same as BlockIteratorBegin except it returns the BasicBlock in the reverse post-order.
	// This is available after RunPasses is run.
	BlockIteratorReversePostOrderBegin() BasicBlock

	// BlockIteratorReversePostOrderNext is almost the same as BlockIteratorPostOrderNext except it returns the BasicBlock in the reverse post-order.
	// This is available after RunPasses is run.
	BlockIteratorReversePostOrderNext() BasicBlock

	// ReturnBlock returns the BasicBlock which is used to return from the function.
	ReturnBlock() BasicBlock

	// InsertUndefined inserts an undefined instruction at the current position.
	InsertUndefined()

	// SetCurrentSourceOffset sets the current source offset. The incoming instruction will be annotated with this offset.
	SetCurrentSourceOffset(line SourceOffset)

	// LoopNestingForestRoots returns the roots of the loop nesting forest.
	LoopNestingForestRoots() []BasicBlock

	// LowestCommonAncestor returns the lowest common ancestor in the dominator tree of the given BasicBlock(s).
	LowestCommonAncestor(blk1, blk2 BasicBlock) BasicBlock

	// Idom returns the immediate dominator of the given BasicBlock.
	Idom(blk BasicBlock) BasicBlock
	// contains filtered or unexported methods
}

Builder is used to builds SSA consisting of Basic Blocks per function.

func NewBuilder

func NewBuilder() Builder

NewBuilder returns a new Builder implementation.

type FloatCmpCond

type FloatCmpCond byte
const (
	// FloatCmpCondInvalid represents an invalid condition.
	FloatCmpCondInvalid FloatCmpCond = iota
	// FloatCmpCondEqual represents "==".
	FloatCmpCondEqual
	// FloatCmpCondNotEqual represents "!=".
	FloatCmpCondNotEqual
	// FloatCmpCondLessThan represents "<".
	FloatCmpCondLessThan
	// FloatCmpCondLessThanOrEqual represents "<=".
	FloatCmpCondLessThanOrEqual
	// FloatCmpCondGreaterThan represents ">".
	FloatCmpCondGreaterThan
	// FloatCmpCondGreaterThanOrEqual represents ">=".
	FloatCmpCondGreaterThanOrEqual
)

func (FloatCmpCond) String

func (f FloatCmpCond) String() string

String implements fmt.Stringer.

type FuncRef

type FuncRef uint32

FuncRef is a unique identifier for a function of the frontend, and is used to reference the function in function call.

func (FuncRef) String

func (r FuncRef) String() string

String implements fmt.Stringer.

type Instruction

type Instruction struct {
	// contains filtered or unexported fields
}

Instruction represents an instruction whose opcode is specified by Opcode. Since Go doesn't have union type, we use this flattened type for all instructions, and therefore each field has different meaning depending on Opcode.

func (*Instruction) Arg

func (i *Instruction) Arg() Value

Arg returns the first argument to this instruction.

func (*Instruction) Arg2

func (i *Instruction) Arg2() (Value, Value)

Arg2 returns the first two arguments to this instruction.

func (*Instruction) Arg2WithLane

func (i *Instruction) Arg2WithLane() (Value, Value, VecLane)

Arg2WithLane returns the first two arguments to this instruction, and the lane type.

func (*Instruction) Arg3

func (i *Instruction) Arg3() (Value, Value, Value)

Arg3 returns the first three arguments to this instruction.

func (*Instruction) ArgWithLane

func (i *Instruction) ArgWithLane() (Value, VecLane)

ArgWithLane returns the first argument to this instruction, and the lane type.

func (*Instruction) Args

func (i *Instruction) Args() (v1, v2, v3 Value, vs []Value)

Args returns the arguments to this instruction.

func (*Instruction) AsBand

func (i *Instruction) AsBand(x, amount Value)

AsBand initializes this instruction as an integer bitwise and instruction with OpcodeBand.

func (*Instruction) AsBitcast

func (i *Instruction) AsBitcast(x Value, dstType Type) *Instruction

AsBitcast initializes this instruction as an instruction with OpcodeBitcast.

func (*Instruction) AsBor

func (i *Instruction) AsBor(x, amount Value)

AsBor initializes this instruction as an integer bitwise or instruction with OpcodeBor.

func (*Instruction) AsBrTable

func (i *Instruction) AsBrTable(index Value, targets []BasicBlock)

AsBrTable initializes this instruction as a branch-table instruction with OpcodeBrTable.

func (*Instruction) AsBrnz

func (i *Instruction) AsBrnz(v Value, args []Value, target BasicBlock) *Instruction

AsBrnz initializes this instruction as a branch-if-not-zero instruction with OpcodeBrnz.

func (*Instruction) AsBrz

func (i *Instruction) AsBrz(v Value, args []Value, target BasicBlock)

AsBrz initializes this instruction as a branch-if-zero instruction with OpcodeBrz.

func (*Instruction) AsBxor

func (i *Instruction) AsBxor(x, amount Value)

AsBxor initializes this instruction as an integer bitwise xor instruction with OpcodeBxor.

func (*Instruction) AsCall

func (i *Instruction) AsCall(ref FuncRef, sig *Signature, args []Value)

AsCall initializes this instruction as a call instruction with OpcodeCall.

func (*Instruction) AsCallIndirect

func (i *Instruction) AsCallIndirect(funcPtr Value, sig *Signature, args []Value) *Instruction

AsCallIndirect initializes this instruction as a call-indirect instruction with OpcodeCallIndirect.

func (*Instruction) AsCeil

func (i *Instruction) AsCeil(x Value) *Instruction

AsCeil initializes this instruction as an instruction with OpcodeCeil.

func (*Instruction) AsClz

func (i *Instruction) AsClz(x Value)

AsClz initializes this instruction as a Count Leading Zeroes instruction with OpcodeClz.

func (*Instruction) AsCtz

func (i *Instruction) AsCtz(x Value)

AsCtz initializes this instruction as a Count Trailing Zeroes instruction with OpcodeCtz.

func (*Instruction) AsExitIfTrueWithCode

func (i *Instruction) AsExitIfTrueWithCode(ctx, c Value, code wazevoapi.ExitCode) *Instruction

AsExitIfTrueWithCode initializes this instruction as a trap instruction with OpcodeExitIfTrueWithCode.

func (*Instruction) AsExitWithCode

func (i *Instruction) AsExitWithCode(ctx Value, code wazevoapi.ExitCode)

AsExitWithCode initializes this instruction as a trap instruction with OpcodeExitWithCode.

func (*Instruction) AsExtLoad

func (i *Instruction) AsExtLoad(op Opcode, ptr Value, offset uint32, dst64bit bool) *Instruction

AsExtLoad initializes this instruction as a store instruction with OpcodeLoad.

func (*Instruction) AsExtractlane

func (i *Instruction) AsExtractlane(x Value, index byte, lane VecLane, signed bool) *Instruction

AsExtractlane initializes this instruction as an extract lane instruction with OpcodeExtractlane on vector.

func (*Instruction) AsF32const

func (i *Instruction) AsF32const(f float32) *Instruction

AsF32const initializes this instruction as a 32-bit floating-point constant instruction with OpcodeF32const.

func (*Instruction) AsF64const

func (i *Instruction) AsF64const(f float64) *Instruction

AsF64const initializes this instruction as a 64-bit floating-point constant instruction with OpcodeF64const.

func (*Instruction) AsFabs

func (i *Instruction) AsFabs(x Value) *Instruction

AsFabs initializes this instruction as an instruction with OpcodeFabs.

func (*Instruction) AsFadd

func (i *Instruction) AsFadd(x, y Value)

AsFadd initializes this instruction as a floating-point addition instruction with OpcodeFadd.

func (*Instruction) AsFallthroughJump

func (i *Instruction) AsFallthroughJump()

AsFallthroughJump marks this instruction as a fallthrough jump.

func (*Instruction) AsFcmp

func (i *Instruction) AsFcmp(x, y Value, c FloatCmpCond)

AsFcmp initializes this instruction as an integer comparison instruction with OpcodeFcmp.

func (*Instruction) AsFcopysign

func (i *Instruction) AsFcopysign(x, y Value) *Instruction

AsFcopysign initializes this instruction as an instruction with OpcodeFcopysign.

func (*Instruction) AsFcvtFromInt

func (i *Instruction) AsFcvtFromInt(x Value, signed bool, dst64bit bool) *Instruction

AsFcvtFromInt initializes this instruction as an instruction with either OpcodeFcvtFromUint or OpcodeFcvtFromSint

func (*Instruction) AsFcvtToInt

func (i *Instruction) AsFcvtToInt(x, ctx Value, signed bool, dst64bit bool, sat bool) *Instruction

AsFcvtToInt initializes this instruction as an instruction with either OpcodeFcvtToUint or OpcodeFcvtToSint

func (*Instruction) AsFdemote

func (i *Instruction) AsFdemote(x Value)

AsFdemote initializes this instruction as an instruction with OpcodeFdemote.

func (*Instruction) AsFdiv

func (i *Instruction) AsFdiv(x, y Value)

AsFdiv initializes this instruction as a floating-point division instruction with OpcodeFdiv.

func (*Instruction) AsFloor

func (i *Instruction) AsFloor(x Value) *Instruction

AsFloor initializes this instruction as an instruction with OpcodeFloor.

func (*Instruction) AsFmax

func (i *Instruction) AsFmax(x, y Value)

AsFmax initializes this instruction to take the maximum of two floating-points with OpcodeFmax.

func (*Instruction) AsFmin

func (i *Instruction) AsFmin(x, y Value)

AsFmin initializes this instruction to take the minimum of two floating-points with OpcodeFmin.

func (*Instruction) AsFmul

func (i *Instruction) AsFmul(x, y Value)

AsFmul initializes this instruction as a floating-point multiplication instruction with OpcodeFmul.

func (*Instruction) AsFneg

func (i *Instruction) AsFneg(x Value) *Instruction

AsFneg initializes this instruction as an instruction with OpcodeFneg.

func (*Instruction) AsFpromote

func (i *Instruction) AsFpromote(x Value)

AsFpromote initializes this instruction as an instruction with OpcodeFpromote.

func (*Instruction) AsFsub

func (i *Instruction) AsFsub(x, y Value)

AsFsub initializes this instruction as a floating-point subtraction instruction with OpcodeFsub.

func (*Instruction) AsFvdemote

func (i *Instruction) AsFvdemote(x Value, lane VecLane) *Instruction

AsFvdemote initializes this instruction as an instruction with OpcodeFvdemote

func (*Instruction) AsFvpromoteLow

func (i *Instruction) AsFvpromoteLow(x Value, lane VecLane) *Instruction

AsFvpromoteLow initializes this instruction as an instruction with OpcodeFvpromoteLow

func (*Instruction) AsIadd

func (i *Instruction) AsIadd(x, y Value) *Instruction

AsIadd initializes this instruction as an integer addition instruction with OpcodeIadd.

func (*Instruction) AsIaddPairwise

func (i *Instruction) AsIaddPairwise(x, y Value, lane VecLane) *Instruction

AsIaddPairwise initializes this instruction as a lane-wise integer extended pairwise addition instruction with OpcodeIaddPairwise on a vector.

func (*Instruction) AsIcmp

func (i *Instruction) AsIcmp(x, y Value, c IntegerCmpCond) *Instruction

AsIcmp initializes this instruction as an integer comparison instruction with OpcodeIcmp.

func (*Instruction) AsIconst32

func (i *Instruction) AsIconst32(v uint32) *Instruction

AsIconst32 initializes this instruction as a 32-bit integer constant instruction with OpcodeIconst.

func (*Instruction) AsIconst64

func (i *Instruction) AsIconst64(v uint64) *Instruction

AsIconst64 initializes this instruction as a 64-bit integer constant instruction with OpcodeIconst.

func (*Instruction) AsImul

func (i *Instruction) AsImul(x, y Value) *Instruction

AsImul initializes this instruction as an integer addition instruction with OpcodeImul.

func (*Instruction) AsInsertlane

func (i *Instruction) AsInsertlane(x, y Value, index byte, lane VecLane) *Instruction

AsInsertlane initializes this instruction as an insert lane instruction with OpcodeInsertlane on vector.

func (*Instruction) AsIreduce

func (i *Instruction) AsIreduce(v Value, dstType Type) *Instruction

AsIreduce initializes this instruction as a reduction instruction with OpcodeIreduce.

func (*Instruction) AsIshl

func (i *Instruction) AsIshl(x, amount Value) *Instruction

AsIshl initializes this instruction as an integer shift left instruction with OpcodeIshl.

func (*Instruction) AsIsub

func (i *Instruction) AsIsub(x, y Value) *Instruction

AsIsub initializes this instruction as an integer subtraction instruction with OpcodeIsub.

func (*Instruction) AsJump

func (i *Instruction) AsJump(vs []Value, target BasicBlock)

AsJump initializes this instruction as a jump instruction with OpcodeJump.

func (*Instruction) AsLoad

func (i *Instruction) AsLoad(ptr Value, offset uint32, typ Type) *Instruction

AsLoad initializes this instruction as a store instruction with OpcodeLoad.

func (*Instruction) AsLoadSplat

func (i *Instruction) AsLoadSplat(ptr Value, offset uint32, lane VecLane) *Instruction

AsLoadSplat initializes this instruction as a store instruction with OpcodeLoadSplat.

func (*Instruction) AsNarrow

func (i *Instruction) AsNarrow(x, y Value, lane VecLane, signed bool) *Instruction

AsNarrow initializes this instruction as an instruction with either OpcodeSnarrow or OpcodeUnarrow

func (*Instruction) AsNearest

func (i *Instruction) AsNearest(x Value) *Instruction

AsNearest initializes this instruction as an instruction with OpcodeNearest.

func (*Instruction) AsPopcnt

func (i *Instruction) AsPopcnt(x Value)

AsPopcnt initializes this instruction as a Population Count instruction with OpcodePopcnt.

func (*Instruction) AsReturn

func (i *Instruction) AsReturn(vs []Value) *Instruction

AsReturn initializes this instruction as a return instruction with OpcodeReturn.

func (*Instruction) AsRotl

func (i *Instruction) AsRotl(x, amount Value)

AsRotl initializes this instruction as a word rotate left instruction with OpcodeRotl.

func (*Instruction) AsRotr

func (i *Instruction) AsRotr(x, amount Value)

AsRotr initializes this instruction as a word rotate right instruction with OpcodeRotr.

func (*Instruction) AsSDiv

func (i *Instruction) AsSDiv(x, y, ctx Value) *Instruction

AsSDiv initializes this instruction as an integer bitwise and instruction with OpcodeSdiv.

func (*Instruction) AsSExtend

func (i *Instruction) AsSExtend(v Value, from, to byte) *Instruction

AsSExtend initializes this instruction as a sign extension instruction with OpcodeSExtend.

func (*Instruction) AsSRem

func (i *Instruction) AsSRem(x, y, ctx Value) *Instruction

AsSRem initializes this instruction as an integer bitwise and instruction with OpcodeSrem.

func (*Instruction) AsSelect

func (i *Instruction) AsSelect(c, x, y Value) *Instruction

AsSelect initializes this instruction as an unsigned extension instruction with OpcodeSelect.

func (*Instruction) AsShuffle

func (i *Instruction) AsShuffle(x, y Value, lane []byte) *Instruction

AsShuffle initializes this instruction as a shuffle instruction with OpcodeShuffle on vector.

func (*Instruction) AsSplat

func (i *Instruction) AsSplat(x Value, lane VecLane) *Instruction

AsSplat initializes this instruction as an insert lane instruction with OpcodeSplat on vector.

func (*Instruction) AsSqmulRoundSat

func (i *Instruction) AsSqmulRoundSat(x, y Value, lane VecLane) *Instruction

AsSqmulRoundSat initializes this instruction as a lane-wise saturating rounding multiplication in Q15 format with OpcodeSqmulRoundSat on a vector.

func (*Instruction) AsSqrt

func (i *Instruction) AsSqrt(x Value) *Instruction

AsSqrt initializes this instruction as an instruction with OpcodeSqrt.

func (*Instruction) AsSshr

func (i *Instruction) AsSshr(x, amount Value) *Instruction

AsSshr initializes this instruction as an integer signed shift right (arithmetic shift right) instruction with OpcodeSshr.

func (*Instruction) AsStore

func (i *Instruction) AsStore(storeOp Opcode, value, ptr Value, offset uint32) *Instruction

AsStore initializes this instruction as a store instruction with OpcodeStore.

func (*Instruction) AsSwizzle

func (i *Instruction) AsSwizzle(x, y Value, lane VecLane) *Instruction

AsSwizzle initializes this instruction as an insert lane instruction with OpcodeSwizzle on vector.

func (*Instruction) AsTrunc

func (i *Instruction) AsTrunc(x Value) *Instruction

AsTrunc initializes this instruction as an instruction with OpcodeTrunc.

func (*Instruction) AsUDiv

func (i *Instruction) AsUDiv(x, y, ctx Value) *Instruction

AsUDiv initializes this instruction as an integer bitwise and instruction with OpcodeUdiv.

func (*Instruction) AsUExtend

func (i *Instruction) AsUExtend(v Value, from, to byte) *Instruction

AsUExtend initializes this instruction as an unsigned extension instruction with OpcodeUExtend.

func (*Instruction) AsURem

func (i *Instruction) AsURem(x, y, ctx Value) *Instruction

AsURem initializes this instruction as an integer bitwise and instruction with OpcodeUrem.

func (*Instruction) AsUshr

func (i *Instruction) AsUshr(x, amount Value) *Instruction

AsUshr initializes this instruction as an integer unsigned shift right (logical shift right) instruction with OpcodeUshr.

func (*Instruction) AsVAvgRound

func (i *Instruction) AsVAvgRound(x, y Value, lane VecLane) *Instruction

AsVAvgRound initializes this instruction as an unsigned integer avg instruction, truncating to zero with OpcodeVAvgRound on a vector.

func (*Instruction) AsVCeil

func (i *Instruction) AsVCeil(x Value, lane VecLane) *Instruction

AsVCeil initializes this instruction as an instruction with OpcodeCeil.

func (*Instruction) AsVFabs

func (i *Instruction) AsVFabs(x Value, lane VecLane) *Instruction

AsVFabs initializes this instruction as a float abs instruction with OpcodeVFabs on a vector.

func (*Instruction) AsVFadd

func (i *Instruction) AsVFadd(x, y Value, lane VecLane) *Instruction

AsVFadd initializes this instruction as a floating point add instruction with OpcodeVFadd on a vector.

func (*Instruction) AsVFcmp

func (i *Instruction) AsVFcmp(x, y Value, c FloatCmpCond, lane VecLane) *Instruction

AsVFcmp initializes this instruction as a float comparison instruction with OpcodeVFcmp on Vector.

func (*Instruction) AsVFcvtFromInt

func (i *Instruction) AsVFcvtFromInt(x Value, lane VecLane, signed bool) *Instruction

AsVFcvtFromInt initializes this instruction as an instruction with either OpcodeVFcvtToSintSat or OpcodeVFcvtToUintSat

func (*Instruction) AsVFcvtToIntSat

func (i *Instruction) AsVFcvtToIntSat(x Value, lane VecLane, signed bool) *Instruction

AsVFcvtToIntSat initializes this instruction as an instruction with either OpcodeVFcvtToSintSat or OpcodeVFcvtToUintSat

func (*Instruction) AsVFdiv

func (i *Instruction) AsVFdiv(x, y Value, lane VecLane) *Instruction

AsVFdiv initializes this instruction as a floating point division instruction with OpcodeVFdiv on a vector.

func (*Instruction) AsVFloor

func (i *Instruction) AsVFloor(x Value, lane VecLane) *Instruction

AsVFloor initializes this instruction as an instruction with OpcodeFloor.

func (*Instruction) AsVFmax

func (i *Instruction) AsVFmax(x, y Value, lane VecLane) *Instruction

AsVFmax initializes this instruction as a float max instruction with OpcodeVFmax on a vector.

func (*Instruction) AsVFmin

func (i *Instruction) AsVFmin(x, y Value, lane VecLane) *Instruction

AsVFmin initializes this instruction as a float min instruction with OpcodeVFmin on a vector.

func (*Instruction) AsVFmul

func (i *Instruction) AsVFmul(x, y Value, lane VecLane) *Instruction

AsVFmul initializes this instruction as a floating point multiplication instruction with OpcodeVFmul on a vector.

func (*Instruction) AsVFneg

func (i *Instruction) AsVFneg(x Value, lane VecLane) *Instruction

AsVFneg initializes this instruction as a float neg instruction with OpcodeVFneg on a vector.

func (*Instruction) AsVFsub

func (i *Instruction) AsVFsub(x, y Value, lane VecLane) *Instruction

AsVFsub initializes this instruction as a floating point subtraction instruction with OpcodeVFsub on a vector.

func (*Instruction) AsVIabs

func (i *Instruction) AsVIabs(x Value, lane VecLane) *Instruction

AsVIabs initializes this instruction as a vector absolute value with OpcodeVIabs.

func (*Instruction) AsVIadd

func (i *Instruction) AsVIadd(x, y Value, lane VecLane) *Instruction

AsVIadd initializes this instruction as an integer addition instruction with OpcodeVIadd on a vector.

func (*Instruction) AsVIcmp

func (i *Instruction) AsVIcmp(x, y Value, c IntegerCmpCond, lane VecLane) *Instruction

AsVIcmp initializes this instruction as an integer vector comparison instruction with OpcodeVIcmp.

func (*Instruction) AsVImax

func (i *Instruction) AsVImax(x, y Value, lane VecLane) *Instruction

AsVImax initializes this instruction as a signed integer max instruction with OpcodeVImax on a vector.

func (*Instruction) AsVImin

func (i *Instruction) AsVImin(x, y Value, lane VecLane) *Instruction

AsVImin initializes this instruction as a signed integer min instruction with OpcodeVImin on a vector.

func (*Instruction) AsVImul

func (i *Instruction) AsVImul(x, y Value, lane VecLane) *Instruction

AsVImul initializes this instruction as an integer multiplication with OpcodeVImul on a vector.

func (*Instruction) AsVIneg

func (i *Instruction) AsVIneg(x Value, lane VecLane) *Instruction

AsVIneg initializes this instruction as a vector negation with OpcodeVIneg.

func (*Instruction) AsVIpopcnt

func (i *Instruction) AsVIpopcnt(x Value, lane VecLane) *Instruction

AsVIpopcnt initializes this instruction as a Population Count instruction with OpcodeVIpopcnt on a vector.

func (*Instruction) AsVIshl

func (i *Instruction) AsVIshl(x, amount Value, lane VecLane) *Instruction

AsVIshl initializes this instruction as an integer shift left instruction with OpcodeVIshl on vector.

func (*Instruction) AsVIsub

func (i *Instruction) AsVIsub(x, y Value, lane VecLane) *Instruction

AsVIsub initializes this instruction as an integer subtraction instruction with OpcodeVIsub on a vector.

func (*Instruction) AsVMaxPseudo

func (i *Instruction) AsVMaxPseudo(x, y Value, lane VecLane) *Instruction

AsVMaxPseudo initializes this instruction as an instruction with OpcodeVMaxPseudo.

func (*Instruction) AsVMinPseudo

func (i *Instruction) AsVMinPseudo(x, y Value, lane VecLane) *Instruction

AsVMinPseudo initializes this instruction as an instruction with OpcodeVMinPseudo.

func (*Instruction) AsVNearest

func (i *Instruction) AsVNearest(x Value, lane VecLane) *Instruction

AsVNearest initializes this instruction as an instruction with OpcodeNearest.

func (*Instruction) AsVSaddSat

func (i *Instruction) AsVSaddSat(x, y Value, lane VecLane) *Instruction

AsVSaddSat initializes this instruction as a vector addition with saturation instruction with OpcodeVSaddSat on a vector.

func (*Instruction) AsVSqrt

func (i *Instruction) AsVSqrt(x Value, lane VecLane) *Instruction

AsVSqrt initializes this instruction as a sqrt instruction with OpcodeVSqrt on a vector.

func (*Instruction) AsVSshr

func (i *Instruction) AsVSshr(x, amount Value, lane VecLane) *Instruction

AsVSshr initializes this instruction as an integer signed shift right (arithmetic shift right) instruction with OpcodeVSshr on vector.

func (*Instruction) AsVSsubSat

func (i *Instruction) AsVSsubSat(x, y Value, lane VecLane) *Instruction

AsVSsubSat initializes this instruction as a vector addition with saturation instruction with OpcodeVSsubSat on a vector.

func (*Instruction) AsVTrunc

func (i *Instruction) AsVTrunc(x Value, lane VecLane) *Instruction

AsVTrunc initializes this instruction as an instruction with OpcodeTrunc.

func (*Instruction) AsVUaddSat

func (i *Instruction) AsVUaddSat(x, y Value, lane VecLane) *Instruction

AsVUaddSat initializes this instruction as a vector addition with saturation instruction with OpcodeVUaddSat on a vector.

func (*Instruction) AsVUmax

func (i *Instruction) AsVUmax(x, y Value, lane VecLane) *Instruction

AsVUmax initializes this instruction as an unsigned integer max instruction with OpcodeVUmax on a vector.

func (*Instruction) AsVUmin

func (i *Instruction) AsVUmin(x, y Value, lane VecLane) *Instruction

AsVUmin initializes this instruction as an unsigned integer min instruction with OpcodeVUmin on a vector.

func (*Instruction) AsVUshr

func (i *Instruction) AsVUshr(x, amount Value, lane VecLane) *Instruction

AsVUshr initializes this instruction as an integer unsigned shift right (logical shift right) instruction with OpcodeVUshr on vector.

func (*Instruction) AsVUsubSat

func (i *Instruction) AsVUsubSat(x, y Value, lane VecLane) *Instruction

AsVUsubSat initializes this instruction as a vector addition with saturation instruction with OpcodeVUsubSat on a vector.

func (*Instruction) AsVZeroExtLoad

func (i *Instruction) AsVZeroExtLoad(ptr Value, offset uint32, scalarType Type) *Instruction

AsVZeroExtLoad initializes this instruction as a store instruction with OpcodeVExtLoad.

func (*Instruction) AsVallTrue

func (i *Instruction) AsVallTrue(x Value, lane VecLane) *Instruction

AsVallTrue initializes this instruction as an allTrue vector instruction with OpcodeVallTrue.

func (*Instruction) AsVanyTrue

func (i *Instruction) AsVanyTrue(x Value) *Instruction

AsVanyTrue initializes this instruction as an anyTrue vector instruction with OpcodeVanyTrue.

func (*Instruction) AsVband

func (i *Instruction) AsVband(x, y Value) *Instruction

AsVband initializes this instruction as an and vector instruction with OpcodeVband.

func (*Instruction) AsVbandnot

func (i *Instruction) AsVbandnot(x, y Value) *Instruction

AsVbandnot initializes this instruction as an and-not vector instruction with OpcodeVbandnot.

func (*Instruction) AsVbitselect

func (i *Instruction) AsVbitselect(c, x, y Value) *Instruction

AsVbitselect initializes this instruction as a bit select vector instruction with OpcodeVbitselect.

func (*Instruction) AsVbnot

func (i *Instruction) AsVbnot(v Value) *Instruction

AsVbnot initializes this instruction as a vector negation instruction with OpcodeVbnot.

func (*Instruction) AsVbor

func (i *Instruction) AsVbor(x, y Value) *Instruction

AsVbor initializes this instruction as an or vector instruction with OpcodeVbor.

func (*Instruction) AsVbxor

func (i *Instruction) AsVbxor(x, y Value) *Instruction

AsVbxor initializes this instruction as a xor vector instruction with OpcodeVbxor.

func (*Instruction) AsVconst

func (i *Instruction) AsVconst(lo, hi uint64) *Instruction

AsVconst initializes this instruction as a vector constant instruction with OpcodeVconst.

func (*Instruction) AsVhighBits

func (i *Instruction) AsVhighBits(x Value, lane VecLane) *Instruction

AsVhighBits initializes this instruction as a highBits vector instruction with OpcodeVhighBits.

func (*Instruction) AsWiden

func (i *Instruction) AsWiden(v Value, lane VecLane, signed, low bool) *Instruction

AsWiden initializes this instruction as a signed or unsigned widen instruction on low half or high half of the given vector with OpcodeSwidenLow, OpcodeUwidenLow, OpcodeSwidenHigh, OpcodeUwidenHigh.

func (*Instruction) BitcastData

func (i *Instruction) BitcastData() (x Value, dstType Type)

BitcastData returns the operands for a bitcast instruction.

func (*Instruction) BrTableData

func (i *Instruction) BrTableData() (index Value, targets []BasicBlock)

BrTableData returns the branch table data for this instruction necessary for backends.

func (*Instruction) BranchData

func (i *Instruction) BranchData() (condVal Value, blockArgs []Value, target BasicBlock)

BranchData returns the branch data for this instruction necessary for backends.

func (*Instruction) CallData

func (i *Instruction) CallData() (ref FuncRef, sigID SignatureID, args []Value)

CallData returns the call data for this instruction necessary for backends.

func (*Instruction) CallIndirectData

func (i *Instruction) CallIndirectData() (funcPtr Value, sigID SignatureID, args []Value)

CallIndirectData returns the call indirect data for this instruction necessary for backends.

func (*Instruction) Constant

func (i *Instruction) Constant() bool

Constant returns true if this instruction is a constant instruction.

func (*Instruction) ConstantVal

func (i *Instruction) ConstantVal() (ret uint64)

ConstantVal returns the constant value of this instruction. How to interpret the return value depends on the opcode.

func (*Instruction) ExitIfTrueWithCodeData

func (i *Instruction) ExitIfTrueWithCodeData() (ctx, c Value, code wazevoapi.ExitCode)

ExitIfTrueWithCodeData returns the context and exit code of OpcodeExitWithCode.

func (*Instruction) ExitWithCodeData

func (i *Instruction) ExitWithCodeData() (ctx Value, code wazevoapi.ExitCode)

ExitWithCodeData returns the context and exit code of OpcodeExitWithCode.

func (*Instruction) ExtendData

func (i *Instruction) ExtendData() (from, to byte, signed bool)

func (*Instruction) ExtendFromToBits

func (i *Instruction) ExtendFromToBits() (from, to byte)

ExtendFromToBits returns the from and to bit size for the extension instruction.

func (*Instruction) ExtractlaneData

func (i *Instruction) ExtractlaneData() (x Value, index byte, signed bool, l VecLane)

ExtractlaneData returns the operands and sign flag of Extractlane on vector.

func (*Instruction) FcmpData

func (i *Instruction) FcmpData() (x, y Value, c FloatCmpCond)

FcmpData returns the operands and comparison condition of this floating-point comparison instruction.

func (*Instruction) Format

func (i *Instruction) Format(b Builder) string

Format returns a string representation of this instruction with the given builder. For debugging purposes only.

func (*Instruction) GroupID

func (i *Instruction) GroupID() InstructionGroupID

GroupID returns the InstructionGroupID of this instruction.

func (*Instruction) IcmpData

func (i *Instruction) IcmpData() (x, y Value, c IntegerCmpCond)

IcmpData returns the operands and comparison condition of this integer comparison instruction.

func (*Instruction) Insert

func (i *Instruction) Insert(b Builder) *Instruction

func (*Instruction) InsertlaneData

func (i *Instruction) InsertlaneData() (x, y Value, index byte, l VecLane)

InsertlaneData returns the operands and sign flag of Insertlane on vector.

func (*Instruction) InvertBrx

func (i *Instruction) InvertBrx()

InvertBrx inverts either OpcodeBrz or OpcodeBrnz to the other.

func (*Instruction) IsBranching

func (i *Instruction) IsBranching() bool

IsBranching returns true if this instruction is a branching instruction.

func (*Instruction) IsFallthroughJump

func (i *Instruction) IsFallthroughJump() bool

IsFallthroughJump returns true if this instruction is a fallthrough jump.

func (*Instruction) LoadData

func (i *Instruction) LoadData() (ptr Value, offset uint32, typ Type)

LoadData returns the operands for a load instruction.

func (*Instruction) LoadSplatData

func (i *Instruction) LoadSplatData() (ptr Value, offset uint32, lane VecLane)

LoadSplatData returns the operands for a load splat instruction.

func (*Instruction) Lowered

func (i *Instruction) Lowered() bool

Lowered returns true if this instruction is already lowered.

func (*Instruction) MarkLowered

func (i *Instruction) MarkLowered()

MarkLowered marks this instruction as already lowered.

func (*Instruction) Next

func (i *Instruction) Next() *Instruction

Next returns the next instruction laid out next to itself.

func (*Instruction) Opcode

func (i *Instruction) Opcode() Opcode

Opcode returns the opcode of this instruction.

func (*Instruction) Prev

func (i *Instruction) Prev() *Instruction

Prev returns the previous instruction laid out prior to itself.

func (*Instruction) Return

func (i *Instruction) Return() (first Value)

Return returns a Value(s) produced by this instruction if any. If there's multiple return values, only the first one is returned.

func (*Instruction) ReturnVals

func (i *Instruction) ReturnVals() []Value

ReturnVals returns the return values of OpcodeReturn.

func (*Instruction) Returns

func (i *Instruction) Returns() (first Value, rest []Value)

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 (*Instruction) SelectData

func (i *Instruction) SelectData() (c, x, y Value)

SelectData returns the select data for this instruction necessary for backends.

func (*Instruction) ShuffleData

func (i *Instruction) ShuffleData() (v Value, v2 Value, lo uint64, hi uint64)

ShuffleData returns the first two arguments to this instruction and 2 uint64s `lo`, `hi`.

Note: Each uint64 encodes a sequence of 8 bytes where each byte encodes a VecLane, so that the 128bit integer `hi<<64|lo` packs a slice `[16]VecLane`, where `lane[0]` is the least significant byte, and `lane[n]` is shifted to offset `n*8`.

func (*Instruction) SourceOffset

func (i *Instruction) SourceOffset() SourceOffset

SourceOffset returns the source offset of this instruction.

func (*Instruction) StoreData

func (i *Instruction) StoreData() (value, ptr Value, offset uint32, storeSizeInBits byte)

StoreData returns the operands for a store instruction.

func (*Instruction) VFcmpData

func (i *Instruction) VFcmpData() (x, y Value, c FloatCmpCond, l VecLane)

VFcmpData returns the operands and comparison condition of this float comparison instruction on vector.

func (*Instruction) VIcmpData

func (i *Instruction) VIcmpData() (x, y Value, c IntegerCmpCond, l VecLane)

VIcmpData returns the operands and comparison condition of this integer comparison instruction on vector.

func (*Instruction) VZeroExtLoadData

func (i *Instruction) VZeroExtLoadData() (ptr Value, offset uint32, typ Type)

VZeroExtLoadData returns the operands for a load instruction. The returned `typ` is the scalar type of the load target.

func (*Instruction) VconstData

func (i *Instruction) VconstData() (lo, hi uint64)

VconstData returns the operands of this vector constant instruction.

type InstructionGroupID

type InstructionGroupID uint32

InstructionGroupID is assigned to each instruction and represents a group of instructions where each instruction is interchangeable with others except for the last instruction in the group which has side effects. In short, InstructionGroupID is determined by the side effects of instructions. That means, if there's an instruction with side effect between two instructions, then these two instructions will have different instructionGroupID. Note that each block always ends with branching, which is with side effects, therefore, instructions in different blocks always have different InstructionGroupID(s).

The notable application of this is used in lowering SSA-level instruction to a ISA specific instruction, where we eagerly try to merge multiple instructions into single operation etc. Such merging cannot be done if these instruction have different InstructionGroupID since it will change the semantics of a program.

See passDeadCodeElimination.

type IntegerCmpCond

type IntegerCmpCond byte

IntegerCmpCond represents a condition for integer comparison.

const (
	// IntegerCmpCondInvalid represents an invalid condition.
	IntegerCmpCondInvalid IntegerCmpCond = iota
	// IntegerCmpCondEqual represents "==".
	IntegerCmpCondEqual
	// IntegerCmpCondNotEqual represents "!=".
	IntegerCmpCondNotEqual
	// IntegerCmpCondSignedLessThan represents Signed "<".
	IntegerCmpCondSignedLessThan
	// IntegerCmpCondSignedGreaterThanOrEqual represents Signed ">=".
	IntegerCmpCondSignedGreaterThanOrEqual
	// IntegerCmpCondSignedGreaterThan represents Signed ">".
	IntegerCmpCondSignedGreaterThan
	// IntegerCmpCondSignedLessThanOrEqual represents Signed "<=".
	IntegerCmpCondSignedLessThanOrEqual
	// IntegerCmpCondUnsignedLessThan represents Unsigned "<".
	IntegerCmpCondUnsignedLessThan
	// IntegerCmpCondUnsignedGreaterThanOrEqual represents Unsigned ">=".
	IntegerCmpCondUnsignedGreaterThanOrEqual
	// IntegerCmpCondUnsignedGreaterThan represents Unsigned ">".
	IntegerCmpCondUnsignedGreaterThan
	// IntegerCmpCondUnsignedLessThanOrEqual represents Unsigned "<=".
	IntegerCmpCondUnsignedLessThanOrEqual
)

func (IntegerCmpCond) Signed

func (i IntegerCmpCond) Signed() bool

Signed returns true if the condition is signed integer comparison.

func (IntegerCmpCond) String

func (i IntegerCmpCond) String() string

String implements fmt.Stringer.

type Opcode

type Opcode uint32

Opcode represents a SSA instruction.

const (
	OpcodeInvalid Opcode = iota

	// OpcodeUndefined is a placeholder for undefined opcode. This can be used for debugging to intentionally
	// cause a crash at certain point.
	OpcodeUndefined

	// OpcodeJump takes the list of args to the `block` and unconditionally jumps to it.
	OpcodeJump

	// OpcodeBrz branches into `blk` with `args`  if the value `c` equals zero: `Brz c, blk, args`.
	OpcodeBrz

	// OpcodeBrnz branches into `blk` with `args`  if the value `c` is not zero: `Brnz c, blk, args`.
	OpcodeBrnz

	// OpcodeBrTable takes the index value `index`, and branches into `labelX`. If the `index` is out of range,
	// it branches into the last labelN: `BrTable index, [label1, label2, ... labelN]`.
	OpcodeBrTable

	// OpcodeExitWithCode exit the execution immediately.
	OpcodeExitWithCode

	// OpcodeExitIfTrueWithCode exits the execution immediately if the value `c` is not zero.
	OpcodeExitIfTrueWithCode

	// OpcodeReturn returns from the function: `return rvalues`.
	OpcodeReturn

	// OpcodeCall calls a function specified by the symbol FN with arguments `args`: `returnvals = Call FN, args...`
	// This is a "near" call, which means the call target is known at compile time, and the target is relatively close
	// to this function. If the target cannot be reached by near call, the backend fails to compile.
	OpcodeCall

	// OpcodeCallIndirect calls a function specified by `callee` which is a function address: `returnvals = call_indirect SIG, callee, args`.
	// Note that this is different from call_indirect in Wasm, which also does type checking, etc.
	OpcodeCallIndirect

	// OpcodeSplat performs a vector splat operation: `v = Splat.lane x`.
	OpcodeSplat

	// OpcodeSwizzle performs a vector swizzle operation: `v = Swizzle.lane x, y`.
	OpcodeSwizzle

	// OpcodeInsertlane ...
	// `v = insertlane x, y, Idx`. (TernaryImm8)
	OpcodeInsertlane

	// OpcodeExtractlane ...
	// `v = extractlane x, Idx`. (BinaryImm8)
	OpcodeExtractlane

	// OpcodeLoad loads a Type value from the [base + offset] address: `v = Load base, offset`.
	OpcodeLoad

	// OpcodeStore stores a Type value to the [base + offset] address: `Store v, base, offset`.
	OpcodeStore

	// OpcodeUload8 loads the 8-bit value from the [base + offset] address, zero-extended to 64 bits: `v = Uload8 base, offset`.
	OpcodeUload8

	// OpcodeSload8 loads the 8-bit value from the [base + offset] address, sign-extended to 64 bits: `v = Sload8 base, offset`.
	OpcodeSload8

	// OpcodeIstore8 stores the 8-bit value to the [base + offset] address, sign-extended to 64 bits: `Istore8 v, base, offset`.
	OpcodeIstore8

	// OpcodeUload16 loads the 16-bit value from the [base + offset] address, zero-extended to 64 bits: `v = Uload16 base, offset`.
	OpcodeUload16

	// OpcodeSload16 loads the 16-bit value from the [base + offset] address, sign-extended to 64 bits: `v = Sload16 base, offset`.
	OpcodeSload16

	// OpcodeIstore16 stores the 16-bit value to the [base + offset] address, zero-extended to 64 bits: `Istore16 v, base, offset`.
	OpcodeIstore16

	// OpcodeUload32 loads the 32-bit value from the [base + offset] address, zero-extended to 64 bits: `v = Uload32 base, offset`.
	OpcodeUload32

	// OpcodeSload32 loads the 32-bit value from the [base + offset] address, sign-extended to 64 bits: `v = Sload32 base, offset`.
	OpcodeSload32

	// OpcodeIstore32 stores the 32-bit value to the [base + offset] address, zero-extended to 64 bits: `Istore16 v, base, offset`.
	OpcodeIstore32

	// OpcodeLoadSplat represents a load that replicates the loaded value to all lanes `v = LoadSplat.lane p, Offset`.
	OpcodeLoadSplat

	// OpcodeVZeroExtLoad loads a scalar single/double precision floating point value from the [p + Offset] address,
	// and zero-extend it to the V128 value: `v = VExtLoad  p, Offset`.
	OpcodeVZeroExtLoad

	// OpcodeIconst represents the integer const.
	OpcodeIconst

	// OpcodeF32const represents the single-precision const.
	OpcodeF32const

	// OpcodeF64const represents the double-precision const.
	OpcodeF64const

	// OpcodeVconst represents the 128bit vector const.
	OpcodeVconst

	// OpcodeVbor computes binary or between two 128bit vectors: `v = bor x, y`.
	OpcodeVbor

	// OpcodeVbxor computes binary xor between two 128bit vectors: `v = bxor x, y`.
	OpcodeVbxor

	// OpcodeVband computes binary and between two 128bit vectors: `v = band x, y`.
	OpcodeVband

	// OpcodeVbandnot computes binary and-not between two 128bit vectors: `v = bandnot x, y`.
	OpcodeVbandnot

	// OpcodeVbnot negates a 128bit vector: `v = bnot x`.
	OpcodeVbnot

	// OpcodeVbitselect uses the bits in the control mask c to select the corresponding bit from x when 1
	// and y when 0: `v = bitselect c, x, y`.
	OpcodeVbitselect

	// OpcodeShuffle shuffles two vectors using the given 128-bit immediate: `v = shuffle imm, x, y`.
	// For each byte in the immediate, a value i in [0, 15] selects the i-th byte in vector x;
	// i in [16, 31] selects the (i-16)-th byte in vector y.
	OpcodeShuffle

	// OpcodeSelect chooses between two values based on a condition `c`: `v = Select c, x, y`.
	OpcodeSelect

	// OpcodeVanyTrue performs a any true operation: `s = VanyTrue a`.
	OpcodeVanyTrue

	// OpcodeVallTrue performs a lane-wise all true operation: `s = VallTrue.lane a`.
	OpcodeVallTrue

	// OpcodeVhighBits performs a lane-wise extract of the high bits: `v = VhighBits.lane a`.
	OpcodeVhighBits

	// OpcodeIcmp compares two integer values with the given condition: `v = icmp Cond, x, y`.
	OpcodeIcmp

	// OpcodeVIcmp compares two integer values with the given condition: `v = vicmp Cond, x, y` on vector.
	OpcodeVIcmp

	// OpcodeIcmpImm compares an integer value with the immediate value on the given condition: `v = icmp_imm Cond, x, Y`.
	OpcodeIcmpImm

	// OpcodeIadd performs an integer addition: `v = Iadd x, y`.
	OpcodeIadd

	// OpcodeVIadd performs an integer addition: `v = VIadd.lane x, y` on vector.
	OpcodeVIadd

	// OpcodeVSaddSat performs a signed saturating vector addition: `v = VSaddSat.lane x, y` on vector.
	OpcodeVSaddSat

	// OpcodeVUaddSat performs an unsigned saturating vector addition: `v = VUaddSat.lane x, y` on vector.
	OpcodeVUaddSat

	// OpcodeIsub performs an integer subtraction: `v = Isub x, y`.
	OpcodeIsub

	// OpcodeVIsub performs an integer subtraction: `v = VIsub.lane x, y` on vector.
	OpcodeVIsub

	// OpcodeVSsubSat performs a signed saturating vector subtraction: `v = VSsubSat.lane x, y` on vector.
	OpcodeVSsubSat

	// OpcodeVUsubSat performs an unsigned saturating vector subtraction: `v = VUsubSat.lane x, y` on vector.
	OpcodeVUsubSat

	// OpcodeVImin performs a signed integer min: `v = VImin.lane x, y` on vector.
	OpcodeVImin

	// OpcodeVUmin performs an unsigned integer min: `v = VUmin.lane x, y` on vector.
	OpcodeVUmin

	// OpcodeVImax performs a signed integer max: `v = VImax.lane x, y` on vector.
	OpcodeVImax

	// OpcodeVUmax performs an unsigned integer max: `v = VUmax.lane x, y` on vector.
	OpcodeVUmax

	// OpcodeVAvgRound performs an unsigned integer avg, truncating to zero: `v = VAvgRound.lane x, y` on vector.
	OpcodeVAvgRound

	// OpcodeVImul performs an integer multiplication: `v = VImul.lane x, y` on vector.
	OpcodeVImul

	// OpcodeVIneg negates the given integer vector value: `v = VIneg x`.
	OpcodeVIneg

	// OpcodeVIpopcnt counts the number of 1-bits in the given vector: `v = VIpopcnt x`.
	OpcodeVIpopcnt

	// OpcodeVIabs returns the absolute value for the given vector value: `v = VIabs.lane x`.
	OpcodeVIabs

	// OpcodeVIshl shifts x left by (y mod lane-width): `v = VIshl.lane x, y` on vector.
	OpcodeVIshl

	// OpcodeVUshr shifts x right by (y mod lane-width), unsigned: `v = VUshr.lane x, y` on vector.
	OpcodeVUshr

	// OpcodeVSshr shifts x right by (y mod lane-width), signed: `v = VSshr.lane x, y` on vector.
	OpcodeVSshr

	// OpcodeVFabs takes the absolute value of a floating point value: `v = VFabs.lane x on vector.
	OpcodeVFabs

	// OpcodeVFmax takes the maximum of two floating point values: `v = VFmax.lane x, y on vector.
	OpcodeVFmax

	// OpcodeVFmin takes the minimum of two floating point values: `v = VFmin.lane x, y on vector.
	OpcodeVFmin

	// OpcodeVFneg negates the given floating point vector value: `v = VFneg x`.
	OpcodeVFneg

	// OpcodeVFadd performs a floating point addition: `v = VFadd.lane x, y` on vector.
	OpcodeVFadd

	// OpcodeVFsub performs a floating point subtraction: `v = VFsub.lane x, y` on vector.
	OpcodeVFsub

	// OpcodeVFmul performs a floating point multiplication: `v = VFmul.lane x, y` on vector.
	OpcodeVFmul

	// OpcodeVFdiv performs a floating point division: `v = VFdiv.lane x, y` on vector.
	OpcodeVFdiv

	// OpcodeVFcmp compares two float values with the given condition: `v = VFcmp.lane Cond, x, y` on float.
	OpcodeVFcmp

	// OpcodeVCeil takes the ceiling of the given floating point value: `v = ceil.lane x` on vector.
	OpcodeVCeil

	// OpcodeVFloor takes the floor of the given floating point value: `v = floor.lane x` on vector.
	OpcodeVFloor

	// OpcodeVTrunc takes the truncation of the given floating point value: `v = trunc.lane x` on vector.
	OpcodeVTrunc

	// OpcodeVNearest takes the nearest integer of the given floating point value: `v = nearest.lane x` on vector.
	OpcodeVNearest

	// OpcodeVMaxPseudo computes the lane-wise maximum value `v = VMaxPseudo.lane x, y` on vector defined as `x < y ? x : y`.
	OpcodeVMaxPseudo

	// OpcodeVMinPseudo computes the lane-wise minimum value `v = VMinPseudo.lane x, y` on vector defined as `y < x ? x : y`.
	OpcodeVMinPseudo

	// OpcodeVSqrt takes the minimum of two floating point values: `v = VFmin.lane x, y` on vector.
	OpcodeVSqrt

	// OpcodeVFcvtToUintSat converts a floating point value to an unsigned integer: `v = FcvtToUintSat.lane x` on vector.
	OpcodeVFcvtToUintSat

	// OpcodeVFcvtToSintSat converts a floating point value to a signed integer: `v = VFcvtToSintSat.lane x` on vector.
	OpcodeVFcvtToSintSat

	// OpcodeVFcvtFromUint converts a floating point value from an unsigned integer: `v = FcvtFromUint.lane x` on vector.
	OpcodeVFcvtFromUint

	// OpcodeVFcvtFromSint converts a floating point value from a signed integer: `v = VFcvtFromSint.lane x` on vector.
	OpcodeVFcvtFromSint

	// OpcodeImul performs an integer multiplication: `v = Imul x, y`.
	OpcodeImul

	// OpcodeUdiv performs the unsigned integer division `v = Udiv x, y`.
	OpcodeUdiv

	// OpcodeSdiv performs the signed integer division `v = Sdiv x, y`.
	OpcodeSdiv

	// OpcodeUrem computes the remainder of the unsigned integer division `v = Urem x, y`.
	OpcodeUrem

	// OpcodeSrem computes the remainder of the signed integer division `v = Srem x, y`.
	OpcodeSrem

	// OpcodeBand performs a binary and: `v = Band x, y`.
	OpcodeBand

	// OpcodeBor performs a binary or: `v = Bor x, y`.
	OpcodeBor

	// OpcodeBxor performs a binary xor: `v = Bxor x, y`.
	OpcodeBxor

	// OpcodeBnot performs a binary not: `v = Bnot x`.
	OpcodeBnot

	// OpcodeRotl rotates the given integer value to the left: `v = Rotl x, y`.
	OpcodeRotl

	// OpcodeRotr rotates the given integer value to the right: `v = Rotr x, y`.
	OpcodeRotr

	// OpcodeIshl does logical shift left: `v = Ishl x, y`.
	OpcodeIshl

	// OpcodeUshr does logical shift right: `v = Ushr x, y`.
	OpcodeUshr

	// OpcodeSshr does arithmetic shift right: `v = Sshr x, y`.
	OpcodeSshr

	// OpcodeClz counts the number of leading zeros: `v = clz x`.
	OpcodeClz

	// OpcodeCtz counts the number of trailing zeros: `v = ctz x`.
	OpcodeCtz

	// OpcodePopcnt counts the number of 1-bits: `v = popcnt x`.
	OpcodePopcnt

	// OpcodeFcmp compares two floating point values: `v = fcmp Cond, x, y`.
	OpcodeFcmp

	// OpcodeFadd performs a floating point addition: / `v = Fadd x, y`.
	OpcodeFadd

	// OpcodeFsub performs a floating point subtraction: `v = Fsub x, y`.
	OpcodeFsub

	// OpcodeFmul performs a floating point multiplication: `v = Fmul x, y`.
	OpcodeFmul

	// OpcodeSqmulRoundSat performs a lane-wise saturating rounding multiplication
	// in Q15 format: `v = SqmulRoundSat.lane x,y` on vector.
	OpcodeSqmulRoundSat

	// OpcodeFdiv performs a floating point division: `v = Fdiv x, y`.
	OpcodeFdiv

	// OpcodeSqrt takes the square root of the given floating point value: `v = sqrt x`.
	OpcodeSqrt

	// OpcodeFneg negates the given floating point value: `v = Fneg x`.
	OpcodeFneg

	// OpcodeFabs takes the absolute value of the given floating point value: `v = fabs x`.
	OpcodeFabs

	// OpcodeFcopysign copies the sign of the second floating point value to the first floating point value:
	// `v = Fcopysign x, y`.
	OpcodeFcopysign

	// OpcodeFmin takes the minimum of two floating point values: `v = fmin x, y`.
	OpcodeFmin

	// OpcodeFmax takes the maximum of two floating point values: `v = fmax x, y`.
	OpcodeFmax

	// OpcodeCeil takes the ceiling of the given floating point value: `v = ceil x`.
	OpcodeCeil

	// OpcodeFloor takes the floor of the given floating point value: `v = floor x`.
	OpcodeFloor

	// OpcodeTrunc takes the truncation of the given floating point value: `v = trunc x`.
	OpcodeTrunc

	// OpcodeNearest takes the nearest integer of the given floating point value: `v = nearest x`.
	OpcodeNearest

	// OpcodeBitcast is a bitcast operation: `v = bitcast x`.
	OpcodeBitcast

	// OpcodeBmask ...
	// `v = bmask x`.
	OpcodeBmask

	// OpcodeIreduce ...
	// `v = ireduce x`.
	OpcodeIreduce

	// OpcodeSnarrow converts two input vectors x, y into a smaller lane vector by narrowing each lane, signed `v = Snarrow.lane x, y`.
	OpcodeSnarrow

	// OpcodeUnarrow converts two input vectors x, y into a smaller lane vector by narrowing each lane, unsigned `v = Unarrow.lane x, y`.
	OpcodeUnarrow

	// OpcodeSwidenLow converts low half of the smaller lane vector to a larger lane vector, sign extended: `v = SwidenLow.lane x`.
	OpcodeSwidenLow

	// OpcodeSwidenHigh converts high half of the smaller lane vector to a larger lane vector, sign extended: `v = SwidenHigh.lane x`.
	OpcodeSwidenHigh

	// OpcodeUwidenLow converts low half of the smaller lane vector to a larger lane vector, zero (unsigned) extended: `v = UwidenLow.lane x`.
	OpcodeUwidenLow

	// OpcodeUwidenHigh converts high half of the smaller lane vector to a larger lane vector, zero (unsigned) extended: `v = UwidenHigh.lane x`.
	OpcodeUwidenHigh

	// OpcodeIaddPairwise is a lane-wise integer extended pairwise addition producing extended results (twice wider results than the inputs): `v = iadd_pairwise x, y` on vector.
	OpcodeIaddPairwise

	// OpcodeWideningPairwiseDotProductS ...
	// `v = widening_pairwise_dot_product_s x, y`.
	OpcodeWideningPairwiseDotProductS

	// OpcodeUExtend zero-extends the given integer: `v = UExtend x, from->to`.
	OpcodeUExtend

	// OpcodeSExtend sign-extends the given integer: `v = SExtend x, from->to`.
	OpcodeSExtend

	// OpcodeFpromote promotes the given floating point value: `v = Fpromote x`.
	OpcodeFpromote

	// OpcodeFvpromoteLow converts the two lower single-precision floating point lanes
	// to the two double-precision lanes of the result: `v = FvpromoteLow.lane x` on vector.
	OpcodeFvpromoteLow

	// OpcodeFdemote demotes the given float point value: `v = Fdemote x`.
	OpcodeFdemote

	// OpcodeFvdemote converts the two double-precision floating point lanes
	// to two lower single-precision lanes of the result `v = Fvdemote.lane x`.
	OpcodeFvdemote

	// OpcodeFcvtToUint ...
	// `v = fcvt_to_uint x`.
	OpcodeFcvtToUint

	// OpcodeFcvtToSint converts a floating point value to a signed integer: `v = FcvtToSint x`.
	OpcodeFcvtToSint

	// OpcodeFcvtToUintSat converts a floating point value to an unsigned integer: `v = FcvtToUintSat x`.
	OpcodeFcvtToUintSat

	// OpcodeFcvtToSintSat ...
	// `v = fcvt_to_sint_sat x`.
	OpcodeFcvtToSintSat

	// OpcodeFcvtFromUint converts an unsigned integer to a floating point value: `v = FcvtFromUint x`.
	OpcodeFcvtFromUint

	// OpcodeFcvtFromSint converts a signed integer to a floating point value: `v = FcvtFromSint x`.
	OpcodeFcvtFromSint

	// OpcodeIsplit ...
	// `lo, hi = isplit x`.
	OpcodeIsplit

	// OpcodeIconcat ...
	// `v = iconcat lo, hi`.
	OpcodeIconcat

	// OpcodeAtomicRmw ...
	// `v = atomic_rmw MemFlags, AtomicRmwOp, p, x`.
	OpcodeAtomicRmw

	// OpcodeAtomicCas ...
	// `v = atomic_cas MemFlags, p, e, x`.
	OpcodeAtomicCas

	// OpcodeAtomicLoad ...
	// `v = atomic_load MemFlags, p`.
	OpcodeAtomicLoad

	// OpcodeAtomicStore ...
	// `atomic_store MemFlags, x, p`.
	OpcodeAtomicStore

	// OpcodeFence ...
	// `fence`.
	OpcodeFence
)

TODO: complete opcode comments.

func (Opcode) String

func (o Opcode) String() (ret string)

String implements fmt.Stringer.

type Signature

type Signature struct {
	// ID is a unique identifier for this signature used to lookup.
	ID SignatureID
	// Params and Results are the types of the parameters and results of the function.
	Params, Results []Type
	// contains filtered or unexported fields
}

Signature is a function prototype.

func (*Signature) String

func (s *Signature) String() string

String implements fmt.Stringer.

type SignatureID

type SignatureID int

SignatureID is an unique identifier used to lookup.

func (SignatureID) String

func (s SignatureID) String() string

String implements fmt.Stringer.

type SourceOffset

type SourceOffset int64

SourceOffset represents the offset of the source of an instruction.

func (SourceOffset) Valid

func (l SourceOffset) Valid() bool

Valid returns true if this source offset is valid.

type Type

type Type byte
const (

	// TypeI32 represents an integer type with 32 bits.
	TypeI32 Type

	// TypeI64 represents an integer type with 64 bits.
	TypeI64

	// TypeF32 represents 32-bit floats in the IEEE 754.
	TypeF32

	// TypeF64 represents 64-bit floats in the IEEE 754.
	TypeF64

	// TypeV128 represents 128-bit SIMD vectors.
	TypeV128
)

func (Type) Bits

func (t Type) Bits() byte

Bits returns the number of bits required to represent the type.

func (Type) IsInt

func (t Type) IsInt() bool

IsInt returns true if the type is an integer type.

func (Type) Size

func (t Type) Size() byte

Size returns the number of bytes required to represent the type.

func (Type) String

func (t Type) String() (ret string)

String implements fmt.Stringer.

type Value

type Value uint64

Value represents an SSA value with a type information. The relationship with Variable is 1: N (including 0), that means there might be multiple Variable(s) for a Value.

Higher 32-bit is used to store Type for this value.

const (
	ValueInvalid Value = Value(valueIDInvalid)
)

func (Value) Format

func (v Value) Format(b Builder) string

Format creates a debug string for this Value using the data stored in Builder.

func (Value) ID

func (v Value) ID() ValueID

ID returns the valueID of this value.

func (Value) Type

func (v Value) Type() Type

Type returns the Type of this value.

func (Value) Valid

func (v Value) Valid() bool

Valid returns true if this value is valid.

type ValueID

type ValueID uint32

ValueID is the lower 32bit of Value, which is the pure identifier of Value without type info.

type Variable

type Variable uint32

Variable is a unique identifier for a source program's variable and will correspond to multiple ssa Value(s).

For example, `Local 1` is a Variable in WebAssembly, and Value(s) will be created for it whenever it executes `local.set 1`.

Variable is useful to track the SSA Values of a variable in the source program, and can be used to find the corresponding latest SSA Value via Builder.FindValue.

func (Variable) String

func (v Variable) String() string

String implements fmt.Stringer.

type VecLane

type VecLane byte

VecLane represents a lane in a SIMD vector.

const (
	VecLaneInvalid VecLane = 1 + iota
	VecLaneI8x16
	VecLaneI16x8
	VecLaneI32x4
	VecLaneI64x2
	VecLaneF32x4
	VecLaneF64x2
)

func (VecLane) String

func (vl VecLane) String() (ret string)

String implements fmt.Stringer.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL