From 7c9225a018bb6a8ae1fa66ec4a74cfb6872951b5 Mon Sep 17 00:00:00 2001 From: Josh Bleecher Snyder Date: Fri, 15 May 2015 08:27:03 -0700 Subject: [PATCH] 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 368 to 344. This reduces the memory usage to compile the rotate tests by about 5.6%. No functional changes. Passes toolstash -cmp. Updates #9933. Change-Id: I2764c5847fb1635ddc898e2ee385d007d67f03c5 --- src/cmd/internal/gc/go.go | 4 +- src/cmd/internal/gc/syntax.go | 100 ++++++++++++++++++---------------- 2 files changed, 56 insertions(+), 48 deletions(-) diff --git a/src/cmd/internal/gc/go.go b/src/cmd/internal/gc/go.go index f116e6020a711b..d520bf1b7d2798 100644 --- a/src/cmd/internal/gc/go.go +++ b/src/cmd/internal/gc/go.go @@ -82,14 +82,14 @@ type Mpcplx struct { } type Val struct { - Ctype int16 // U contains one of: // bool bool when Ctype == CTBOOL // *Mpint int when Ctype == CTINT, rune when Ctype == CTRUNE // *Mpflt float when Ctype == CTFLT // *Mpcplx pair of floats when Ctype == CTCPLX // string string when Ctype == CTSTR - U interface{} + U interface{} + Ctype int16 } type Pkg struct { diff --git a/src/cmd/internal/gc/syntax.go b/src/cmd/internal/gc/syntax.go index c5dd0c7c325659..49e31751a1156a 100644 --- a/src/cmd/internal/gc/syntax.go +++ b/src/cmd/internal/gc/syntax.go @@ -23,32 +23,6 @@ type Node struct { List *NodeList Rlist *NodeList - Op uint8 - Nointerface bool - Ullman uint8 // sethi/ullman number - Addable bool // addressable - Etype uint8 // op for OASOP, etype for OTYPE, exclam for export - Bounded bool // bounds check unnecessary - Class uint8 // PPARAM, PAUTO, PEXTERN, etc - Embedded uint8 // ODCLFIELD embedded type - Colas bool // OAS resulting from := - Diag uint8 // already printed error about this - Noescape bool // func arguments do not escape; TODO(rsc): move Noescape to Func struct (see CL 7360) - Walkdef uint8 - Typecheck uint8 - Local bool - Dodata uint8 - Initorder uint8 - Used bool - Isddd bool // is the argument variadic - Implicit bool - Addrtaken bool // address taken, even if not moved to heap - Assigned bool // is the variable ever assigned to - Likely int8 // likeliness of if statement - Hasbreak bool // has break statement - Esc uint16 // EscXXX - Funcdepth int32 - // most nodes Type *Type Orig *Node // original form, for printing, and tracking copies of ONAMEs @@ -57,12 +31,6 @@ type Node struct { // func Func *Func - // OLITERAL - Val Val - - // OREGISTER, OINDREG - Reg int16 - // ONAME *Name Ntype *Node @@ -76,10 +44,9 @@ type Node struct { Stackparam *Node // OPARAM node referring to stack copy of param Alloc *Node // allocation call - // ONAME closure param with PPARAMREF - Outer *Node // outer PPARAMREF in nested closure - Closure *Node // ONAME/PHEAP <-> ONAME/PPARAMREF - Top TypecheckCtxt // top context (Ecall, Eproc, etc) + // ONAME closure param with PPARAMREF (see also the Top field, below) + Outer *Node // outer PPARAMREF in nested closure + Closure *Node // ONAME/PHEAP <-> ONAME/PPARAMREF // OPACK Pkg *Pkg @@ -88,20 +55,61 @@ type Node struct { Initplan *InitPlan // Escape analysis. - Escflowsrc *NodeList // flow(this, src) - Escretval *NodeList // on OCALLxxx, list of dummy return values - Escloopdepth int32 // -1: global, 0: return variables, 1:function top level, increased inside function for every loop or label to mark scopes + Escflowsrc *NodeList // flow(this, src) + Escretval *NodeList // on OCALLxxx, list of dummy return values + + Sym *Sym // various + + Opt interface{} // for optimization passes + + // OLITERAL + Val Val - Sym *Sym // various - Vargen int32 // unique name for OTYPE/ONAME within a function. Function outputs are numbered starting at one. - Lineno int32 Xoffset int64 Stkdelta int64 // offset added by stack frame compaction phase. - Ostk uint8 // 6g only - Iota int32 - Walkgen uint32 + + // Escape analysis. + Escloopdepth int32 // -1: global, 0: return variables, 1:function top level, increased inside function for every loop or label to mark scopes + + Vargen int32 // unique name for OTYPE/ONAME within a function. Function outputs are numbered starting at one. + Lineno int32 + Iota int32 + Walkgen uint32 + + Funcdepth int32 + + // OREGISTER, OINDREG + Reg int16 + + Top TypecheckCtxt // top context (Ecall, Eproc, etc) in ONAME closure param with PPARAMREF + Esclevel Level - Opt interface{} // for optimization passes + Esc uint16 // EscXXX + + Op uint8 + Nointerface bool + Ullman uint8 // sethi/ullman number + Addable bool // addressable + Etype uint8 // op for OASOP, etype for OTYPE, exclam for export + Bounded bool // bounds check unnecessary + Class uint8 // PPARAM, PAUTO, PEXTERN, etc + Embedded uint8 // ODCLFIELD embedded type + Colas bool // OAS resulting from := + Diag uint8 // already printed error about this + Noescape bool // func arguments do not escape; TODO(rsc): move Noescape to Func struct (see CL 7360) + Walkdef uint8 + Typecheck uint8 + Local bool + Dodata uint8 + Initorder uint8 + Used bool + Isddd bool // is the argument variadic + Implicit bool + Addrtaken bool // address taken, even if not moved to heap + Assigned bool // is the variable ever assigned to + Likely int8 // likeliness of if statement + Hasbreak bool // has break statement + Ostk uint8 // 6g only } // Name holds Node fields used only by ONAME nodes.