cmd/compile: fix Node.Etype overloading

Add helper methods that validate n.Op and convert to/from the
appropriate type.

Notably, there was a lot of code in walk.go that thought setting
Etype=1 on an OADDR node affected escape analysis.

Passes toolstash-check.

TBR=marvin

Change-Id: Ieae7c67225c1459c9719f9e6a748a25b975cf758
Reviewed-on: https://go-review.googlesource.com/99535
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
This commit is contained in:
Matthew Dempsky 2018-03-08 04:18:18 -08:00
parent 91102bf723
commit e4de522c95
11 changed files with 98 additions and 72 deletions

View file

@ -55,8 +55,62 @@ type Node struct {
Esc uint16 // EscXXX
Op Op
Etype types.EType // op for OASOP, etype for OTYPE, exclam for export, 6g saved reg, ChanDir for OTCHAN, for OINDEXMAP 1=LHS,0=RHS
Op Op
aux uint8
}
func (n *Node) ResetAux() {
n.aux = 0
}
func (n *Node) SubOp() Op {
switch n.Op {
case OASOP, OCMPIFACE, OCMPSTR, ONAME:
default:
Fatalf("unexpected op: %v", n.Op)
}
return Op(n.aux)
}
func (n *Node) SetSubOp(op Op) {
switch n.Op {
case OASOP, OCMPIFACE, OCMPSTR, ONAME:
default:
Fatalf("unexpected op: %v", n.Op)
}
n.aux = uint8(op)
}
func (n *Node) IndexMapLValue() bool {
if n.Op != OINDEXMAP {
Fatalf("unexpected op: %v", n.Op)
}
return n.aux != 0
}
func (n *Node) SetIndexMapLValue(b bool) {
if n.Op != OINDEXMAP {
Fatalf("unexpected op: %v", n.Op)
}
if b {
n.aux = 1
} else {
n.aux = 0
}
}
func (n *Node) TChanDir() types.ChanDir {
if n.Op != OTCHAN {
Fatalf("unexpected op: %v", n.Op)
}
return types.ChanDir(n.aux)
}
func (n *Node) SetTChanDir(dir types.ChanDir) {
if n.Op != OTCHAN {
Fatalf("unexpected op: %v", n.Op)
}
n.aux = uint8(dir)
}
func (n *Node) IsSynthetic() bool {