github.com/shogo82148/std@v1.22.1-0.20240327122250-4e474527810c/cmd/compile/internal/ssa/op.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/abi" 9 "github.com/shogo82148/std/cmd/compile/internal/ir" 10 "github.com/shogo82148/std/cmd/compile/internal/types" 11 "github.com/shogo82148/std/cmd/internal/obj" 12 ) 13 14 // An Op encodes the specific operation that a Value performs. 15 // Opcodes' semantics can be modified by the type and aux fields of the Value. 16 // For instance, OpAdd can be 32 or 64 bit, signed or unsigned, float or complex, depending on Value.Type. 17 // Semantics of each op are described in the opcode files in _gen/*Ops.go. 18 // There is one file for generic (architecture-independent) ops and one file 19 // for each architecture. 20 type Op int32 21 22 type AuxNameOffset struct { 23 Name *ir.Name 24 Offset int64 25 } 26 27 func (a *AuxNameOffset) CanBeAnSSAAux() 28 func (a *AuxNameOffset) String() string 29 30 func (a *AuxNameOffset) FrameOffset() int64 31 32 type AuxCall struct { 33 Fn *obj.LSym 34 reg *regInfo 35 abiInfo *abi.ABIParamResultInfo 36 } 37 38 // Reg returns the regInfo for a given call, combining the derived in/out register masks 39 // with the machine-specific register information in the input i. (The machine-specific 40 // regInfo is much handier at the call site than it is when the AuxCall is being constructed, 41 // therefore do this lazily). 42 // 43 // TODO: there is a Clever Hack that allows pre-generation of a small-ish number of the slices 44 // of inputInfo and outputInfo used here, provided that we are willing to reorder the inputs 45 // and outputs from calls, so that all integer registers come first, then all floating registers. 46 // At this point (active development of register ABI) that is very premature, 47 // but if this turns out to be a cost, we could do it. 48 func (a *AuxCall) Reg(i *regInfo, c *Config) *regInfo 49 50 func (a *AuxCall) ABI() *abi.ABIConfig 51 52 func (a *AuxCall) ABIInfo() *abi.ABIParamResultInfo 53 54 func (a *AuxCall) ResultReg(c *Config) *regInfo 55 56 // For ABI register index r, returns the register number used in the obj 57 // package (assembler). 58 func ObjRegForAbiReg(r abi.RegIndex, c *Config) int16 59 60 // ArgWidth returns the amount of stack needed for all the inputs 61 // and outputs of a function or method, including ABI-defined parameter 62 // slots and ABI-defined spill slots for register-resident parameters. 63 // 64 // The name is taken from the types package's ArgWidth(<function type>), 65 // which predated changes to the ABI; this version handles those changes. 66 func (a *AuxCall) ArgWidth() int64 67 68 // ParamAssignmentForResult returns the ABI Parameter assignment for result which (indexed 0, 1, etc). 69 func (a *AuxCall) ParamAssignmentForResult(which int64) *abi.ABIParamAssignment 70 71 // OffsetOfResult returns the SP offset of result which (indexed 0, 1, etc). 72 func (a *AuxCall) OffsetOfResult(which int64) int64 73 74 // OffsetOfArg returns the SP offset of argument which (indexed 0, 1, etc). 75 // If the call is to a method, the receiver is the first argument (i.e., index 0) 76 func (a *AuxCall) OffsetOfArg(which int64) int64 77 78 // RegsOfResult returns the register(s) used for result which (indexed 0, 1, etc). 79 func (a *AuxCall) RegsOfResult(which int64) []abi.RegIndex 80 81 // RegsOfArg returns the register(s) used for argument which (indexed 0, 1, etc). 82 // If the call is to a method, the receiver is the first argument (i.e., index 0) 83 func (a *AuxCall) RegsOfArg(which int64) []abi.RegIndex 84 85 // NameOfResult returns the ir.Name of result which (indexed 0, 1, etc). 86 func (a *AuxCall) NameOfResult(which int64) *ir.Name 87 88 // TypeOfResult returns the type of result which (indexed 0, 1, etc). 89 func (a *AuxCall) TypeOfResult(which int64) *types.Type 90 91 // TypeOfArg returns the type of argument which (indexed 0, 1, etc). 92 // If the call is to a method, the receiver is the first argument (i.e., index 0) 93 func (a *AuxCall) TypeOfArg(which int64) *types.Type 94 95 // SizeOfResult returns the size of result which (indexed 0, 1, etc). 96 func (a *AuxCall) SizeOfResult(which int64) int64 97 98 // SizeOfArg returns the size of argument which (indexed 0, 1, etc). 99 // If the call is to a method, the receiver is the first argument (i.e., index 0) 100 func (a *AuxCall) SizeOfArg(which int64) int64 101 102 // NResults returns the number of results. 103 func (a *AuxCall) NResults() int64 104 105 // LateExpansionResultType returns the result type (including trailing mem) 106 // for a call that will be expanded later in the SSA phase. 107 func (a *AuxCall) LateExpansionResultType() *types.Type 108 109 // NArgs returns the number of arguments (including receiver, if there is one). 110 func (a *AuxCall) NArgs() int64 111 112 // String returns "AuxCall{<fn>}" 113 func (a *AuxCall) String() string 114 115 // StaticAuxCall returns an AuxCall for a static call. 116 func StaticAuxCall(sym *obj.LSym, paramResultInfo *abi.ABIParamResultInfo) *AuxCall 117 118 // InterfaceAuxCall returns an AuxCall for an interface call. 119 func InterfaceAuxCall(paramResultInfo *abi.ABIParamResultInfo) *AuxCall 120 121 // ClosureAuxCall returns an AuxCall for a closure call. 122 func ClosureAuxCall(paramResultInfo *abi.ABIParamResultInfo) *AuxCall 123 124 func (*AuxCall) CanBeAnSSAAux() 125 126 // OwnAuxCall returns a function's own AuxCall. 127 func OwnAuxCall(fn *obj.LSym, paramResultInfo *abi.ABIParamResultInfo) *AuxCall 128 129 // A SymEffect describes the effect that an SSA Value has on the variable 130 // identified by the symbol in its Aux field. 131 type SymEffect int8 132 133 const ( 134 SymRead SymEffect = 1 << iota 135 SymWrite 136 SymAddr 137 138 SymRdWr = SymRead | SymWrite 139 140 SymNone SymEffect = 0 141 ) 142 143 // A Sym represents a symbolic offset from a base register. 144 // Currently a Sym can be one of 3 things: 145 // - a *gc.Node, for an offset from SP (the stack pointer) 146 // - a *obj.LSym, for an offset from SB (the global pointer) 147 // - nil, for no offset 148 type Sym interface { 149 CanBeAnSSASym() 150 CanBeAnSSAAux() 151 } 152 153 // A ValAndOff is used by the several opcodes. It holds 154 // both a value and a pointer offset. 155 // A ValAndOff is intended to be encoded into an AuxInt field. 156 // The zero ValAndOff encodes a value of 0 and an offset of 0. 157 // The high 32 bits hold a value. 158 // The low 32 bits hold a pointer offset. 159 type ValAndOff int64 160 161 func (x ValAndOff) Val() int32 162 func (x ValAndOff) Val64() int64 163 func (x ValAndOff) Val16() int16 164 func (x ValAndOff) Val8() int8 165 166 func (x ValAndOff) Off64() int64 167 func (x ValAndOff) Off() int32 168 169 func (x ValAndOff) String() string 170 171 type BoundsKind uint8 172 173 const ( 174 BoundsIndex BoundsKind = iota 175 BoundsIndexU 176 BoundsSliceAlen 177 BoundsSliceAlenU 178 BoundsSliceAcap 179 BoundsSliceAcapU 180 BoundsSliceB 181 BoundsSliceBU 182 BoundsSlice3Alen 183 BoundsSlice3AlenU 184 BoundsSlice3Acap 185 BoundsSlice3AcapU 186 BoundsSlice3B 187 BoundsSlice3BU 188 BoundsSlice3C 189 BoundsSlice3CU 190 BoundsConvert 191 BoundsKindCount 192 )