mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
cmd/5g etc: mechanical cleanup
Run rsc.io/grind rev a26569f on C->Go conversions. The new change in grind is the inlining of goto targets. If code says 'goto x' and the block starting at label x is unreachable except through that goto and the code can be moved to where the goto is without changing the meaning of its variable names, grind does that move. Simlarly, a goto to a plain return statement turns into that return statement (even if there are other paths to the return statement). Combined, these remove many long-distance gotos, which in turn makes it possible to reduce the scope of more variable declarations. (Because gotos can't jump across declarations, the gotos were keeping the declarations from moving.) Checked bit-for-bit compatibility with toolstash + buildall. Reduces compiler runtime in html/template by about 12%. Change-Id: Id727c0bd7763a61aa22f3daa00aeb8fccbc057a3 Reviewed-on: https://go-review.googlesource.com/6472 Reviewed-by: Aram Hăvărneanu <aram@mgk.ro> Reviewed-by: Dmitry Vyukov <dvyukov@google.com>
This commit is contained in:
parent
190357d560
commit
79f727a70e
67 changed files with 4118 additions and 5445 deletions
|
|
@ -533,21 +533,18 @@ func isliteral(n *Node) bool {
|
|||
|
||||
func simplename(n *Node) bool {
|
||||
if n.Op != ONAME {
|
||||
goto no
|
||||
return false
|
||||
}
|
||||
if n.Addable == 0 {
|
||||
goto no
|
||||
return false
|
||||
}
|
||||
if n.Class&PHEAP != 0 {
|
||||
goto no
|
||||
return false
|
||||
}
|
||||
if n.Class == PPARAMREF {
|
||||
goto no
|
||||
return false
|
||||
}
|
||||
return true
|
||||
|
||||
no:
|
||||
return false
|
||||
}
|
||||
|
||||
func litas(l *Node, r *Node, init **NodeList) {
|
||||
|
|
@ -1191,48 +1188,48 @@ func anylit(ctxt int, n *Node, var_ *Node, init **NodeList) {
|
|||
}
|
||||
|
||||
func oaslit(n *Node, init **NodeList) bool {
|
||||
var ctxt int
|
||||
|
||||
if n.Left == nil || n.Right == nil {
|
||||
goto no
|
||||
// not a special composit literal assignment
|
||||
return false
|
||||
}
|
||||
if n.Left.Type == nil || n.Right.Type == nil {
|
||||
goto no
|
||||
// not a special composit literal assignment
|
||||
return false
|
||||
}
|
||||
if !simplename(n.Left) {
|
||||
goto no
|
||||
// not a special composit literal assignment
|
||||
return false
|
||||
}
|
||||
if !Eqtype(n.Left.Type, n.Right.Type) {
|
||||
goto no
|
||||
// not a special composit literal assignment
|
||||
return false
|
||||
}
|
||||
|
||||
// context is init() function.
|
||||
// implies generated data executed
|
||||
// exactly once and not subject to races.
|
||||
ctxt = 0
|
||||
ctxt := 0
|
||||
|
||||
// if(n->dodata == 1)
|
||||
// ctxt = 1;
|
||||
|
||||
switch n.Right.Op {
|
||||
default:
|
||||
goto no
|
||||
// not a special composit literal assignment
|
||||
return false
|
||||
|
||||
case OSTRUCTLIT,
|
||||
OARRAYLIT,
|
||||
OMAPLIT:
|
||||
if vmatch1(n.Left, n.Right) {
|
||||
goto no
|
||||
// not a special composit literal assignment
|
||||
return false
|
||||
}
|
||||
anylit(ctxt, n.Right, n.Left, init)
|
||||
}
|
||||
|
||||
n.Op = OEMPTY
|
||||
return true
|
||||
|
||||
// not a special composit literal assignment
|
||||
no:
|
||||
return false
|
||||
}
|
||||
|
||||
func getlit(lit *Node) int {
|
||||
|
|
@ -1244,7 +1241,7 @@ func getlit(lit *Node) int {
|
|||
|
||||
func stataddr(nam *Node, n *Node) bool {
|
||||
if n == nil {
|
||||
goto no
|
||||
return false
|
||||
}
|
||||
|
||||
switch n.Op {
|
||||
|
|
@ -1281,7 +1278,6 @@ func stataddr(nam *Node, n *Node) bool {
|
|||
return true
|
||||
}
|
||||
|
||||
no:
|
||||
return false
|
||||
}
|
||||
|
||||
|
|
@ -1420,7 +1416,6 @@ func gen_as_init(n *Node) bool {
|
|||
var nr *Node
|
||||
var nl *Node
|
||||
var nam Node
|
||||
var nod1 Node
|
||||
|
||||
if n.Dodata == 0 {
|
||||
goto no
|
||||
|
|
@ -1436,7 +1431,7 @@ func gen_as_init(n *Node) bool {
|
|||
if nam.Class != PEXTERN {
|
||||
goto no
|
||||
}
|
||||
goto yes
|
||||
return true
|
||||
}
|
||||
|
||||
if nr.Type == nil || !Eqtype(nl.Type, nr.Type) {
|
||||
|
|
@ -1466,7 +1461,33 @@ func gen_as_init(n *Node) bool {
|
|||
case OSLICEARR:
|
||||
if nr.Right.Op == OKEY && nr.Right.Left == nil && nr.Right.Right == nil {
|
||||
nr = nr.Left
|
||||
goto slice
|
||||
gused(nil) // in case the data is the dest of a goto
|
||||
nl := nr
|
||||
if nr == nil || nr.Op != OADDR {
|
||||
goto no
|
||||
}
|
||||
nr = nr.Left
|
||||
if nr == nil || nr.Op != ONAME {
|
||||
goto no
|
||||
}
|
||||
|
||||
// nr is the array being converted to a slice
|
||||
if nr.Type == nil || nr.Type.Etype != TARRAY || nr.Type.Bound < 0 {
|
||||
goto no
|
||||
}
|
||||
|
||||
nam.Xoffset += int64(Array_array)
|
||||
gdata(&nam, nl, int(Types[Tptr].Width))
|
||||
|
||||
nam.Xoffset += int64(Array_nel) - int64(Array_array)
|
||||
var nod1 Node
|
||||
Nodconst(&nod1, Types[TINT], nr.Type.Bound)
|
||||
gdata(&nam, &nod1, Widthint)
|
||||
|
||||
nam.Xoffset += int64(Array_cap) - int64(Array_nel)
|
||||
gdata(&nam, &nod1, Widthint)
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
goto no
|
||||
|
|
@ -1505,37 +1526,8 @@ func gen_as_init(n *Node) bool {
|
|||
gdatastring(&nam, nr.Val.U.Sval)
|
||||
}
|
||||
|
||||
yes:
|
||||
return true
|
||||
|
||||
slice:
|
||||
gused(nil) // in case the data is the dest of a goto
|
||||
nl = nr
|
||||
if nr == nil || nr.Op != OADDR {
|
||||
goto no
|
||||
}
|
||||
nr = nr.Left
|
||||
if nr == nil || nr.Op != ONAME {
|
||||
goto no
|
||||
}
|
||||
|
||||
// nr is the array being converted to a slice
|
||||
if nr.Type == nil || nr.Type.Etype != TARRAY || nr.Type.Bound < 0 {
|
||||
goto no
|
||||
}
|
||||
|
||||
nam.Xoffset += int64(Array_array)
|
||||
gdata(&nam, nl, int(Types[Tptr].Width))
|
||||
|
||||
nam.Xoffset += int64(Array_nel) - int64(Array_array)
|
||||
Nodconst(&nod1, Types[TINT], nr.Type.Bound)
|
||||
gdata(&nam, &nod1, Widthint)
|
||||
|
||||
nam.Xoffset += int64(Array_cap) - int64(Array_nel)
|
||||
gdata(&nam, &nod1, Widthint)
|
||||
|
||||
goto yes
|
||||
|
||||
no:
|
||||
if n.Dodata == 2 {
|
||||
Dump("\ngen_as_init", n)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue