github.com/wasilibs/wazerox@v0.0.0-20240124024944-4923be63ab5f/internal/engine/wazevo/backend/vdef.go (about) 1 package backend 2 3 import ( 4 "github.com/wasilibs/wazerox/internal/engine/wazevo/backend/regalloc" 5 "github.com/wasilibs/wazerox/internal/engine/wazevo/ssa" 6 ) 7 8 // SSAValueDefinition represents a definition of an SSA value. 9 type SSAValueDefinition struct { 10 // BlockParamValue is valid if Instr == nil 11 BlockParamValue ssa.Value 12 13 // BlkParamVReg is valid if Instr == nil 14 BlkParamVReg regalloc.VReg 15 16 // Instr is not nil if this is a definition from an instruction. 17 Instr *ssa.Instruction 18 // N is the index of the return value in the instr's return values list. 19 N int 20 // RefCount is the number of references to the result. 21 RefCount int 22 } 23 24 func (d *SSAValueDefinition) IsFromInstr() bool { 25 return d.Instr != nil 26 } 27 28 func (d *SSAValueDefinition) IsFromBlockParam() bool { 29 return d.Instr == nil 30 } 31 32 func (d *SSAValueDefinition) SSAValue() ssa.Value { 33 if d.IsFromBlockParam() { 34 return d.BlockParamValue 35 } else { 36 r, rs := d.Instr.Returns() 37 if d.N == 0 { 38 return r 39 } else { 40 return rs[d.N-1] 41 } 42 } 43 }