mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
cmd/compile: check loop rescheduling with stack bound, not counter
After benchmarking with a compiler modified to have better spill location, it became clear that this method of checking was actually faster on (at least) two different architectures (ppc64 and amd64) and it also provides more timely interruption of loops. This change adds a modified FOR loop node "FORUNTIL" that checks after executing the loop body instead of before (i.e., always at least once). This ensures that a pointer past the end of a slice or array is not made visible to the garbage collector. Without the rescheduling checks inserted, the restructured loop from this change apparently provides a 1% geomean improvement on PPC64 running the go1 benchmarks; the improvement on AMD64 is only 0.12%. Inserting the rescheduling check exposed some peculiar bug with the ssa test code for s390x; this was updated based on initial code actually generated for GOARCH=s390x to use appropriate OpArg, OpAddr, and OpVarDef. NaCl is disabled in testing. Change-Id: Ieafaa9a61d2a583ad00968110ef3e7a441abca50 Reviewed-on: https://go-review.googlesource.com/36206 Run-TryBot: David Chase <drchase@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Cherry Zhang <cherryyz@google.com>
This commit is contained in:
parent
6fbedc1afe
commit
d71f36b5aa
16 changed files with 162 additions and 140 deletions
|
|
@ -133,7 +133,11 @@ out:
|
|||
decldepth--
|
||||
}
|
||||
|
||||
func walkrange(n *Node) {
|
||||
// walkrange transforms various forms of ORANGE into
|
||||
// simpler forms. The result must be assigned back to n.
|
||||
// Node n may also be modified in place, and may also be
|
||||
// the returned node.
|
||||
func walkrange(n *Node) *Node {
|
||||
// variable name conventions:
|
||||
// ohv1, hv1, hv2: hidden (old) val 1, 2
|
||||
// ha, hit: hidden aggregate, iterator
|
||||
|
|
@ -160,6 +164,10 @@ func walkrange(n *Node) {
|
|||
Fatalf("walkrange: v2 != nil while v1 == nil")
|
||||
}
|
||||
|
||||
var ifGuard *Node
|
||||
|
||||
translatedLoopOp := OFOR
|
||||
|
||||
// n.List has no meaning anymore, clear it
|
||||
// to avoid erroneous processing by racewalk.
|
||||
n.List.Set(nil)
|
||||
|
|
@ -173,7 +181,7 @@ func walkrange(n *Node) {
|
|||
case TARRAY, TSLICE:
|
||||
if memclrrange(n, v1, v2, a) {
|
||||
lineno = lno
|
||||
return
|
||||
return n
|
||||
}
|
||||
|
||||
// orderstmt arranged for a copy of the array/slice variable if needed.
|
||||
|
|
@ -185,6 +193,7 @@ func walkrange(n *Node) {
|
|||
|
||||
init = append(init, nod(OAS, hv1, nil))
|
||||
init = append(init, nod(OAS, hn, nod(OLEN, ha, nil)))
|
||||
|
||||
if v2 != nil {
|
||||
hp = temp(ptrto(n.Type.Elem()))
|
||||
tmp := nod(OINDEX, ha, nodintconst(0))
|
||||
|
|
@ -198,7 +207,11 @@ func walkrange(n *Node) {
|
|||
body = nil
|
||||
} else if v2 == nil {
|
||||
body = []*Node{nod(OAS, v1, hv1)}
|
||||
} else {
|
||||
} else { // for i,a := range thing { body }
|
||||
ifGuard = nod(OIF, nil, nil)
|
||||
ifGuard.Left = nod(OLT, hv1, hn)
|
||||
translatedLoopOp = OFORUNTIL
|
||||
|
||||
a := nod(OAS2, nil, nil)
|
||||
a.List.Set2(v1, v2)
|
||||
a.Rlist.Set2(hv1, nod(OIND, hp, nil))
|
||||
|
|
@ -360,17 +373,33 @@ func walkrange(n *Node) {
|
|||
}
|
||||
}
|
||||
|
||||
n.Op = OFOR
|
||||
n.Op = translatedLoopOp
|
||||
typecheckslice(init, Etop)
|
||||
n.Ninit.Append(init...)
|
||||
|
||||
if ifGuard != nil {
|
||||
ifGuard.Ninit.Append(init...)
|
||||
typecheckslice(ifGuard.Left.Ninit.Slice(), Etop)
|
||||
ifGuard.Left = typecheck(ifGuard.Left, Erv)
|
||||
} else {
|
||||
n.Ninit.Append(init...)
|
||||
}
|
||||
|
||||
typecheckslice(n.Left.Ninit.Slice(), Etop)
|
||||
|
||||
n.Left = typecheck(n.Left, Erv)
|
||||
n.Right = typecheck(n.Right, Etop)
|
||||
typecheckslice(body, Etop)
|
||||
n.Nbody.Prepend(body...)
|
||||
|
||||
if ifGuard != nil {
|
||||
ifGuard.Nbody.Set1(n)
|
||||
n = ifGuard
|
||||
}
|
||||
|
||||
n = walkstmt(n)
|
||||
|
||||
lineno = lno
|
||||
return n
|
||||
}
|
||||
|
||||
// Lower n into runtime·memclr if possible, for
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue