mirror of
https://github.com/golang/go
synced 2024-11-18 09:04:49 -07:00
cmd/compile: cleanups for Node trimming sequence
Suggested during code reviews of last 15 CLs (or so). Change-Id: If780f6eb47a7a31df133c64d5dcf0eaf04d8447b Reviewed-on: https://go-review.googlesource.com/10675 Reviewed-by: Ian Lance Taylor <iant@golang.org> Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com>
This commit is contained in:
parent
ca19e55f9a
commit
a53710ffcb
@ -72,7 +72,7 @@ func closurebody(body *NodeList) *Node {
|
|||||||
var v *Node
|
var v *Node
|
||||||
for l := func_.Func.Cvars; l != nil; l = l.Next {
|
for l := func_.Func.Cvars; l != nil; l = l.Next {
|
||||||
v = l.N
|
v = l.N
|
||||||
v.Name.Param.Closure.Name.Closure = v.Name.Outer
|
v.Name.Param.Closure.Name.Param.Closure = v.Name.Param.Outer
|
||||||
v.Name.Param.Outerexpr = oldname(v.Sym)
|
v.Name.Param.Outerexpr = oldname(v.Sym)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -411,7 +411,7 @@ type EscState struct {
|
|||||||
walkgen uint32
|
walkgen uint32
|
||||||
}
|
}
|
||||||
|
|
||||||
// funcSym returns n.Nname.Sym if no nils are encountered along the way.
|
// funcSym returns fn.Func.Nname.Sym if no nils are encountered along the way.
|
||||||
func funcSym(fn *Node) *Sym {
|
func funcSym(fn *Node) *Sym {
|
||||||
if fn == nil || fn.Func.Nname == nil {
|
if fn == nil || fn.Func.Nname == nil {
|
||||||
return nil
|
return nil
|
||||||
@ -1238,7 +1238,14 @@ func escassignfromtag(e *EscState, note *string, dsts *NodeList, src *Node) uint
|
|||||||
return em0
|
return em0
|
||||||
}
|
}
|
||||||
|
|
||||||
// e.addDereference constructs a suitable OIND note applied to src.
|
func escassignDereference(e *EscState, dst *Node, src *Node) {
|
||||||
|
if src.Op == OLITERAL {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
escassign(e, dst, e.addDereference(src))
|
||||||
|
}
|
||||||
|
|
||||||
|
// addDereference constructs a suitable OIND note applied to src.
|
||||||
// Because this is for purposes of escape accounting, not execution,
|
// Because this is for purposes of escape accounting, not execution,
|
||||||
// some semantically dubious node combinations are (currently) possible.
|
// some semantically dubious node combinations are (currently) possible.
|
||||||
func (e *EscState) addDereference(n *Node) *Node {
|
func (e *EscState) addDereference(n *Node) *Node {
|
||||||
|
@ -236,6 +236,9 @@ func Jconv(n *Node, flag int) string {
|
|||||||
if n.Name != nil && n.Name.Funcdepth != 0 {
|
if n.Name != nil && n.Name.Funcdepth != 0 {
|
||||||
fmt.Fprintf(&buf, " f(%d)", n.Name.Funcdepth)
|
fmt.Fprintf(&buf, " f(%d)", n.Name.Funcdepth)
|
||||||
}
|
}
|
||||||
|
if n.Func != nil && n.Func.Depth != 0 {
|
||||||
|
fmt.Fprintf(&buf, " ff(%d)", n.Func.Depth)
|
||||||
|
}
|
||||||
|
|
||||||
switch n.Esc {
|
switch n.Esc {
|
||||||
case EscUnknown:
|
case EscUnknown:
|
||||||
|
@ -98,6 +98,9 @@ type NilVal struct{}
|
|||||||
func (v Val) Ctype() int {
|
func (v Val) Ctype() int {
|
||||||
switch x := v.U.(type) {
|
switch x := v.U.(type) {
|
||||||
default:
|
default:
|
||||||
|
Fatal("unexpected Ctype for %T", v.U)
|
||||||
|
panic("not reached")
|
||||||
|
case nil:
|
||||||
return 0
|
return 0
|
||||||
case *NilVal:
|
case *NilVal:
|
||||||
return CTNIL
|
return CTNIL
|
||||||
|
@ -18,9 +18,11 @@ const (
|
|||||||
InitPending = 2
|
InitPending = 2
|
||||||
)
|
)
|
||||||
|
|
||||||
var initlist *NodeList
|
var (
|
||||||
var initplans = make(map[*Node]*InitPlan)
|
initlist *NodeList
|
||||||
var inittemps = make(map[*Node]*Node)
|
initplans map[*Node]*InitPlan
|
||||||
|
inittemps = make(map[*Node]*Node)
|
||||||
|
)
|
||||||
|
|
||||||
// init1 walks the AST starting at n, and accumulates in out
|
// init1 walks the AST starting at n, and accumulates in out
|
||||||
// the list of definitions needing init code in dependency order.
|
// the list of definitions needing init code in dependency order.
|
||||||
@ -255,9 +257,11 @@ func initreorder(l *NodeList, out **NodeList) {
|
|||||||
// to include in the init() function body.
|
// to include in the init() function body.
|
||||||
func initfix(l *NodeList) *NodeList {
|
func initfix(l *NodeList) *NodeList {
|
||||||
var lout *NodeList
|
var lout *NodeList
|
||||||
|
initplans = make(map[*Node]*InitPlan)
|
||||||
lno := int(lineno)
|
lno := int(lineno)
|
||||||
initreorder(l, &lout)
|
initreorder(l, &lout)
|
||||||
lineno = int32(lno)
|
lineno = int32(lno)
|
||||||
|
initplans = nil
|
||||||
return lout
|
return lout
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -333,6 +333,7 @@ func importdot(opkg *Pkg, pack *Node) {
|
|||||||
s1.Block = s.Block
|
s1.Block = s.Block
|
||||||
if s1.Def.Name == nil {
|
if s1.Def.Name == nil {
|
||||||
Dump("s1def", s1.Def)
|
Dump("s1def", s1.Def)
|
||||||
|
Fatal("missing Name")
|
||||||
}
|
}
|
||||||
s1.Def.Name.Pack = pack
|
s1.Def.Name.Pack = pack
|
||||||
s1.Origpkg = opkg
|
s1.Origpkg = opkg
|
||||||
|
@ -280,7 +280,6 @@ func (s *exprSwitch) walk(sw *Node) {
|
|||||||
sw.Nbody = concat(cas, sw.Nbody)
|
sw.Nbody = concat(cas, sw.Nbody)
|
||||||
walkstmtlist(sw.Nbody)
|
walkstmtlist(sw.Nbody)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// walkCases generates an AST implementing the cases in cc.
|
// walkCases generates an AST implementing the cases in cc.
|
||||||
|
@ -73,15 +73,15 @@ type Node struct {
|
|||||||
|
|
||||||
// Name holds Node fields used only by named nodes (ONAME, OPACK, some OLITERAL).
|
// Name holds Node fields used only by named nodes (ONAME, OPACK, some OLITERAL).
|
||||||
type Name struct {
|
type Name struct {
|
||||||
Pack *Node // real package for import . names
|
Pack *Node // real package for import . names
|
||||||
Pkg *Pkg // pkg for OPACK nodes
|
Pkg *Pkg // pkg for OPACK nodes
|
||||||
Heapaddr *Node // temp holding heap address of param
|
Heapaddr *Node // temp holding heap address of param
|
||||||
Inlvar *Node // ONAME substitute while inlining
|
Inlvar *Node // ONAME substitute while inlining
|
||||||
Defn *Node // initializing assignment
|
Defn *Node // initializing assignment
|
||||||
Curfn *Node // function for local variables
|
Curfn *Node // function for local variables
|
||||||
*Param
|
Param *Param
|
||||||
Decldepth int32 // declaration loop depth, increased for every loop or label
|
Decldepth int32 // declaration loop depth, increased for every loop or label
|
||||||
Vargen int32 // unique name for OTYPE/ONAME within a function. Function outputs are numbered starting at one.
|
Vargen int32 // unique name for ONAME within a function. Function outputs are numbered starting at one.
|
||||||
Iota int32 // value if this name is iota
|
Iota int32 // value if this name is iota
|
||||||
Funcdepth int32
|
Funcdepth int32
|
||||||
Method bool // OCALLMETH name
|
Method bool // OCALLMETH name
|
||||||
|
@ -823,7 +823,7 @@ OpSwitch:
|
|||||||
}
|
}
|
||||||
l.Addrtaken = true
|
l.Addrtaken = true
|
||||||
if l.Name != nil && l.Name.Param != nil && l.Name.Param.Closure != nil {
|
if l.Name != nil && l.Name.Param != nil && l.Name.Param.Closure != nil {
|
||||||
l.Name.Closure.Addrtaken = true
|
l.Name.Param.Closure.Addrtaken = true
|
||||||
}
|
}
|
||||||
defaultlit(&n.Left, nil)
|
defaultlit(&n.Left, nil)
|
||||||
l = n.Left
|
l = n.Left
|
||||||
@ -2832,36 +2832,36 @@ func keydup(n *Node, hash map[uint32][]*Node) {
|
|||||||
return // we dont check variables
|
return // we dont check variables
|
||||||
}
|
}
|
||||||
|
|
||||||
var b uint32
|
var h uint32
|
||||||
switch n.Val.Ctype() {
|
switch n.Val.Ctype() {
|
||||||
default: // unknown, bool, nil
|
default: // unknown, bool, nil
|
||||||
b = 23
|
h = 23
|
||||||
|
|
||||||
case CTINT, CTRUNE:
|
case CTINT, CTRUNE:
|
||||||
b = uint32(Mpgetfix(n.Val.U.(*Mpint)))
|
h = uint32(Mpgetfix(n.Val.U.(*Mpint)))
|
||||||
|
|
||||||
case CTFLT:
|
case CTFLT:
|
||||||
d := mpgetflt(n.Val.U.(*Mpflt))
|
d := mpgetflt(n.Val.U.(*Mpflt))
|
||||||
x := math.Float64bits(d)
|
x := math.Float64bits(d)
|
||||||
for i := 0; i < 8; i++ {
|
for i := 0; i < 8; i++ {
|
||||||
b = b*PRIME1 + uint32(x&0xFF)
|
h = h*PRIME1 + uint32(x&0xFF)
|
||||||
x >>= 8
|
x >>= 8
|
||||||
}
|
}
|
||||||
|
|
||||||
case CTSTR:
|
case CTSTR:
|
||||||
b = 0
|
h = 0
|
||||||
s := n.Val.U.(string)
|
s := n.Val.U.(string)
|
||||||
for i := len(n.Val.U.(string)); i > 0; i-- {
|
for i := len(n.Val.U.(string)); i > 0; i-- {
|
||||||
b = b*PRIME1 + uint32(s[0])
|
h = h*PRIME1 + uint32(s[0])
|
||||||
s = s[1:]
|
s = s[1:]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var cmp Node
|
var cmp Node
|
||||||
for _, a := range hash[b] {
|
for _, a := range hash[h] {
|
||||||
cmp.Op = OEQ
|
cmp.Op = OEQ
|
||||||
cmp.Left = n
|
cmp.Left = n
|
||||||
b = 0
|
b := uint32(0)
|
||||||
if a.Op == OCONVIFACE && orign.Op == OCONVIFACE {
|
if a.Op == OCONVIFACE && orign.Op == OCONVIFACE {
|
||||||
if Eqtype(a.Left.Type, n.Type) {
|
if Eqtype(a.Left.Type, n.Type) {
|
||||||
cmp.Right = a.Left
|
cmp.Right = a.Left
|
||||||
@ -2880,7 +2880,7 @@ func keydup(n *Node, hash map[uint32][]*Node) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
hash[b] = append(hash[b], orign)
|
hash[h] = append(hash[h], orign)
|
||||||
}
|
}
|
||||||
|
|
||||||
func indexdup(n *Node, hash map[int64]*Node) {
|
func indexdup(n *Node, hash map[int64]*Node) {
|
||||||
@ -3936,7 +3936,7 @@ func markbreaklist(l *NodeList, implicit *Node) {
|
|||||||
lab = new(Label)
|
lab = new(Label)
|
||||||
lab.Def = n.Name.Defn
|
lab.Def = n.Name.Defn
|
||||||
n.Left.Sym.Label = lab
|
n.Left.Sym.Label = lab
|
||||||
markbreak(n.Name.Defn, n.Name.Defn) // XXX
|
markbreak(n.Name.Defn, n.Name.Defn)
|
||||||
n.Left.Sym.Label = nil
|
n.Left.Sym.Label = nil
|
||||||
l = l.Next
|
l = l.Next
|
||||||
continue
|
continue
|
||||||
|
Loading…
Reference in New Issue
Block a user