github.com/shogo82148/std@v1.22.1-0.20240327122250-4e474527810c/cmd/compile/internal/ssa/value.go (about) 1 // Copyright 2015 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package ssa 6 7 import ( 8 "github.com/shogo82148/std/cmd/compile/internal/ir" 9 "github.com/shogo82148/std/cmd/compile/internal/types" 10 "github.com/shogo82148/std/cmd/internal/src" 11 ) 12 13 // A Value represents a value in the SSA representation of the program. 14 // The ID and Type fields must not be modified. The remainder may be modified 15 // if they preserve the value of the Value (e.g. changing a (mul 2 x) to an (add x x)). 16 type Value struct { 17 // A unique identifier for the value. For performance we allocate these IDs 18 // densely starting at 1. There is no guarantee that there won't be occasional holes, though. 19 ID ID 20 21 // The operation that computes this value. See op.go. 22 Op Op 23 24 // The type of this value. Normally this will be a Go type, but there 25 // are a few other pseudo-types, see ../types/type.go. 26 Type *types.Type 27 28 // Auxiliary info for this value. The type of this information depends on the opcode and type. 29 // AuxInt is used for integer values, Aux is used for other values. 30 // Floats are stored in AuxInt using math.Float64bits(f). 31 // Unused portions of AuxInt are filled by sign-extending the used portion, 32 // even if the represented value is unsigned. 33 // Users of AuxInt which interpret AuxInt as unsigned (e.g. shifts) must be careful. 34 // Use Value.AuxUnsigned to get the zero-extended value of AuxInt. 35 AuxInt int64 36 Aux Aux 37 38 // Arguments of this value 39 Args []*Value 40 41 // Containing basic block 42 Block *Block 43 44 // Source position 45 Pos src.XPos 46 47 // Use count. Each appearance in Value.Args and Block.Controls counts once. 48 Uses int32 49 50 // wasm: Value stays on the WebAssembly stack. This value will not get a "register" (WebAssembly variable) 51 // nor a slot on Go stack, and the generation of this value is delayed to its use time. 52 OnWasmStack bool 53 54 // Is this value in the per-function constant cache? If so, remove from cache before changing it or recycling it. 55 InCache bool 56 57 // Storage for the first three args 58 argstorage [3]*Value 59 } 60 61 // short form print. Just v#. 62 func (v *Value) String() string 63 64 func (v *Value) AuxInt8() int8 65 66 func (v *Value) AuxUInt8() uint8 67 68 func (v *Value) AuxInt16() int16 69 70 func (v *Value) AuxInt32() int32 71 72 // AuxUnsigned returns v.AuxInt as an unsigned value for OpConst*. 73 // v.AuxInt is always sign-extended to 64 bits, even if the 74 // represented value is unsigned. This undoes that sign extension. 75 func (v *Value) AuxUnsigned() uint64 76 77 func (v *Value) AuxFloat() float64 78 79 func (v *Value) AuxValAndOff() ValAndOff 80 81 func (v *Value) AuxArm64BitField() arm64BitField 82 83 // long form print. v# = opcode <type> [aux] args [: reg] (names) 84 func (v *Value) LongString() string 85 86 // If/when midstack inlining is enabled (-l=4), the compiler gets both larger and slower. 87 // Not-inlining this method is a help (*Value.reset and *Block.NewValue0 are similar). 88 // 89 //go:noinline 90 func (v *Value) AddArg(w *Value) 91 92 //go:noinline 93 func (v *Value) AddArg2(w1, w2 *Value) 94 95 //go:noinline 96 func (v *Value) AddArg3(w1, w2, w3 *Value) 97 98 //go:noinline 99 func (v *Value) AddArg4(w1, w2, w3, w4 *Value) 100 101 //go:noinline 102 func (v *Value) AddArg5(w1, w2, w3, w4, w5 *Value) 103 104 //go:noinline 105 func (v *Value) AddArg6(w1, w2, w3, w4, w5, w6 *Value) 106 107 func (v *Value) AddArgs(a ...*Value) 108 109 func (v *Value) SetArg(i int, w *Value) 110 111 func (v *Value) SetArgs1(a *Value) 112 113 func (v *Value) SetArgs2(a, b *Value) 114 115 func (v *Value) SetArgs3(a, b, c *Value) 116 117 func (v *Value) Logf(msg string, args ...interface{}) 118 func (v *Value) Log() bool 119 func (v *Value) Fatalf(msg string, args ...interface{}) 120 121 // ResultReg returns the result register assigned to v, in cmd/internal/obj/$ARCH numbering. 122 // It is similar to Reg and Reg0, except that it is usable interchangeably for all Value Ops. 123 // If you know v.Op, using Reg or Reg0 (as appropriate) will be more efficient. 124 func (v *Value) ResultReg() int16 125 126 // Reg returns the register assigned to v, in cmd/internal/obj/$ARCH numbering. 127 func (v *Value) Reg() int16 128 129 // Reg0 returns the register assigned to the first output of v, in cmd/internal/obj/$ARCH numbering. 130 func (v *Value) Reg0() int16 131 132 // Reg1 returns the register assigned to the second output of v, in cmd/internal/obj/$ARCH numbering. 133 func (v *Value) Reg1() int16 134 135 // RegTmp returns the temporary register assigned to v, in cmd/internal/obj/$ARCH numbering. 136 func (v *Value) RegTmp() int16 137 138 func (v *Value) RegName() string 139 140 // MemoryArg returns the memory argument for the Value. 141 // The returned value, if non-nil, will be memory-typed (or a tuple with a memory-typed second part). 142 // Otherwise, nil is returned. 143 func (v *Value) MemoryArg() *Value 144 145 // LackingPos indicates whether v is a value that is unlikely to have a correct 146 // position assigned to it. Ignoring such values leads to more user-friendly positions 147 // assigned to nearby values and the blocks containing them. 148 func (v *Value) LackingPos() bool 149 150 // AutoVar returns a *Name and int64 representing the auto variable and offset within it 151 // where v should be spilled. 152 func AutoVar(v *Value) (*ir.Name, int64) 153 154 // CanSSA reports whether values of type t can be represented as a Value. 155 func CanSSA(t *types.Type) bool