mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
[dev.regabi] cmd/compile: clean up Order.copyExpr TODO
Just a little cleaner to read. Passes buildall w/ toolstash -cmp. Change-Id: I27b9f09bf6756f74f1c01794444518ded1a7d625 Reviewed-on: https://go-review.googlesource.com/c/go/+/274106 Trust: Russ Cox <rsc@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com>
This commit is contained in:
parent
7c9b6b1ca2
commit
5fc192af56
1 changed files with 35 additions and 30 deletions
|
|
@ -93,21 +93,26 @@ func (o *Order) newTemp(t *types.Type, clear bool) ir.Node {
|
||||||
|
|
||||||
// copyExpr behaves like newTemp but also emits
|
// copyExpr behaves like newTemp but also emits
|
||||||
// code to initialize the temporary to the value n.
|
// code to initialize the temporary to the value n.
|
||||||
//
|
func (o *Order) copyExpr(n ir.Node) ir.Node {
|
||||||
// The clear argument is provided for use when the evaluation
|
return o.copyExpr1(n, false)
|
||||||
// of tmp = n turns into a function call that is passed a pointer
|
}
|
||||||
// to the temporary as the output space. If the call blocks before
|
|
||||||
// tmp has been written, the garbage collector will still treat the
|
// copyExprClear is like copyExpr but clears the temp before assignment.
|
||||||
// temporary as live, so we must zero it before entering that call.
|
// It is provided for use when the evaluation of tmp = n turns into
|
||||||
|
// a function call that is passed a pointer to the temporary as the output space.
|
||||||
|
// If the call blocks before tmp has been written,
|
||||||
|
// the garbage collector will still treat the temporary as live,
|
||||||
|
// so we must zero it before entering that call.
|
||||||
// Today, this only happens for channel receive operations.
|
// Today, this only happens for channel receive operations.
|
||||||
// (The other candidate would be map access, but map access
|
// (The other candidate would be map access, but map access
|
||||||
// returns a pointer to the result data instead of taking a pointer
|
// returns a pointer to the result data instead of taking a pointer
|
||||||
// to be filled in.)
|
// to be filled in.)
|
||||||
// TODO(rsc): t == n.Type() always; remove parameter.
|
func (o *Order) copyExprClear(n ir.Node) ir.Node {
|
||||||
func (o *Order) copyExpr(n ir.Node, t *types.Type, clear bool) ir.Node {
|
return o.copyExpr1(n, true)
|
||||||
if t != n.Type() {
|
}
|
||||||
panic("copyExpr")
|
|
||||||
}
|
func (o *Order) copyExpr1(n ir.Node, clear bool) ir.Node {
|
||||||
|
t := n.Type()
|
||||||
v := o.newTemp(t, clear)
|
v := o.newTemp(t, clear)
|
||||||
a := ir.Nod(ir.OAS, v, n)
|
a := ir.Nod(ir.OAS, v, n)
|
||||||
a = typecheck(a, ctxStmt)
|
a = typecheck(a, ctxStmt)
|
||||||
|
|
@ -137,7 +142,7 @@ func (o *Order) cheapExpr(n ir.Node) ir.Node {
|
||||||
return typecheck(a, ctxExpr)
|
return typecheck(a, ctxExpr)
|
||||||
}
|
}
|
||||||
|
|
||||||
return o.copyExpr(n, n.Type(), false)
|
return o.copyExpr(n)
|
||||||
}
|
}
|
||||||
|
|
||||||
// safeExpr returns a safe version of n.
|
// safeExpr returns a safe version of n.
|
||||||
|
|
@ -224,7 +229,7 @@ func (o *Order) addrTemp(n ir.Node) ir.Node {
|
||||||
if isaddrokay(n) {
|
if isaddrokay(n) {
|
||||||
return n
|
return n
|
||||||
}
|
}
|
||||||
return o.copyExpr(n, n.Type(), false)
|
return o.copyExpr(n)
|
||||||
}
|
}
|
||||||
|
|
||||||
// mapKeyTemp prepares n to be a key in a map runtime call and returns n.
|
// mapKeyTemp prepares n to be a key in a map runtime call and returns n.
|
||||||
|
|
@ -493,7 +498,7 @@ func (o *Order) call(n ir.Node) {
|
||||||
// by copying it into a temp and marking that temp
|
// by copying it into a temp and marking that temp
|
||||||
// still alive when we pop the temp stack.
|
// still alive when we pop the temp stack.
|
||||||
if arg.Op() == ir.OCONVNOP && arg.Left().Type().IsUnsafePtr() {
|
if arg.Op() == ir.OCONVNOP && arg.Left().Type().IsUnsafePtr() {
|
||||||
x := o.copyExpr(arg.Left(), arg.Left().Type(), false)
|
x := o.copyExpr(arg.Left())
|
||||||
arg.SetLeft(x)
|
arg.SetLeft(x)
|
||||||
x.Name().SetAddrtaken(true) // ensure SSA keeps the x variable
|
x.Name().SetAddrtaken(true) // ensure SSA keeps the x variable
|
||||||
n.PtrBody().Append(typecheck(ir.Nod(ir.OVARLIVE, x, nil), ctxStmt))
|
n.PtrBody().Append(typecheck(ir.Nod(ir.OVARLIVE, x, nil), ctxStmt))
|
||||||
|
|
@ -555,10 +560,10 @@ func (o *Order) mapAssign(n ir.Node) {
|
||||||
switch {
|
switch {
|
||||||
case m.Op() == ir.OINDEXMAP:
|
case m.Op() == ir.OINDEXMAP:
|
||||||
if !ir.IsAutoTmp(m.Left()) {
|
if !ir.IsAutoTmp(m.Left()) {
|
||||||
m.SetLeft(o.copyExpr(m.Left(), m.Left().Type(), false))
|
m.SetLeft(o.copyExpr(m.Left()))
|
||||||
}
|
}
|
||||||
if !ir.IsAutoTmp(m.Right()) {
|
if !ir.IsAutoTmp(m.Right()) {
|
||||||
m.SetRight(o.copyExpr(m.Right(), m.Right().Type(), false))
|
m.SetRight(o.copyExpr(m.Right()))
|
||||||
}
|
}
|
||||||
fallthrough
|
fallthrough
|
||||||
case instrumenting && n.Op() == ir.OAS2FUNC && !ir.IsBlank(m):
|
case instrumenting && n.Op() == ir.OAS2FUNC && !ir.IsBlank(m):
|
||||||
|
|
@ -617,7 +622,7 @@ func (o *Order) stmt(n ir.Node) {
|
||||||
if l1.Op() == ir.OINDEXMAP {
|
if l1.Op() == ir.OINDEXMAP {
|
||||||
l2.SetIndexMapLValue(false)
|
l2.SetIndexMapLValue(false)
|
||||||
}
|
}
|
||||||
l2 = o.copyExpr(l2, l2.Type(), false)
|
l2 = o.copyExpr(l2)
|
||||||
r := ir.NodAt(n.Pos(), n.SubOp(), l2, n.Right())
|
r := ir.NodAt(n.Pos(), n.SubOp(), l2, n.Right())
|
||||||
r = typecheck(r, ctxExpr)
|
r = typecheck(r, ctxExpr)
|
||||||
r = o.expr(r, nil)
|
r = o.expr(r, nil)
|
||||||
|
|
@ -802,7 +807,7 @@ func (o *Order) stmt(n ir.Node) {
|
||||||
r = typecheck(r, ctxExpr)
|
r = typecheck(r, ctxExpr)
|
||||||
}
|
}
|
||||||
|
|
||||||
n.SetRight(o.copyExpr(r, r.Type(), false))
|
n.SetRight(o.copyExpr(r))
|
||||||
|
|
||||||
case types.TMAP:
|
case types.TMAP:
|
||||||
if isMapClear(n) {
|
if isMapClear(n) {
|
||||||
|
|
@ -817,7 +822,7 @@ func (o *Order) stmt(n ir.Node) {
|
||||||
// TODO(rsc): Make tmp = literal expressions reuse tmp.
|
// TODO(rsc): Make tmp = literal expressions reuse tmp.
|
||||||
// For maps tmp is just one word so it hardly matters.
|
// For maps tmp is just one word so it hardly matters.
|
||||||
r := n.Right()
|
r := n.Right()
|
||||||
n.SetRight(o.copyExpr(r, r.Type(), false))
|
n.SetRight(o.copyExpr(r))
|
||||||
|
|
||||||
// prealloc[n] is the temp for the iterator.
|
// prealloc[n] is the temp for the iterator.
|
||||||
// hiter contains pointers and needs to be zeroed.
|
// hiter contains pointers and needs to be zeroed.
|
||||||
|
|
@ -898,7 +903,7 @@ func (o *Order) stmt(n ir.Node) {
|
||||||
|
|
||||||
recv.SetLeft(o.expr(recv.Left(), nil))
|
recv.SetLeft(o.expr(recv.Left(), nil))
|
||||||
if recv.Left().Op() != ir.ONAME {
|
if recv.Left().Op() != ir.ONAME {
|
||||||
recv.SetLeft(o.copyExpr(recv.Left(), recv.Left().Type(), false))
|
recv.SetLeft(o.copyExpr(recv.Left()))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Introduce temporary for receive and move actual copy into case body.
|
// Introduce temporary for receive and move actual copy into case body.
|
||||||
|
|
@ -956,11 +961,11 @@ func (o *Order) stmt(n ir.Node) {
|
||||||
r.SetLeft(o.expr(r.Left(), nil))
|
r.SetLeft(o.expr(r.Left(), nil))
|
||||||
|
|
||||||
if !ir.IsAutoTmp(r.Left()) {
|
if !ir.IsAutoTmp(r.Left()) {
|
||||||
r.SetLeft(o.copyExpr(r.Left(), r.Left().Type(), false))
|
r.SetLeft(o.copyExpr(r.Left()))
|
||||||
}
|
}
|
||||||
r.SetRight(o.expr(r.Right(), nil))
|
r.SetRight(o.expr(r.Right(), nil))
|
||||||
if !ir.IsAutoTmp(r.Right()) {
|
if !ir.IsAutoTmp(r.Right()) {
|
||||||
r.SetRight(o.copyExpr(r.Right(), r.Right().Type(), false))
|
r.SetRight(o.copyExpr(r.Right()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -988,7 +993,7 @@ func (o *Order) stmt(n ir.Node) {
|
||||||
if instrumenting {
|
if instrumenting {
|
||||||
// Force copying to the stack so that (chan T)(nil) <- x
|
// Force copying to the stack so that (chan T)(nil) <- x
|
||||||
// is still instrumented as a read of x.
|
// is still instrumented as a read of x.
|
||||||
n.SetRight(o.copyExpr(n.Right(), n.Right().Type(), false))
|
n.SetRight(o.copyExpr(n.Right()))
|
||||||
} else {
|
} else {
|
||||||
n.SetRight(o.addrTemp(n.Right()))
|
n.SetRight(o.addrTemp(n.Right()))
|
||||||
}
|
}
|
||||||
|
|
@ -1134,7 +1139,7 @@ func (o *Order) expr(n, lhs ir.Node) ir.Node {
|
||||||
// key must be addressable
|
// key must be addressable
|
||||||
n.SetRight(o.mapKeyTemp(n.Left().Type(), n.Right()))
|
n.SetRight(o.mapKeyTemp(n.Left().Type(), n.Right()))
|
||||||
if needCopy {
|
if needCopy {
|
||||||
n = o.copyExpr(n, n.Type(), false)
|
n = o.copyExpr(n)
|
||||||
}
|
}
|
||||||
|
|
||||||
// concrete type (not interface) argument might need an addressable
|
// concrete type (not interface) argument might need an addressable
|
||||||
|
|
@ -1159,7 +1164,7 @@ func (o *Order) expr(n, lhs ir.Node) ir.Node {
|
||||||
o.init(n.Left())
|
o.init(n.Left())
|
||||||
o.call(n.Left())
|
o.call(n.Left())
|
||||||
if lhs == nil || lhs.Op() != ir.ONAME || instrumenting {
|
if lhs == nil || lhs.Op() != ir.ONAME || instrumenting {
|
||||||
n = o.copyExpr(n, n.Type(), false)
|
n = o.copyExpr(n)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
n.SetLeft(o.expr(n.Left(), nil))
|
n.SetLeft(o.expr(n.Left(), nil))
|
||||||
|
|
@ -1229,7 +1234,7 @@ func (o *Order) expr(n, lhs ir.Node) ir.Node {
|
||||||
}
|
}
|
||||||
|
|
||||||
if lhs == nil || lhs.Op() != ir.ONAME || instrumenting {
|
if lhs == nil || lhs.Op() != ir.ONAME || instrumenting {
|
||||||
n = o.copyExpr(n, n.Type(), false)
|
n = o.copyExpr(n)
|
||||||
}
|
}
|
||||||
|
|
||||||
case ir.OAPPEND:
|
case ir.OAPPEND:
|
||||||
|
|
@ -1242,7 +1247,7 @@ func (o *Order) expr(n, lhs ir.Node) ir.Node {
|
||||||
}
|
}
|
||||||
|
|
||||||
if lhs == nil || lhs.Op() != ir.ONAME && !samesafeexpr(lhs, n.List().First()) {
|
if lhs == nil || lhs.Op() != ir.ONAME && !samesafeexpr(lhs, n.List().First()) {
|
||||||
n = o.copyExpr(n, n.Type(), false)
|
n = o.copyExpr(n)
|
||||||
}
|
}
|
||||||
|
|
||||||
case ir.OSLICE, ir.OSLICEARR, ir.OSLICESTR, ir.OSLICE3, ir.OSLICE3ARR:
|
case ir.OSLICE, ir.OSLICEARR, ir.OSLICESTR, ir.OSLICE3, ir.OSLICE3ARR:
|
||||||
|
|
@ -1256,7 +1261,7 @@ func (o *Order) expr(n, lhs ir.Node) ir.Node {
|
||||||
max = o.cheapExpr(max)
|
max = o.cheapExpr(max)
|
||||||
n.SetSliceBounds(low, high, max)
|
n.SetSliceBounds(low, high, max)
|
||||||
if lhs == nil || lhs.Op() != ir.ONAME && !samesafeexpr(lhs, n.Left()) {
|
if lhs == nil || lhs.Op() != ir.ONAME && !samesafeexpr(lhs, n.Left()) {
|
||||||
n = o.copyExpr(n, n.Type(), false)
|
n = o.copyExpr(n)
|
||||||
}
|
}
|
||||||
|
|
||||||
case ir.OCLOSURE:
|
case ir.OCLOSURE:
|
||||||
|
|
@ -1283,12 +1288,12 @@ func (o *Order) expr(n, lhs ir.Node) ir.Node {
|
||||||
case ir.ODOTTYPE, ir.ODOTTYPE2:
|
case ir.ODOTTYPE, ir.ODOTTYPE2:
|
||||||
n.SetLeft(o.expr(n.Left(), nil))
|
n.SetLeft(o.expr(n.Left(), nil))
|
||||||
if !isdirectiface(n.Type()) || instrumenting {
|
if !isdirectiface(n.Type()) || instrumenting {
|
||||||
n = o.copyExpr(n, n.Type(), true)
|
n = o.copyExprClear(n)
|
||||||
}
|
}
|
||||||
|
|
||||||
case ir.ORECV:
|
case ir.ORECV:
|
||||||
n.SetLeft(o.expr(n.Left(), nil))
|
n.SetLeft(o.expr(n.Left(), nil))
|
||||||
n = o.copyExpr(n, n.Type(), true)
|
n = o.copyExprClear(n)
|
||||||
|
|
||||||
case ir.OEQ, ir.ONE, ir.OLT, ir.OLE, ir.OGT, ir.OGE:
|
case ir.OEQ, ir.ONE, ir.OLT, ir.OLE, ir.OGT, ir.OGE:
|
||||||
n.SetLeft(o.expr(n.Left(), nil))
|
n.SetLeft(o.expr(n.Left(), nil))
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue