package regalloc

Import Path
	github.com/tetratelabs/wazero/internal/engine/wazevo/backend/regalloc (on go.dev)

Dependency Relation
	imports 5 packages, and imported by 2 packages

Involved Source Files api.go reg.go Package regalloc performs register allocation. The algorithm can work on any ISA by implementing the interfaces in api.go. References: - https://web.stanford.edu/class/archive/cs/cs143/cs143.1128/lectures/17/Slides17.pdf - https://en.wikipedia.org/wiki/Chaitin%27s_algorithm - https://llvm.org/ProjectsWithLLVM/2004-Fall-CS426-LS.pdf - https://pfalcon.github.io/ssabook/latest/book-full.pdf: Chapter 9. for liveness analysis. - https://github.com/golang/go/blob/release-branch.go1.21/src/cmd/compile/internal/ssa/regalloc.go regset.go
Package-Level Type Names (total 10)
/* sort by: | */
Type Parameters: I: Instr B: Block[I] F: Function[I, B] Allocator is a register allocator. DoAllocation performs register allocation on the given Function. Reset resets the allocator's internal state so that it can be reused. func NewAllocator[I, B, F](allocatableRegs *RegisterInfo) Allocator[I, B, F]
Type Parameters: I: Instr Block is a basic block in the CFG of a function, and it consists of multiple instructions, and predecessor Block(s). Right now, this corresponds to a ssa.BasicBlock lowered to the machine level. Entry returns true if the block is for the entry block. FirstInstr returns the fist instruction in this block where instructions will be inserted after it. ID returns the unique identifier of this block which is ordered in the reverse post-order traversal of the CFG. InstrIteratorBegin returns the first instruction in this block. Instructions added after lowering must be skipped. Note: multiple Instr(s) will not be held at the same time, so it's safe to use the same impl for the return Instr. InstrIteratorNext returns the next instruction in this block. Instructions added after lowering must be skipped. Note: multiple Instr(s) will not be held at the same time, so it's safe to use the same impl for the return Instr. InstrRevIteratorBegin is the same as InstrIteratorBegin, but in the reverse order. InstrRevIteratorNext is the same as InstrIteratorNext, but in the reverse order. LastInstrForInsertion returns the last instruction in this block where instructions will be inserted before it. Such insertions only happen when we need to insert spill/reload instructions to adjust the merge edges. At the time of register allocation, all the critical edges are already split, so there is no need to worry about the case where branching instruction has multiple successors. Therefore, usually, it is the nop instruction, but if the block ends with an unconditional branching, then it returns the unconditional branch, not the nop. In other words it is either nop or unconditional branch. LoopHeader returns true if this block is a loop header. LoopNestingForestChildren returns the number of children of this block in the loop nesting forest. Preds returns the number of predecessors of this block in the CFG. Succs returns the number of successors of this block in the CFG.
Type Parameters: I: Instr B: Block[I] Function is the top-level interface to do register allocation, which corresponds to a CFG containing Blocks(s). I is the type of the instruction, and B is the type of the basic block. BlockParams returns the virtual registers used as the parameters of this block. ClobberedRegisters tell the clobbered registers by this function. Idom returns the immediate dominator of the given block. InsertMoveBefore inserts move instruction(s) before the given instruction for the given virtual registers. LoopNestingForestChild returns the i-th child of the block in the loop nesting forest. LoopNestingForestRoot returns the i-th root of the loop nesting forest in a function. LoopNestingForestRoots returns the number of roots of the loop nesting forest in a function. LowestCommonAncestor returns the lowest common ancestor of two blocks in the dominator tree. PostOrderBlockIteratorBegin returns the first block in the post-order traversal of the CFG. In other words, the last blocks in the CFG will be returned first. PostOrderBlockIteratorNext returns the next block in the post-order traversal of the CFG. Pred returns the i-th predecessor of the block in the CFG. ReloadRegisterAfter inserts reload instruction(s) after the given instruction for the given virtual register. ReloadRegisterBefore inserts reload instruction(s) before the given instruction for the given virtual register. ReversePostOrderBlockIteratorBegin returns the first block in the reverse post-order traversal of the CFG. In other words, the first blocks in the CFG will be returned first. ReversePostOrderBlockIteratorNext returns the next block in the reverse post-order traversal of the CFG. StoreRegisterAfter inserts store instruction(s) after the given instruction for the given virtual register. StoreRegisterBefore inserts store instruction(s) before the given instruction for the given virtual register. Succ returns the i-th successor of the block in the CFG. SwapBefore swaps the two virtual registers at the end of the given block.
Instr is an instruction in a block, abstracting away the underlying ISA. AssignDef assigns a RealReg-allocated virtual register defined by this instruction. This only accepts one register because we don't allocate registers for multi-def instructions (i.e. call instruction) AssignUse assigns the RealReg-allocated virtual register used by this instruction at the given index. Defs returns the virtual registers defined by this instruction. IsCall returns true if this instruction is a call instruction. The result is used to insert caller saved register spills and restores. IsCopy returns true if this instruction is a move instruction between two registers. If true, the instruction is of the form of dst = src, and if the src and dst do not interfere with each other, we could coalesce them, and hence the copy can be eliminated from the final code. IsIndirectCall returns true if this instruction is an indirect call instruction which calls a function pointer. The result is used to insert caller saved register spills and restores. IsReturn returns true if this instruction is a return instruction. ( Instr) String() string Uses returns the virtual registers used by this instruction. Note: multiple returned []VReg will not be held at the same time, so it's safe to use the same slice for this. Instr : expvar.Var Instr : fmt.Stringer
RealReg represents a physical register. String implements fmt.Stringer. RealReg : expvar.Var RealReg : fmt.Stringer func VReg.RealReg() RealReg func github.com/tetratelabs/wazero/internal/engine/wazevo/backend.Machine.ArgsResultsRegs() (argResultInts, argResultFloats []RealReg) func FromRealReg(r RealReg, typ RegType) VReg func NewRegSet(regs ...RealReg) RegSet func VReg.SetRealReg(r RealReg) VReg func github.com/tetratelabs/wazero/internal/engine/wazevo/backend.(*FunctionABI).Init(sig *ssa.Signature, argResultInts, argResultFloats []RealReg) const RealRegInvalid
RegisterInfo holds the statically-known ISA-specific register information. AllocatableRegisters is a 2D array of allocatable RealReg, indexed by regTypeNum and regNum. The order matters: the first element is the most preferred one when allocating. CalleeSavedRegisters RegSet CallerSavedRegisters RegSet RealRegName returns the name of the given RealReg for debugging. RealRegToVReg []VReg RealRegType func(r RealReg) RegType func NewAllocator[I, B, F](allocatableRegs *RegisterInfo) Allocator[I, B, F]
RegSet represents a set of registers. ( RegSet) Range(f func(allocatedRealReg RealReg)) func NewRegSet(regs ...RealReg) RegSet
RegType represents the type of a register. String implements fmt.Stringer. RegType : expvar.Var RegType : fmt.Stringer func RegTypeOf(p ssa.Type) RegType func VReg.RegType() RegType func FromRealReg(r RealReg, typ RegType) VReg func VReg.SetRegType(t RegType) VReg const NumRegType const RegTypeFloat const RegTypeInt const RegTypeInvalid
VReg represents a register which is assigned to an SSA value. This is used to represent a register in the backend. A VReg may or may not be a physical register, and the info of physical register can be obtained by RealReg. ID returns the VRegID of this VReg. IsRealReg returns true if this VReg is backed by a physical register. RealReg returns the RealReg of this VReg. RegType returns the RegType of this VReg. SetRealReg sets the RealReg of this VReg and returns the updated VReg. SetRegType sets the RegType of this VReg and returns the updated VReg. String implements fmt.Stringer. Valid returns true if this VReg is Valid. VReg : expvar.Var VReg : fmt.Stringer func FromRealReg(r RealReg, typ RegType) VReg func Function.BlockParams(B, *[]VReg) []VReg func Instr.Defs(*[]VReg) []VReg func Instr.Uses(*[]VReg) []VReg func VReg.SetRealReg(r RealReg) VReg func VReg.SetRegType(t RegType) VReg func github.com/tetratelabs/wazero/internal/engine/wazevo/backend.Compiler.AllocateVReg(typ ssa.Type) VReg func github.com/tetratelabs/wazero/internal/engine/wazevo/backend.Compiler.VRegOf(value ssa.Value) VReg func Function.BlockParams(B, *[]VReg) []VReg func Function.ClobberedRegisters([]VReg) func Function.InsertMoveBefore(dst, src VReg, instr I) func Function.ReloadRegisterAfter(v VReg, instr I) func Function.ReloadRegisterBefore(v VReg, instr I) func Function.StoreRegisterAfter(v VReg, instr I) func Function.StoreRegisterBefore(v VReg, instr I) func Function.SwapBefore(x1, x2, tmp VReg, instr I) func Instr.AssignDef(VReg) func Instr.AssignUse(index int, v VReg) func Instr.Defs(*[]VReg) []VReg func Instr.Uses(*[]VReg) []VReg func github.com/tetratelabs/wazero/internal/engine/wazevo/backend.Compiler.TypeOf(VReg) ssa.Type func github.com/tetratelabs/wazero/internal/engine/wazevo/backend.Machine.InsertLoadConstantBlockArg(instr *ssa.Instruction, vr VReg) func github.com/tetratelabs/wazero/internal/engine/wazevo/backend.Machine.InsertMove(dst, src VReg, typ ssa.Type) const VRegInvalid
VRegID is the lower 32bit of VReg, which is the pure identifier of VReg without RealReg info. func VReg.ID() VRegID const VRegIDNonReservedBegin
Package-Level Functions (total 4)
FromRealReg returns a VReg from the given RealReg and RegType. This is used to represent a specific pre-colored register in the backend.
Type Parameters: I: Instr B: Block[I] F: Function[I, B] NewAllocator returns a new Allocator.
NewRegSet returns a new RegSet with the given registers.
RegTypeOf returns the RegType of the given ssa.Type.
Package-Level Constants (total 7)
const NumRegType RegType = 3
const RegTypeInt RegType = 1
const VRegInvalid VReg = 2147483648