github.com/shogo82148/std@v1.22.1-0.20240327122250-4e474527810c/cmd/compile/internal/ssa/location.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  )
    11  
    12  // A place that an ssa variable can reside.
    13  type Location interface {
    14  	String() string
    15  }
    16  
    17  // A Register is a machine register, like AX.
    18  // They are numbered densely from 0 (for each architecture).
    19  type Register struct {
    20  	num    int32
    21  	objNum int16
    22  	gcNum  int16
    23  	name   string
    24  }
    25  
    26  func (r *Register) String() string
    27  
    28  // ObjNum returns the register number from cmd/internal/obj/$ARCH that
    29  // corresponds to this register.
    30  func (r *Register) ObjNum() int16
    31  
    32  // GCNum returns the runtime GC register index of r, or -1 if this
    33  // register can't contain pointers.
    34  func (r *Register) GCNum() int16
    35  
    36  // A LocalSlot is a location in the stack frame, which identifies and stores
    37  // part or all of a PPARAM, PPARAMOUT, or PAUTO ONAME node.
    38  // It can represent a whole variable, part of a larger stack slot, or part of a
    39  // variable that has been decomposed into multiple stack slots.
    40  // As an example, a string could have the following configurations:
    41  //
    42  //	          stack layout              LocalSlots
    43  //
    44  //	Optimizations are disabled. s is on the stack and represented in its entirety.
    45  //	[ ------- s string ---- ] { N: s, Type: string, Off: 0 }
    46  //
    47  //	s was not decomposed, but the SSA operates on its parts individually, so
    48  //	there is a LocalSlot for each of its fields that points into the single stack slot.
    49  //	[ ------- s string ---- ] { N: s, Type: *uint8, Off: 0 }, {N: s, Type: int, Off: 8}
    50  //
    51  //	s was decomposed. Each of its fields is in its own stack slot and has its own LocalSLot.
    52  //	[ ptr *uint8 ] [ len int] { N: ptr, Type: *uint8, Off: 0, SplitOf: parent, SplitOffset: 0},
    53  //	                          { N: len, Type: int, Off: 0, SplitOf: parent, SplitOffset: 8}
    54  //	                          parent = &{N: s, Type: string}
    55  type LocalSlot struct {
    56  	N    *ir.Name
    57  	Type *types.Type
    58  	Off  int64
    59  
    60  	SplitOf     *LocalSlot
    61  	SplitOffset int64
    62  }
    63  
    64  func (s LocalSlot) String() string
    65  
    66  type LocPair [2]Location
    67  
    68  func (t LocPair) String() string
    69  
    70  type LocResults []Location
    71  
    72  func (t LocResults) String() string
    73  
    74  type Spill struct {
    75  	Type   *types.Type
    76  	Offset int64
    77  	Reg    int16
    78  }