Skip to content

Commit 82833b3

Browse files
committed
cmd/internal/gc: rearrange Node fields
Rearrange Node fields to enable better struct packing. This reduces readability in favor of shrinking the size of Nodes. This reduces the size of Node from 328 to 312. This reduces the memory usage to compile the rotate tests by about 4.4%. No functional changes. Passes toolstash -cmp. Updates #9933. Change-Id: I2764c5847fb1635ddc898e2ee385d007d67f03c5 Reviewed-on: https://go-review.googlesource.com/10141 Reviewed-by: Russ Cox <[email protected]>
1 parent f4ab820 commit 82833b3

File tree

1 file changed

+49
-41
lines changed

1 file changed

+49
-41
lines changed

src/cmd/internal/gc/syntax.go

Lines changed: 49 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -23,32 +23,6 @@ type Node struct {
2323
List *NodeList
2424
Rlist *NodeList
2525

26-
Op uint8
27-
Nointerface bool
28-
Ullman uint8 // sethi/ullman number
29-
Addable bool // addressable
30-
Etype uint8 // op for OASOP, etype for OTYPE, exclam for export, 6g saved reg
31-
Bounded bool // bounds check unnecessary
32-
Class uint8 // PPARAM, PAUTO, PEXTERN, etc
33-
Embedded uint8 // ODCLFIELD embedded type
34-
Colas bool // OAS resulting from :=
35-
Diag uint8 // already printed error about this
36-
Noescape bool // func arguments do not escape; TODO(rsc): move Noescape to Func struct (see CL 7360)
37-
Walkdef uint8
38-
Typecheck uint8
39-
Local bool
40-
Dodata uint8
41-
Initorder uint8
42-
Used bool
43-
Isddd bool // is the argument variadic
44-
Implicit bool
45-
Addrtaken bool // address taken, even if not moved to heap
46-
Assigned bool // is the variable ever assigned to
47-
Likely int8 // likeliness of if statement
48-
Hasbreak bool // has break statement
49-
Esc uint16 // EscXXX
50-
Funcdepth int32
51-
5226
// most nodes
5327
Type *Type
5428
Orig *Node // original form, for printing, and tracking copies of ONAMEs
@@ -57,12 +31,6 @@ type Node struct {
5731
// func
5832
Func *Func
5933

60-
// OLITERAL
61-
Val Val
62-
63-
// OREGISTER, OINDREG
64-
Reg int16
65-
6634
// ONAME
6735
Name *Name
6836
Defn *Node // ONAME: initializing assignment; OLABEL: labeled statement
@@ -79,19 +47,59 @@ type Node struct {
7947
Initplan *InitPlan
8048

8149
// Escape analysis.
82-
Escflowsrc *NodeList // flow(this, src)
83-
Escretval *NodeList // on OCALLxxx, list of dummy return values
84-
Escloopdepth int32 // -1: global, 0: return variables, 1:function top level, increased inside function for every loop or label to mark scopes
50+
Escflowsrc *NodeList // flow(this, src)
51+
Escretval *NodeList // on OCALLxxx, list of dummy return values
52+
53+
Sym *Sym // various
54+
55+
Opt interface{} // for optimization passes
56+
57+
// OLITERAL
58+
Val Val
8559

86-
Sym *Sym // various
87-
Vargen int32 // unique name for OTYPE/ONAME within a function. Function outputs are numbered starting at one.
88-
Lineno int32
8960
Xoffset int64
9061
Stkdelta int64 // offset added by stack frame compaction phase.
91-
Iota int32
92-
Walkgen uint32
62+
63+
// Escape analysis.
64+
Escloopdepth int32 // -1: global, 0: return variables, 1:function top level, increased inside function for every loop or label to mark scopes
65+
66+
Vargen int32 // unique name for OTYPE/ONAME within a function. Function outputs are numbered starting at one.
67+
Lineno int32
68+
Iota int32
69+
Walkgen uint32
70+
71+
Funcdepth int32
72+
73+
// OREGISTER, OINDREG
74+
Reg int16
75+
76+
// most nodes - smaller fields
9377
Esclevel Level
94-
Opt interface{} // for optimization passes
78+
Esc uint16 // EscXXX
79+
80+
Op uint8
81+
Nointerface bool
82+
Ullman uint8 // sethi/ullman number
83+
Addable bool // addressable
84+
Etype uint8 // op for OASOP, etype for OTYPE, exclam for export, 6g saved reg
85+
Bounded bool // bounds check unnecessary
86+
Class uint8 // PPARAM, PAUTO, PEXTERN, etc
87+
Embedded uint8 // ODCLFIELD embedded type
88+
Colas bool // OAS resulting from :=
89+
Diag uint8 // already printed error about this
90+
Noescape bool // func arguments do not escape; TODO(rsc): move Noescape to Func struct (see CL 7360)
91+
Walkdef uint8
92+
Typecheck uint8
93+
Local bool
94+
Dodata uint8
95+
Initorder uint8
96+
Used bool
97+
Isddd bool // is the argument variadic
98+
Implicit bool
99+
Addrtaken bool // address taken, even if not moved to heap
100+
Assigned bool // is the variable ever assigned to
101+
Likely int8 // likeliness of if statement
102+
Hasbreak bool // has break statement
95103
}
96104

97105
// Name holds Node fields used only by ONAME nodes.

0 commit comments

Comments
 (0)