diff options
author | cuiweixie <cuiweixie@gmail.com> | 2021-04-29 14:28:43 +0000 |
---|---|---|
committer | Matthew Dempsky <mdempsky@google.com> | 2021-04-29 17:38:15 +0000 |
commit | 32dbaac572f9aed4fbaa6aa359bdc821fa02e9d4 (patch) | |
tree | 264303bd8ff28997bc9423f3c98574b382149457 /src/cmd/compile/internal/walk | |
parent | e03cca64073bd1b4704482c81061d19ab019b5cc (diff) | |
download | go-32dbaac572f9aed4fbaa6aa359bdc821fa02e9d4.tar.gz go-32dbaac572f9aed4fbaa6aa359bdc821fa02e9d4.zip |
cmd/compile/internal/walk: merge operations when calling ir.NewSlic…
Change-Id: I55ef35a9d8157063c4a41b23cd1ac0002838d30a
GitHub-Last-Rev: e716c5200545a944313ae0d995fcb6eb17d2720e
GitHub-Pull-Request: golang/go#45814
Reviewed-on: https://go-review.googlesource.com/c/go/+/314569
Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Trust: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Trust: Matthew Dempsky <mdempsky@google.com>
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Diffstat (limited to 'src/cmd/compile/internal/walk')
-rw-r--r-- | src/cmd/compile/internal/walk/builtin.go | 35 |
1 files changed, 13 insertions, 22 deletions
diff --git a/src/cmd/compile/internal/walk/builtin.go b/src/cmd/compile/internal/walk/builtin.go index 684fc7d72a..aacdedcb4d 100644 --- a/src/cmd/compile/internal/walk/builtin.go +++ b/src/cmd/compile/internal/walk/builtin.go @@ -421,16 +421,13 @@ func walkMakeSlice(n *ir.MakeExpr, init *ir.Nodes) ir.Node { fnname = "makeslice" argtype = types.Types[types.TINT] } - - m := ir.NewSliceHeaderExpr(base.Pos, nil, nil, nil, nil) - m.SetType(t) - fn := typecheck.LookupRuntime(fnname) - m.Ptr = mkcall1(fn, types.Types[types.TUNSAFEPTR], init, reflectdata.TypePtr(t.Elem()), typecheck.Conv(len, argtype), typecheck.Conv(cap, argtype)) - m.Ptr.MarkNonNil() - m.Len = typecheck.Conv(len, types.Types[types.TINT]) - m.Cap = typecheck.Conv(cap, types.Types[types.TINT]) - return walkExpr(typecheck.Expr(m), init) + ptr := mkcall1(fn, types.Types[types.TUNSAFEPTR], init, reflectdata.TypePtr(t.Elem()), typecheck.Conv(len, argtype), typecheck.Conv(cap, argtype)) + ptr.MarkNonNil() + len = typecheck.Conv(len, types.Types[types.TINT]) + cap = typecheck.Conv(cap, types.Types[types.TINT]) + sh := ir.NewSliceHeaderExpr(base.Pos, t, ptr, len, cap) + return walkExpr(typecheck.Expr(sh), init) } // walkMakeSliceCopy walks an OMAKESLICECOPY node. @@ -459,12 +456,9 @@ func walkMakeSliceCopy(n *ir.MakeExpr, init *ir.Nodes) ir.Node { // instantiate mallocgc(size uintptr, typ *byte, needszero bool) unsafe.Pointer fn := typecheck.LookupRuntime("mallocgc") - sh := ir.NewSliceHeaderExpr(base.Pos, nil, nil, nil, nil) - sh.Ptr = mkcall1(fn, types.Types[types.TUNSAFEPTR], init, size, typecheck.NodNil(), ir.NewBool(false)) - sh.Ptr.MarkNonNil() - sh.Len = length - sh.Cap = length - sh.SetType(t) + ptr := mkcall1(fn, types.Types[types.TUNSAFEPTR], init, size, typecheck.NodNil(), ir.NewBool(false)) + ptr.MarkNonNil() + sh := ir.NewSliceHeaderExpr(base.Pos, t, ptr, length, length) s := typecheck.Temp(t) r := typecheck.Stmt(ir.NewAssignStmt(base.Pos, s, sh)) @@ -482,13 +476,10 @@ func walkMakeSliceCopy(n *ir.MakeExpr, init *ir.Nodes) ir.Node { // Replace make+copy with runtime.makeslicecopy. // instantiate makeslicecopy(typ *byte, tolen int, fromlen int, from unsafe.Pointer) unsafe.Pointer fn := typecheck.LookupRuntime("makeslicecopy") - s := ir.NewSliceHeaderExpr(base.Pos, nil, nil, nil, nil) - s.Ptr = mkcall1(fn, types.Types[types.TUNSAFEPTR], init, reflectdata.TypePtr(t.Elem()), length, copylen, typecheck.Conv(copyptr, types.Types[types.TUNSAFEPTR])) - s.Ptr.MarkNonNil() - s.Len = length - s.Cap = length - s.SetType(t) - return walkExpr(typecheck.Expr(s), init) + ptr := mkcall1(fn, types.Types[types.TUNSAFEPTR], init, reflectdata.TypePtr(t.Elem()), length, copylen, typecheck.Conv(copyptr, types.Types[types.TUNSAFEPTR])) + ptr.MarkNonNil() + sh := ir.NewSliceHeaderExpr(base.Pos, t, ptr, length, length) + return walkExpr(typecheck.Expr(sh), init) } // walkNew walks an ONEW node. |