Commit e2560ace authored by Josh Bleecher Snyder's avatar Josh Bleecher Snyder

cmd/compile: move Node.Initorder to flags

Grand savings: 6 bits.

Change-Id: I364be54cc41534689e01672ed0fe2c10a560d3d4
Reviewed-on: https://go-review.googlesource.com/41794
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
Reviewed-by: default avatarBrad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
parent af7da9a5
...@@ -55,7 +55,7 @@ func init1(n *Node, out *[]*Node) { ...@@ -55,7 +55,7 @@ func init1(n *Node, out *[]*Node) {
switch n.Class { switch n.Class {
case PEXTERN, PFUNC: case PEXTERN, PFUNC:
default: default:
if isblank(n) && n.Name.Curfn == nil && n.Name.Defn != nil && n.Name.Defn.Initorder == InitNotStarted { if isblank(n) && n.Name.Curfn == nil && n.Name.Defn != nil && n.Name.Defn.Initorder() == InitNotStarted {
// blank names initialization is part of init() but not // blank names initialization is part of init() but not
// when they are inside a function. // when they are inside a function.
break break
...@@ -63,10 +63,10 @@ func init1(n *Node, out *[]*Node) { ...@@ -63,10 +63,10 @@ func init1(n *Node, out *[]*Node) {
return return
} }
if n.Initorder == InitDone { if n.Initorder() == InitDone {
return return
} }
if n.Initorder == InitPending { if n.Initorder() == InitPending {
// Since mutually recursive sets of functions are allowed, // Since mutually recursive sets of functions are allowed,
// we don't necessarily raise an error if n depends on a node // we don't necessarily raise an error if n depends on a node
// which is already waiting for its dependencies to be visited. // which is already waiting for its dependencies to be visited.
...@@ -95,7 +95,7 @@ func init1(n *Node, out *[]*Node) { ...@@ -95,7 +95,7 @@ func init1(n *Node, out *[]*Node) {
} }
// reached a new unvisited node. // reached a new unvisited node.
n.Initorder = InitPending n.SetInitorder(InitPending)
initlist = append(initlist, n) initlist = append(initlist, n)
// make sure that everything n depends on is initialized. // make sure that everything n depends on is initialized.
...@@ -133,10 +133,10 @@ func init1(n *Node, out *[]*Node) { ...@@ -133,10 +133,10 @@ func init1(n *Node, out *[]*Node) {
} }
case OAS2FUNC, OAS2MAPR, OAS2DOTTYPE, OAS2RECV: case OAS2FUNC, OAS2MAPR, OAS2DOTTYPE, OAS2RECV:
if defn.Initorder == InitDone { if defn.Initorder() == InitDone {
break break
} }
defn.Initorder = InitPending defn.SetInitorder(InitPending)
for _, n2 := range defn.Rlist.Slice() { for _, n2 := range defn.Rlist.Slice() {
init1(n2, out) init1(n2, out)
} }
...@@ -144,7 +144,7 @@ func init1(n *Node, out *[]*Node) { ...@@ -144,7 +144,7 @@ func init1(n *Node, out *[]*Node) {
Dump("nonstatic", defn) Dump("nonstatic", defn)
} }
*out = append(*out, defn) *out = append(*out, defn)
defn.Initorder = InitDone defn.SetInitorder(InitDone)
} }
} }
...@@ -155,7 +155,7 @@ func init1(n *Node, out *[]*Node) { ...@@ -155,7 +155,7 @@ func init1(n *Node, out *[]*Node) {
initlist[last] = nil // allow GC initlist[last] = nil // allow GC
initlist = initlist[:last] initlist = initlist[:last]
n.Initorder = InitDone n.SetInitorder(InitDone)
return return
} }
...@@ -197,7 +197,7 @@ func foundinitloop(node, visited *Node) { ...@@ -197,7 +197,7 @@ func foundinitloop(node, visited *Node) {
// recurse over n, doing init1 everywhere. // recurse over n, doing init1 everywhere.
func init2(n *Node, out *[]*Node) { func init2(n *Node, out *[]*Node) {
if n == nil || n.Initorder == InitDone { if n == nil || n.Initorder() == InitDone {
return return
} }
......
...@@ -59,7 +59,6 @@ type Node struct { ...@@ -59,7 +59,6 @@ type Node struct {
Etype types.EType // op for OASOP, etype for OTYPE, exclam for export, 6g saved reg, ChanDir for OTCHAN, for OINDEXMAP 1=LHS,0=RHS Etype types.EType // op for OASOP, etype for OTYPE, exclam for export, 6g saved reg, ChanDir for OTCHAN, for OINDEXMAP 1=LHS,0=RHS
Class Class // PPARAM, PAUTO, PEXTERN, etc Class Class // PPARAM, PAUTO, PEXTERN, etc
Typecheck uint8 // tracks state during typechecking; 2 == loop detected Typecheck uint8 // tracks state during typechecking; 2 == loop detected
Initorder uint8
} }
// IsAutoTmp indicates if n was created by the compiler as a temporary, // IsAutoTmp indicates if n was created by the compiler as a temporary,
...@@ -74,6 +73,8 @@ func (n *Node) IsAutoTmp() bool { ...@@ -74,6 +73,8 @@ func (n *Node) IsAutoTmp() bool {
const ( const (
nodeWalkdef, _ = iota, 1 << iota // tracks state during typecheckdef; 2 == loop detected; two bits nodeWalkdef, _ = iota, 1 << iota // tracks state during typecheckdef; 2 == loop detected; two bits
_, _ // second nodeWalkdef bit _, _ // second nodeWalkdef bit
nodeInitorder, _ // tracks state during init1; two bits
_, _ // second nodeInitorder bit
_, nodeHasBreak _, nodeHasBreak
_, nodeIsClosureVar _, nodeIsClosureVar
_, nodeIsOutputParamHeapAddr _, nodeIsOutputParamHeapAddr
...@@ -98,6 +99,7 @@ const ( ...@@ -98,6 +99,7 @@ const (
) )
func (n *Node) Walkdef() uint8 { return n.flags.get2(nodeWalkdef) } func (n *Node) Walkdef() uint8 { return n.flags.get2(nodeWalkdef) }
func (n *Node) Initorder() uint8 { return n.flags.get2(nodeInitorder) }
func (n *Node) HasBreak() bool { return n.flags&nodeHasBreak != 0 } func (n *Node) HasBreak() bool { return n.flags&nodeHasBreak != 0 }
func (n *Node) IsClosureVar() bool { return n.flags&nodeIsClosureVar != 0 } func (n *Node) IsClosureVar() bool { return n.flags&nodeIsClosureVar != 0 }
...@@ -122,6 +124,7 @@ func (n *Node) HasOpt() bool { return n.flags&nodeHasOpt != 0 } ...@@ -122,6 +124,7 @@ func (n *Node) HasOpt() bool { return n.flags&nodeHasOpt != 0 }
func (n *Node) Embedded() bool { return n.flags&nodeEmbedded != 0 } func (n *Node) Embedded() bool { return n.flags&nodeEmbedded != 0 }
func (n *Node) SetWalkdef(b uint8) { n.flags.set2(nodeWalkdef, b) } func (n *Node) SetWalkdef(b uint8) { n.flags.set2(nodeWalkdef, b) }
func (n *Node) SetInitorder(b uint8) { n.flags.set2(nodeInitorder, b) }
func (n *Node) SetHasBreak(b bool) { n.flags.set(nodeHasBreak, b) } func (n *Node) SetHasBreak(b bool) { n.flags.set(nodeHasBreak, b) }
func (n *Node) SetIsClosureVar(b bool) { n.flags.set(nodeIsClosureVar, b) } func (n *Node) SetIsClosureVar(b bool) { n.flags.set(nodeIsClosureVar, b) }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment