github.com/shogo82148/std@v1.22.1-0.20240327122250-4e474527810c/cmd/compile/internal/ssagen/ssa.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 ssagen 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/liveness" 11 "github.com/shogo82148/std/cmd/compile/internal/objw" 12 "github.com/shogo82148/std/cmd/compile/internal/ssa" 13 "github.com/shogo82148/std/cmd/internal/obj" 14 "github.com/shogo82148/std/cmd/internal/src" 15 ) 16 17 func DumpInline(fn *ir.Func) 18 19 func InitEnv() 20 21 func InitConfig() 22 23 // AbiForBodylessFuncStackMap returns the ABI for a bodyless function's stack map. 24 // This is not necessarily the ABI used to call it. 25 // Currently (1.17 dev) such a stack map is always ABI0; 26 // any ABI wrapper that is present is nosplit, hence a precise 27 // stack map is not needed there (the parameters survive only long 28 // enough to call the wrapped assembly function). 29 // This always returns a freshly copied ABI. 30 func AbiForBodylessFuncStackMap(fn *ir.Func) *abi.ABIConfig 31 32 func InitTables() 33 34 func IsIntrinsicCall(n *ir.CallExpr) bool 35 36 // Branch is an unresolved branch. 37 type Branch struct { 38 P *obj.Prog 39 B *ssa.Block 40 } 41 42 // State contains state needed during Prog generation. 43 type State struct { 44 ABI obj.ABI 45 46 pp *objw.Progs 47 48 // Branches remembers all the branch instructions we've seen 49 // and where they would like to go. 50 Branches []Branch 51 52 // JumpTables remembers all the jump tables we've seen. 53 JumpTables []*ssa.Block 54 55 // bstart remembers where each block starts (indexed by block ID) 56 bstart []*obj.Prog 57 58 maxarg int64 59 60 // Map from GC safe points to liveness index, generated by 61 // liveness analysis. 62 livenessMap liveness.Map 63 64 // partLiveArgs includes arguments that may be partially live, for which we 65 // need to generate instructions that spill the argument registers. 66 partLiveArgs map[*ir.Name]bool 67 68 // lineRunStart records the beginning of the current run of instructions 69 // within a single block sharing the same line number 70 // Used to move statement marks to the beginning of such runs. 71 lineRunStart *obj.Prog 72 73 // wasm: The number of values on the WebAssembly stack. This is only used as a safeguard. 74 OnWasmStackSkipped int 75 } 76 77 func (s *State) FuncInfo() *obj.FuncInfo 78 79 // Prog appends a new Prog. 80 func (s *State) Prog(as obj.As) *obj.Prog 81 82 // Pc returns the current Prog. 83 func (s *State) Pc() *obj.Prog 84 85 // SetPos sets the current source position. 86 func (s *State) SetPos(pos src.XPos) 87 88 // Br emits a single branch instruction and returns the instruction. 89 // Not all architectures need the returned instruction, but otherwise 90 // the boilerplate is common to all. 91 func (s *State) Br(op obj.As, target *ssa.Block) *obj.Prog 92 93 // DebugFriendlySetPosFrom adjusts Pos.IsStmt subject to heuristics 94 // that reduce "jumpy" line number churn when debugging. 95 // Spill/fill/copy instructions from the register allocator, 96 // phi functions, and instructions with a no-pos position 97 // are examples of instructions that can cause churn. 98 func (s *State) DebugFriendlySetPosFrom(v *ssa.Value) 99 100 // emit argument info (locations on stack) of f for traceback. 101 func EmitArgInfo(f *ir.Func, abiInfo *abi.ABIParamResultInfo) *obj.LSym 102 103 // For generating consecutive jump instructions to model a specific branching 104 type IndexJump struct { 105 Jump obj.As 106 Index int 107 } 108 109 // CombJump generates combinational instructions (2 at present) for a block jump, 110 // thereby the behaviour of non-standard condition codes could be simulated 111 func (s *State) CombJump(b, next *ssa.Block, jumps *[2][2]IndexJump) 112 113 // AddAux adds the offset in the aux fields (AuxInt and Aux) of v to a. 114 func AddAux(a *obj.Addr, v *ssa.Value) 115 116 func AddAux2(a *obj.Addr, v *ssa.Value, offset int64) 117 118 // CheckLoweredPhi checks that regalloc and stackalloc correctly handled phi values. 119 // Called during ssaGenValue. 120 func CheckLoweredPhi(v *ssa.Value) 121 122 // CheckLoweredGetClosurePtr checks that v is the first instruction in the function's entry block, 123 // except for incoming in-register arguments. 124 // The output of LoweredGetClosurePtr is generally hardwired to the correct register. 125 // That register contains the closure pointer on closure entry. 126 func CheckLoweredGetClosurePtr(v *ssa.Value) 127 128 // CheckArgReg ensures that v is in the function's entry block. 129 func CheckArgReg(v *ssa.Value) 130 131 func AddrAuto(a *obj.Addr, v *ssa.Value) 132 133 // Call returns a new CALL instruction for the SSA value v. 134 // It uses PrepareCall to prepare the call. 135 func (s *State) Call(v *ssa.Value) *obj.Prog 136 137 // TailCall returns a new tail call instruction for the SSA value v. 138 // It is like Call, but for a tail call. 139 func (s *State) TailCall(v *ssa.Value) *obj.Prog 140 141 // PrepareCall prepares to emit a CALL instruction for v and does call-related bookkeeping. 142 // It must be called immediately before emitting the actual CALL instruction, 143 // since it emits PCDATA for the stack map at the call (calls are safe points). 144 func (s *State) PrepareCall(v *ssa.Value) 145 146 // UseArgs records the fact that an instruction needs a certain amount of 147 // callee args space for its use. 148 func (s *State) UseArgs(n int64) 149 150 // SpillSlotAddr uses LocalSlot information to initialize an obj.Addr 151 // The resulting addr is used in a non-standard context -- in the prologue 152 // of a function, before the frame has been constructed, so the standard 153 // addressing for the parameters will be wrong. 154 func SpillSlotAddr(spill ssa.Spill, baseReg int16, extraOffset int64) obj.Addr 155 156 var ( 157 BoundsCheckFunc [ssa.BoundsKindCount]*obj.LSym 158 ExtendCheckFunc [ssa.BoundsKindCount]*obj.LSym 159 )