1
0
mirror of https://github.com/golang/go synced 2024-11-18 16:54:43 -07:00

cmd/compile/internal/gc: remove Node.IsStatic field

We can immediately emit static assignment data rather than queueing
them up to be processed during SSA building.

Passes toolstash -cmp.

Change-Id: I8bcea4b72eafb0cc0b849cd93e9cde9d84f30d5e
Reviewed-on: https://go-review.googlesource.com/37024
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com>
This commit is contained in:
Matthew Dempsky 2017-02-15 21:16:49 -08:00
parent 3557d54609
commit c61cf5e6b7
5 changed files with 26 additions and 97 deletions

View File

@ -335,10 +335,6 @@ func (n *Node) jconv(s fmt.State, flag FmtFlag) {
fmt.Fprintf(s, " tc(%d)", n.Typecheck)
}
if c == 0 && n.IsStatic {
fmt.Fprint(s, " static")
}
if n.Isddd {
fmt.Fprintf(s, " isddd(%v)", n.Isddd)
}

View File

@ -751,19 +751,15 @@ func fixedlit(ctxt initContext, kind initKind, n *Node, var_ *Node, init *Nodes)
a = typecheck(a, Etop)
switch kind {
case initKindStatic:
a = walkexpr(a, init) // add any assignments in r to top
if a.Op != OAS {
Fatalf("fixedlit: not as, is %v", a)
}
a.IsStatic = true
genAsStatic(a)
case initKindDynamic, initKindLocalCode:
a = orderstmtinplace(a)
a = walkstmt(a)
init.Append(a)
default:
Fatalf("fixedlit: bad kind %d", kind)
}
init.Append(a)
}
}
@ -780,12 +776,22 @@ func slicelit(ctxt initContext, n *Node, var_ *Node, init *Nodes) {
fixedlit(ctxt, initKindDynamic, n, vstat, init)
// copy static to slice
a := nod(OSLICE, vstat, nil)
var_ = typecheck(var_, Erv|Easgn)
var nam Node
if !stataddr(&nam, var_) || nam.Class != PEXTERN {
Fatalf("slicelit: %v", var_)
}
var v Node
nodconst(&v, Types[TINT], t.NumElem())
nam.Xoffset += int64(array_array)
gdata(&nam, nod(OADDR, vstat, nil), Widthptr)
nam.Xoffset += int64(array_nel) - int64(array_array)
gdata(&nam, &v, Widthint)
nam.Xoffset += int64(array_cap) - int64(array_nel)
gdata(&nam, &v, Widthint)
a = nod(OAS, var_, a)
a = typecheck(a, Etop)
a.IsStatic = true
init.Append(a)
return
}
@ -964,18 +970,14 @@ func maplit(n *Node, m *Node, init *Nodes) {
lhs := nod(OINDEX, vstatk, nodintconst(b))
as := nod(OAS, lhs, index)
as = typecheck(as, Etop)
as = walkexpr(as, init)
as.IsStatic = true
init.Append(as)
genAsStatic(as)
// build vstatv[b] = value
setlineno(value)
lhs = nod(OINDEX, vstatv, nodintconst(b))
as = nod(OAS, lhs, value)
as = typecheck(as, Etop)
as = walkexpr(as, init)
as.IsStatic = true
init.Append(as)
genAsStatic(as)
b++
}
@ -1344,69 +1346,15 @@ func isvaluelit(n *Node) bool {
return n.Op == OARRAYLIT || n.Op == OSTRUCTLIT
}
func genAsInitNoCheck(n *Node) bool {
nr := n.Right
nl := n.Left
if nr == nil {
var nam Node
return stataddr(&nam, nl) && nam.Class == PEXTERN
}
if nr.Type == nil || !eqtype(nl.Type, nr.Type) {
return false
}
func genAsStatic(as *Node) {
var nam Node
if !stataddr(&nam, nl) || nam.Class != PEXTERN {
return false
if !stataddr(&nam, as.Left) || nam.Class != PEXTERN {
Fatalf("genAsStatic: lhs %v", as.Left)
}
switch nr.Op {
default:
return false
case OCONVNOP:
nr = nr.Left
if nr == nil || nr.Op != OSLICEARR {
return false
}
fallthrough
case OSLICEARR:
low, high, _ := nr.SliceBounds()
if low != nil || high != nil {
return false
}
nr = nr.Left
if nr == nil || nr.Op != OADDR {
return false
}
ptr := nr
nr = nr.Left
if nr == nil || nr.Op != ONAME {
return false
}
// nr is the array being converted to a slice
if nr.Type == nil || !nr.Type.IsArray() {
return false
}
nam.Xoffset += int64(array_array)
gdata(&nam, ptr, Widthptr)
nam.Xoffset += int64(array_nel) - int64(array_array)
var nod1 Node
nodconst(&nod1, Types[TINT], nr.Type.NumElem())
gdata(&nam, &nod1, Widthint)
nam.Xoffset += int64(array_cap) - int64(array_nel)
gdata(&nam, &nod1, Widthint)
return true
case OLITERAL:
gdata(&nam, nr, int(nr.Type.Width))
return true
if as.Right.Op != OLITERAL {
Fatalf("genAsStatic: rhs %v", as.Right)
}
gdata(&nam, as.Right, int(as.Right.Type.Width))
}

View File

@ -630,15 +630,6 @@ func (s *state) stmt(n *Node) {
b.AddEdgeTo(lab.target)
case OAS:
// Generate static data rather than code, if possible.
if n.IsStatic {
if !genAsInitNoCheck(n) {
Dump("\ngen_as_init", n)
Fatalf("gen_as_init couldn't generate static data")
}
return
}
if n.Left == n.Right && n.Left.Op == ONAME {
// An x=x assignment. No point in doing anything
// here. In addition, skipping this assignment

View File

@ -65,7 +65,6 @@ type Node struct {
Walkdef uint8 // tracks state during typecheckdef; 2 == loop detected
Typecheck uint8 // tracks state during typechecking; 2 == loop detected
Local bool // type created in this file (see also Type.Local); TODO(gri): move this into flags
IsStatic bool // whether this Node will be converted to purely static data
Initorder uint8
Used bool // for variable/label declared and not used error
Isddd bool // is the argument variadic

View File

@ -145,9 +145,6 @@ func walkstmt(n *Node) *Node {
if n == nil {
return n
}
if n.IsStatic { // don't walk, generated by anylit.
return n
}
setlineno(n)
@ -720,9 +717,7 @@ opswitch:
}
if n.Left != nil && n.Right != nil {
static := n.IsStatic
n = convas(n, init)
n.IsStatic = static
}
case OAS2: