summaryrefslogtreecommitdiff
path: root/vendor/github.com/tetratelabs/wazero/internal/engine/wazevo/backend/vdef.go
blob: edfa962b5c7204334c4d5b5ff713e8a7d718cc88 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package backend

import (
	"github.com/tetratelabs/wazero/internal/engine/wazevo/backend/regalloc"
	"github.com/tetratelabs/wazero/internal/engine/wazevo/ssa"
)

// SSAValueDefinition represents a definition of an SSA value.
type SSAValueDefinition struct {
	// BlockParamValue is valid if Instr == nil
	BlockParamValue ssa.Value

	// BlkParamVReg is valid if Instr == nil
	BlkParamVReg regalloc.VReg

	// Instr is not nil if this is a definition from an instruction.
	Instr *ssa.Instruction
	// N is the index of the return value in the instr's return values list.
	N int
	// RefCount is the number of references to the result.
	RefCount int
}

func (d *SSAValueDefinition) IsFromInstr() bool {
	return d.Instr != nil
}

func (d *SSAValueDefinition) IsFromBlockParam() bool {
	return d.Instr == nil
}

func (d *SSAValueDefinition) SSAValue() ssa.Value {
	if d.IsFromBlockParam() {
		return d.BlockParamValue
	} else {
		r, rs := d.Instr.Returns()
		if d.N == 0 {
			return r
		} else {
			return rs[d.N-1]
		}
	}
}