From: Egon Elbre Date: Wed, 17 May 2023 15:10:58 +0000 (+0300) Subject: compile/internal/walk: add walkGrowslice X-Git-Tag: go1.22rc1~995 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=a2647f08f0c4e540540a7ae1b9ba7e668e6fed80;p=gostls13.git 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 Reviewed-by: Matthew Dempsky LUCI-TryBot-Result: Go LUCI Reviewed-by: Keith Randall --- 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, ) (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, ) (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()