aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorEgon Elbre <egonelbre@gmail.com>2023-05-17 18:10:58 +0300
committerKeith Randall <khr@golang.org>2023-09-05 15:06:41 +0000
commita2647f08f0c4e540540a7ae1b9ba7e668e6fed80 (patch)
tree465f88d986f7694526d857e4f51c149f9e6b8a0f /src
parent0e1a9e18671a1ba171cda9d681cacaf91bd2c0bb (diff)
downloadgo-a2647f08f0c4e540540a7ae1b9ba7e668e6fed80.tar.xz
compile/internal/walk: add walkGrowslice
Move growslice generation to a separate func so that specialization logic can be shared. Updates #49480 Change-Id: I9ea5bb898753622d2d767546a46b4db6410dc725 Reviewed-on: https://go-review.googlesource.com/c/go/+/495877 Reviewed-by: Keith Randall <khr@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Keith Randall <khr@google.com>
Diffstat (limited to 'src')
-rw-r--r--src/cmd/compile/internal/walk/assign.go13
-rw-r--r--src/cmd/compile/internal/walk/builtin.go16
2 files changed, 13 insertions, 16 deletions
diff --git a/src/cmd/compile/internal/walk/assign.go b/src/cmd/compile/internal/walk/assign.go
index bf7592967e..b8dcba5968 100644
--- a/src/cmd/compile/internal/walk/assign.go
+++ b/src/cmd/compile/internal/walk/assign.go
@@ -513,11 +513,8 @@ func appendSlice(n *ir.CallExpr, init *ir.Nodes) ir.Node {
slice.SetBounded(true)
nif.Body = []ir.Node{ir.NewAssignStmt(base.Pos, s, slice)}
- // func growslice(oldPtr unsafe.Pointer, newLen, oldCap, num int, et *_type) []T
- fn := typecheck.LookupRuntime("growslice", elemtype, elemtype)
-
// else { s = growslice(oldPtr, newLen, oldCap, num, T) }
- call := mkcall1(fn, s.Type(), nif.PtrInit(), oldPtr, newLen, oldCap, num, reflectdata.TypePtrAt(base.Pos, elemtype))
+ call := walkGrowslice(s, nif.PtrInit(), oldPtr, newLen, oldCap, num)
nif.Else = []ir.Node{ir.NewAssignStmt(base.Pos, s, call)}
nodes.Append(nif)
@@ -691,17 +688,13 @@ func extendSlice(n *ir.CallExpr, init *ir.Nodes) ir.Node {
nt.SetBounded(true)
nif.Body = []ir.Node{ir.NewAssignStmt(base.Pos, s, nt)}
- // instantiate growslice(oldPtr *any, newLen, oldCap, num int, typ *type) []any
- fn := typecheck.LookupRuntime("growslice", elemtype, elemtype)
-
// else { s = growslice(s.ptr, n, s.cap, l2, T) }
nif.Else = []ir.Node{
- ir.NewAssignStmt(base.Pos, s, mkcall1(fn, s.Type(), nif.PtrInit(),
+ ir.NewAssignStmt(base.Pos, s, walkGrowslice(s, nif.PtrInit(),
ir.NewUnaryExpr(base.Pos, ir.OSPTR, s),
nn,
ir.NewUnaryExpr(base.Pos, ir.OCAP, s),
- l2,
- reflectdata.TypePtrAt(base.Pos, elemtype))),
+ l2)),
}
nodes = append(nodes, nif)
diff --git a/src/cmd/compile/internal/walk/builtin.go b/src/cmd/compile/internal/walk/builtin.go
index c3a641eac9..56dad14f21 100644
--- a/src/cmd/compile/internal/walk/builtin.go
+++ b/src/cmd/compile/internal/walk/builtin.go
@@ -101,17 +101,13 @@ func walkAppend(n *ir.CallExpr, init *ir.Nodes, dst ir.Node) ir.Node {
ir.NewAssignStmt(base.Pos, s, slice),
}
- // growslice(ptr *T, newLen, oldCap, num int, <type>) (ret []T)
- fn := typecheck.LookupRuntime("growslice", s.Type().Elem(), s.Type().Elem())
-
// else { s = growslice(s.ptr, n, s.cap, a, T) }
nif.Else = []ir.Node{
- ir.NewAssignStmt(base.Pos, s, mkcall1(fn, s.Type(), nif.PtrInit(),
+ ir.NewAssignStmt(base.Pos, s, walkGrowslice(s, nif.PtrInit(),
ir.NewUnaryExpr(base.Pos, ir.OSPTR, s),
newLen,
ir.NewUnaryExpr(base.Pos, ir.OCAP, s),
- num,
- reflectdata.TypePtrAt(base.Pos, s.Type().Elem()))),
+ num)),
}
l = append(l, nif)
@@ -130,6 +126,14 @@ func walkAppend(n *ir.CallExpr, init *ir.Nodes, dst ir.Node) ir.Node {
return s
}
+// growslice(ptr *T, newLen, oldCap, num int, <type>) (ret []T)
+func walkGrowslice(slice *ir.Name, init *ir.Nodes, oldPtr, newLen, oldCap, num ir.Node) *ir.CallExpr {
+ elemtype := slice.Type().Elem()
+ fn := typecheck.LookupRuntime("growslice", elemtype, elemtype)
+ elemtypeptr := reflectdata.TypePtrAt(base.Pos, elemtype)
+ return mkcall1(fn, slice.Type(), init, oldPtr, newLen, oldCap, num, elemtypeptr)
+}
+
// walkClear walks an OCLEAR node.
func walkClear(n *ir.UnaryExpr) ir.Node {
typ := n.X.Type()