mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
cmd/compile: simplify InitPlan
Passes toolstash -cmp. Change-Id: Iaa0d78c2552efb29e67f6c99c7287f8566027add Reviewed-on: https://go-review.googlesource.com/20673 Reviewed-by: Matthew Dempsky <mdempsky@google.com>
This commit is contained in:
parent
e59c1729ba
commit
7971864267
1 changed files with 9 additions and 26 deletions
|
|
@ -22,9 +22,6 @@ type InitEntry struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type InitPlan struct {
|
type InitPlan struct {
|
||||||
Lit int64
|
|
||||||
Zero int64
|
|
||||||
Expr int64
|
|
||||||
E []InitEntry
|
E []InitEntry
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1261,7 +1258,7 @@ func initplan(n *Node) {
|
||||||
if a.Op != OKEY || !Smallintconst(a.Left) {
|
if a.Op != OKEY || !Smallintconst(a.Left) {
|
||||||
Fatalf("initplan arraylit")
|
Fatalf("initplan arraylit")
|
||||||
}
|
}
|
||||||
addvalue(p, n.Type.Type.Width*Mpgetfix(a.Left.Val().U.(*Mpint)), nil, a.Right)
|
addvalue(p, n.Type.Type.Width*Mpgetfix(a.Left.Val().U.(*Mpint)), a.Right)
|
||||||
}
|
}
|
||||||
|
|
||||||
case OSTRUCTLIT:
|
case OSTRUCTLIT:
|
||||||
|
|
@ -1269,7 +1266,7 @@ func initplan(n *Node) {
|
||||||
if a.Op != OKEY || a.Left.Type == nil {
|
if a.Op != OKEY || a.Left.Type == nil {
|
||||||
Fatalf("initplan structlit")
|
Fatalf("initplan structlit")
|
||||||
}
|
}
|
||||||
addvalue(p, a.Left.Type.Width, nil, a.Right)
|
addvalue(p, a.Left.Type.Width, a.Right)
|
||||||
}
|
}
|
||||||
|
|
||||||
case OMAPLIT:
|
case OMAPLIT:
|
||||||
|
|
@ -1277,15 +1274,14 @@ func initplan(n *Node) {
|
||||||
if a.Op != OKEY {
|
if a.Op != OKEY {
|
||||||
Fatalf("initplan maplit")
|
Fatalf("initplan maplit")
|
||||||
}
|
}
|
||||||
addvalue(p, -1, a.Left, a.Right)
|
addvalue(p, -1, a.Right)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func addvalue(p *InitPlan, xoffset int64, key *Node, n *Node) {
|
func addvalue(p *InitPlan, xoffset int64, n *Node) {
|
||||||
// special case: zero can be dropped entirely
|
// special case: zero can be dropped entirely
|
||||||
if iszero(n) {
|
if iszero(n) {
|
||||||
p.Zero += n.Type.Width
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1294,23 +1290,15 @@ func addvalue(p *InitPlan, xoffset int64, key *Node, n *Node) {
|
||||||
initplan(n)
|
initplan(n)
|
||||||
q := initplans[n]
|
q := initplans[n]
|
||||||
for _, qe := range q.E {
|
for _, qe := range q.E {
|
||||||
e := entry(p)
|
// qe is a copy; we are not modifying entries in q.E
|
||||||
*e = qe
|
qe.Xoffset += xoffset
|
||||||
e.Xoffset += xoffset
|
p.E = append(p.E, qe)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// add to plan
|
// add to plan
|
||||||
if n.Op == OLITERAL {
|
p.E = append(p.E, InitEntry{Xoffset: xoffset, Expr: n})
|
||||||
p.Lit += n.Type.Width
|
|
||||||
} else {
|
|
||||||
p.Expr += n.Type.Width
|
|
||||||
}
|
|
||||||
|
|
||||||
e := entry(p)
|
|
||||||
e.Xoffset = xoffset
|
|
||||||
e.Expr = n
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func iszero(n *Node) bool {
|
func iszero(n *Node) bool {
|
||||||
|
|
@ -1363,11 +1351,6 @@ func isvaluelit(n *Node) bool {
|
||||||
return (n.Op == OARRAYLIT && Isfixedarray(n.Type)) || n.Op == OSTRUCTLIT
|
return (n.Op == OARRAYLIT && Isfixedarray(n.Type)) || n.Op == OSTRUCTLIT
|
||||||
}
|
}
|
||||||
|
|
||||||
func entry(p *InitPlan) *InitEntry {
|
|
||||||
p.E = append(p.E, InitEntry{})
|
|
||||||
return &p.E[len(p.E)-1]
|
|
||||||
}
|
|
||||||
|
|
||||||
// gen_as_init attempts to emit static data for n and reports whether it succeeded.
|
// gen_as_init attempts to emit static data for n and reports whether it succeeded.
|
||||||
// If reportOnly is true, it does not emit static data and does not modify the AST.
|
// If reportOnly is true, it does not emit static data and does not modify the AST.
|
||||||
func gen_as_init(n *Node, reportOnly bool) bool {
|
func gen_as_init(n *Node, reportOnly bool) bool {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue