mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
cmd/compile: add convnop helper function
Like the conv helper function but for creating OCONVNOP nodes instead of OCONV nodes. passes toolstash -cmp Change-Id: Ib93ffe66590ebaa2b4fa552c81f1a2902e789d8e Reviewed-on: https://go-review.googlesource.com/112597 Run-TryBot: Martin Möhrmann <moehrmann@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com>
This commit is contained in:
parent
9e2a04d5eb
commit
c5d38b896d
5 changed files with 21 additions and 27 deletions
|
|
@ -382,10 +382,7 @@ func walkclosure(clo *Node, init *Nodes) *Node {
|
||||||
clos.List.Set(append([]*Node{nod(OCFUNC, xfunc.Func.Nname, nil)}, clo.Func.Enter.Slice()...))
|
clos.List.Set(append([]*Node{nod(OCFUNC, xfunc.Func.Nname, nil)}, clo.Func.Enter.Slice()...))
|
||||||
|
|
||||||
// Force type conversion from *struct to the func type.
|
// Force type conversion from *struct to the func type.
|
||||||
clos = nod(OCONVNOP, clos, nil)
|
clos = convnop(clos, clo.Type)
|
||||||
clos.Type = clo.Type
|
|
||||||
|
|
||||||
clos = typecheck(clos, Erv)
|
|
||||||
|
|
||||||
// typecheck will insert a PTRLIT node under CONVNOP,
|
// typecheck will insert a PTRLIT node under CONVNOP,
|
||||||
// tag it with escape analysis result.
|
// tag it with escape analysis result.
|
||||||
|
|
@ -511,10 +508,7 @@ func walkpartialcall(n *Node, init *Nodes) *Node {
|
||||||
clos.List.Append(n.Left)
|
clos.List.Append(n.Left)
|
||||||
|
|
||||||
// Force type conversion from *struct to the func type.
|
// Force type conversion from *struct to the func type.
|
||||||
clos = nod(OCONVNOP, clos, nil)
|
clos = convnop(clos, n.Type)
|
||||||
clos.Type = n.Type
|
|
||||||
|
|
||||||
clos = typecheck(clos, Erv)
|
|
||||||
|
|
||||||
// typecheck will insert a PTRLIT node under CONVNOP,
|
// typecheck will insert a PTRLIT node under CONVNOP,
|
||||||
// tag it with escape analysis result.
|
// tag it with escape analysis result.
|
||||||
|
|
|
||||||
|
|
@ -580,8 +580,7 @@ func arrayClear(n, v1, v2, a *Node) bool {
|
||||||
tmp := nod(OINDEX, a, nodintconst(0))
|
tmp := nod(OINDEX, a, nodintconst(0))
|
||||||
tmp.SetBounded(true)
|
tmp.SetBounded(true)
|
||||||
tmp = nod(OADDR, tmp, nil)
|
tmp = nod(OADDR, tmp, nil)
|
||||||
tmp = nod(OCONVNOP, tmp, nil)
|
tmp = convnop(tmp, types.Types[TUNSAFEPTR])
|
||||||
tmp.Type = types.Types[TUNSAFEPTR]
|
|
||||||
n.Nbody.Append(nod(OAS, hp, tmp))
|
n.Nbody.Append(nod(OAS, hp, tmp))
|
||||||
|
|
||||||
// hn = len(a) * sizeof(elem(a))
|
// hn = len(a) * sizeof(elem(a))
|
||||||
|
|
|
||||||
|
|
@ -316,13 +316,11 @@ func walkselectcases(cases *Nodes) []*Node {
|
||||||
|
|
||||||
setField("kind", nodintconst(kind))
|
setField("kind", nodintconst(kind))
|
||||||
if c != nil {
|
if c != nil {
|
||||||
c = nod(OCONVNOP, c, nil)
|
c = convnop(c, types.Types[TUNSAFEPTR])
|
||||||
c.Type = types.Types[TUNSAFEPTR]
|
|
||||||
setField("c", c)
|
setField("c", c)
|
||||||
}
|
}
|
||||||
if elem != nil {
|
if elem != nil {
|
||||||
elem = nod(OCONVNOP, elem, nil)
|
elem = convnop(elem, types.Types[TUNSAFEPTR])
|
||||||
elem.Type = types.Types[TUNSAFEPTR]
|
|
||||||
setField("elem", elem)
|
setField("elem", elem)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -375,10 +373,9 @@ func walkselectcases(cases *Nodes) []*Node {
|
||||||
|
|
||||||
// bytePtrToIndex returns a Node representing "(*byte)(&n[i])".
|
// bytePtrToIndex returns a Node representing "(*byte)(&n[i])".
|
||||||
func bytePtrToIndex(n *Node, i int64) *Node {
|
func bytePtrToIndex(n *Node, i int64) *Node {
|
||||||
s := nod(OCONVNOP, nod(OADDR, nod(OINDEX, n, nodintconst(i)), nil), nil)
|
s := nod(OADDR, nod(OINDEX, n, nodintconst(i)), nil)
|
||||||
s.Type = types.NewPtr(types.Types[TUINT8])
|
t := types.NewPtr(types.Types[TUINT8])
|
||||||
s = typecheck(s, Erv)
|
return convnop(s, t)
|
||||||
return s
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var scase *types.Type
|
var scase *types.Type
|
||||||
|
|
|
||||||
|
|
@ -1674,8 +1674,7 @@ func genwrapper(rcvr *types.Type, method *types.Field, newnam *types.Sym) {
|
||||||
if !dotlist[0].field.Type.IsPtr() {
|
if !dotlist[0].field.Type.IsPtr() {
|
||||||
dot = nod(OADDR, dot, nil)
|
dot = nod(OADDR, dot, nil)
|
||||||
}
|
}
|
||||||
as := nod(OAS, nthis, nod(OCONVNOP, dot, nil))
|
as := nod(OAS, nthis, convnop(dot, rcvr))
|
||||||
as.Right.Type = rcvr
|
|
||||||
fn.Nbody.Append(as)
|
fn.Nbody.Append(as)
|
||||||
fn.Nbody.Append(nodSym(ORETJMP, nil, methodSym(methodrcvr, method.Sym)))
|
fn.Nbody.Append(nodSym(ORETJMP, nil, methodSym(methodrcvr, method.Sym)))
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
|
|
@ -1506,9 +1506,7 @@ opswitch:
|
||||||
a = typecheck(a, Etop)
|
a = typecheck(a, Etop)
|
||||||
a = walkexpr(a, init)
|
a = walkexpr(a, init)
|
||||||
init.Append(a)
|
init.Append(a)
|
||||||
n = nod(OCONVNOP, h, nil)
|
n = convnop(h, t)
|
||||||
n.Type = t
|
|
||||||
n = typecheck(n, Erv)
|
|
||||||
} else {
|
} else {
|
||||||
// Call runtime.makehmap to allocate an
|
// Call runtime.makehmap to allocate an
|
||||||
// hmap on the heap and initialize hmap's hash0 field.
|
// hmap on the heap and initialize hmap's hash0 field.
|
||||||
|
|
@ -2029,8 +2027,7 @@ func ascompatte(call *Node, isddd bool, lhs *types.Type, rhs []*Node, fp int, in
|
||||||
// optimization - can do block copy
|
// optimization - can do block copy
|
||||||
if eqtypenoname(rhs[0].Type, lhs) {
|
if eqtypenoname(rhs[0].Type, lhs) {
|
||||||
nl := nodarg(lhs, fp)
|
nl := nodarg(lhs, fp)
|
||||||
nr := nod(OCONVNOP, rhs[0], nil)
|
nr := convnop(rhs[0], nl.Type)
|
||||||
nr.Type = nl.Type
|
|
||||||
n := convas(nod(OAS, nl, nr), init)
|
n := convas(nod(OAS, nl, nr), init)
|
||||||
n.SetTypecheck(1)
|
n.SetTypecheck(1)
|
||||||
return []*Node{n}
|
return []*Node{n}
|
||||||
|
|
@ -2748,6 +2745,15 @@ func conv(n *Node, t *types.Type) *Node {
|
||||||
return n
|
return n
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// convnop converts node n to type t using the OCONVNOP op
|
||||||
|
// and typechecks the result with Erv.
|
||||||
|
func convnop(n *Node, t *types.Type) *Node {
|
||||||
|
n = nod(OCONVNOP, n, nil)
|
||||||
|
n.Type = t
|
||||||
|
n = typecheck(n, Erv)
|
||||||
|
return n
|
||||||
|
}
|
||||||
|
|
||||||
// byteindex converts n, which is byte-sized, to a uint8.
|
// byteindex converts n, which is byte-sized, to a uint8.
|
||||||
// We cannot use conv, because we allow converting bool to uint8 here,
|
// We cannot use conv, because we allow converting bool to uint8 here,
|
||||||
// which is forbidden in user code.
|
// which is forbidden in user code.
|
||||||
|
|
@ -3157,8 +3163,7 @@ func extendslice(n *Node, init *Nodes) *Node {
|
||||||
hp := nod(OINDEX, s, nod(OLEN, l1, nil))
|
hp := nod(OINDEX, s, nod(OLEN, l1, nil))
|
||||||
hp.SetBounded(true)
|
hp.SetBounded(true)
|
||||||
hp = nod(OADDR, hp, nil)
|
hp = nod(OADDR, hp, nil)
|
||||||
hp = nod(OCONVNOP, hp, nil)
|
hp = convnop(hp, types.Types[TUNSAFEPTR])
|
||||||
hp.Type = types.Types[TUNSAFEPTR]
|
|
||||||
|
|
||||||
// hn := l2 * sizeof(elem(s))
|
// hn := l2 * sizeof(elem(s))
|
||||||
hn := nod(OMUL, l2, nodintconst(elemtype.Width))
|
hn := nod(OMUL, l2, nodintconst(elemtype.Width))
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue