cmd/compile: move Node.Walkdef into flags

Node.Walkdef is 0, 1, or 2, so it only requires two bits.
Add support for 2-bit values to bitset,
and use it for Node.Walkdef.

Class, Embedded, Typecheck, and Initorder will follow suit
in subsequent CLs.

The multi-bit flags will go at the beginning,
since that generates (marginally) more efficient code.

Change-Id: Id6e2e66e437f10aaa05b8a6e1652efb327d06128
Reviewed-on: https://go-review.googlesource.com/41791
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
This commit is contained in:
Josh Bleecher Snyder 2017-04-25 17:30:08 -07:00
parent 804784c8ba
commit d286399641
4 changed files with 43 additions and 27 deletions

View file

@ -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
Class Class // PPARAM, PAUTO, PEXTERN, etc
Embedded uint8 // ODCLFIELD embedded type
Walkdef uint8 // tracks state during typecheckdef; 2 == loop detected
Typecheck uint8 // tracks state during typechecking; 2 == loop detected
Initorder uint8
}
@ -74,28 +73,32 @@ func (n *Node) IsAutoTmp() bool {
}
const (
nodeHasBreak = 1 << iota
nodeIsClosureVar
nodeIsOutputParamHeapAddr
nodeNoInline // used internally by inliner to indicate that a function call should not be inlined; set for OCALLFUNC and OCALLMETH only
nodeAssigned // is the variable ever assigned to
nodeAddrtaken // address taken, even if not moved to heap
nodeImplicit
nodeIsddd // is the argument variadic
nodeLocal // type created in this file (see also Type.Local)
nodeDiag // already printed error about this
nodeColas // OAS resulting from :=
nodeNonNil // guaranteed to be non-nil
nodeNoescape // func arguments do not escape; TODO(rsc): move Noescape to Func struct (see CL 7360)
nodeBounded // bounds check unnecessary
nodeAddable // addressable
nodeUsed // for variable/label declared and not used error
nodeHasCall // expression contains a function call
nodeLikely // if statement condition likely
nodeHasVal // node.E contains a Val
nodeHasOpt // node.E contains an Opt
nodeWalkdef, _ = iota, 1 << iota // tracks state during typecheckdef; 2 == loop detected; two bits
_, _ // second nodeWalkdef bit
_, nodeHasBreak
_, nodeIsClosureVar
_, nodeIsOutputParamHeapAddr
_, nodeNoInline // used internally by inliner to indicate that a function call should not be inlined; set for OCALLFUNC and OCALLMETH only
_, nodeAssigned // is the variable ever assigned to
_, nodeAddrtaken // address taken, even if not moved to heap
_, nodeImplicit
_, nodeIsddd // is the argument variadic
_, nodeLocal // type created in this file (see also Type.Local)
_, nodeDiag // already printed error about this
_, nodeColas // OAS resulting from :=
_, nodeNonNil // guaranteed to be non-nil
_, nodeNoescape // func arguments do not escape; TODO(rsc): move Noescape to Func struct (see CL 7360)
_, nodeBounded // bounds check unnecessary
_, nodeAddable // addressable
_, nodeUsed // for variable/label declared and not used error
_, nodeHasCall // expression contains a function call
_, nodeLikely // if statement condition likely
_, nodeHasVal // node.E contains a Val
_, nodeHasOpt // node.E contains an Opt
)
func (n *Node) Walkdef() uint8 { return n.flags.get2(nodeWalkdef) }
func (n *Node) HasBreak() bool { return n.flags&nodeHasBreak != 0 }
func (n *Node) IsClosureVar() bool { return n.flags&nodeIsClosureVar != 0 }
func (n *Node) NoInline() bool { return n.flags&nodeNoInline != 0 }
@ -117,6 +120,8 @@ func (n *Node) Likely() bool { return n.flags&nodeLikely != 0 }
func (n *Node) HasVal() bool { return n.flags&nodeHasVal != 0 }
func (n *Node) HasOpt() bool { return n.flags&nodeHasOpt != 0 }
func (n *Node) SetWalkdef(b uint8) { n.flags.set2(nodeWalkdef, 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) SetNoInline(b bool) { n.flags.set(nodeNoInline, b) }