Debian Codegraph @

src/cmd/compile/internal/ssa/location.go

raw
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 "cmd/compile/internal/ir"
9 "cmd/compile/internal/types"
10 "fmt"
11 )
12
13 // A place that an ssa variable can reside.
14 type Location interface {
15 String() string // name to use in assembly templates: AX, 16(SP), ...
16 }
17
18 // A Register is a machine register, like AX.
19 // They are numbered densely from 0 (for each architecture).
20 type Register struct {
21 num int32 // dense numbering
22 objNum int16 // register number from cmd/internal/obj/$ARCH
23 name string
24 }
25
26 func (r *Register) String() string {
27 return r.name
28 }
29
30 // ObjNum returns the register number from cmd/internal/obj/$ARCH that
31 // corresponds to this register.
32 func (r *Register) ObjNum() int16 {
33 return r.objNum
34 }
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 // an ONAME *ir.Name representing a stack location.
57 Type *types.Type // type of slot
58 Off int64 // offset of slot in N
59
60 SplitOf *LocalSlot // slot is a decomposition of SplitOf
61 SplitOffset int64 // .. at this offset.
62 }
63
64 func (s LocalSlot) String() string {
65 if s.Off == 0 {
66 return fmt.Sprintf("%v[%v]", s.N, s.Type)
67 }
68 return fmt.Sprintf("%v+%d[%v]", s.N, s.Off, s.Type)
69 }
70
71 type LocPair [2]Location
72
73 func (t LocPair) String() string {
74 n0, n1 := "nil", "nil"
75 if t[0] != nil {
76 n0 = t[0].String()
77 }
78 if t[1] != nil {
79 n1 = t[1].String()
80 }
81 return fmt.Sprintf("<%s,%s>", n0, n1)
82 }
83
84 type LocResults []Location
85
86 func (t LocResults) String() string {
87 s := ""
88 a := "<"
89 for _, r := range t {
90 a += s
91 s = ","
92 a += r.String()
93 }
94 a += ">"
95 return a
96 }
97
98 type Spill struct {
99 Type *types.Type
100 Offset int64
101 Reg int16
102 }