diff options
author | Matthew Dempsky <mdempsky@google.com> | 2021-06-21 22:03:02 -0700 |
---|---|---|
committer | Matthew Dempsky <mdempsky@google.com> | 2021-06-22 09:11:39 +0000 |
commit | 077100dfcd11b2aba4bd3099d5d28b4ce7de1126 (patch) | |
tree | 7a15e4c9a57ddc9115047943c74f5d6a6705b7c3 /src/cmd/compile/internal/walk | |
parent | 859d903b06af669edbbc74be371186f732b60bfa (diff) | |
download | go-077100dfcd11b2aba4bd3099d5d28b4ce7de1126.tar.gz go-077100dfcd11b2aba4bd3099d5d28b4ce7de1126.zip |
[dev.typeparams] cmd/compile: remove special escape analysis tags
This CL removes the special escape analysis tags added to support
//go:uintptrescapes and calls to external functions. Instead, these
are kept as function pragmas.
This CL by itself isn't very interesting, but I expect will help with
subsequent cleanups I have planned here.
Change-Id: Ifb960289a27e0a6295ce2d2f5ec233cac590522b
Reviewed-on: https://go-review.googlesource.com/c/go/+/329969
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Trust: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Trust: Matthew Dempsky <mdempsky@google.com>
Diffstat (limited to 'src/cmd/compile/internal/walk')
-rw-r--r-- | src/cmd/compile/internal/walk/order.go | 52 |
1 files changed, 30 insertions, 22 deletions
diff --git a/src/cmd/compile/internal/walk/order.go b/src/cmd/compile/internal/walk/order.go index 845bf03657..b9aff03240 100644 --- a/src/cmd/compile/internal/walk/order.go +++ b/src/cmd/compile/internal/walk/order.go @@ -9,7 +9,6 @@ import ( "go/constant" "cmd/compile/internal/base" - "cmd/compile/internal/escape" "cmd/compile/internal/ir" "cmd/compile/internal/reflectdata" "cmd/compile/internal/staticinit" @@ -554,37 +553,46 @@ func (o *orderState) call(nn ir.Node) { n.X = o.expr(n.X, nil) o.exprList(n.Args) - if n.Op() == ir.OCALLINTER { + // Pick out the function callee, if statically known. + // TODO(mdempsky): De-duplicate with similar code in escape analysis. + var callee *ir.Func + switch n.Op() { + case ir.OCALLFUNC: + if fn, ok := n.X.(*ir.Name); ok && fn.Op() == ir.ONAME && fn.Class == ir.PFUNC { + callee = fn.Func + } + case ir.OCALLMETH: + callee = ir.MethodExprName(n.X).Func + } + + if callee == nil || callee.Pragma&ir.UintptrKeepAlive == 0 { return } - keepAlive := func(arg ir.Node) { + + keepAlive := func(args []ir.Node) { // If the argument is really a pointer being converted to uintptr, // arrange for the pointer to be kept alive until the call returns, // by copying it into a temp and marking that temp // still alive when we pop the temp stack. - if arg.Op() == ir.OCONVNOP { - arg := arg.(*ir.ConvExpr) - if arg.X.Type().IsUnsafePtr() { - x := o.copyExpr(arg.X) - arg.X = x - x.SetAddrtaken(true) // ensure SSA keeps the x variable - n.KeepAlive = append(n.KeepAlive, x) + for _, arg := range args { + if arg.Op() == ir.OCONVNOP && arg.Type().IsUintptr() { + arg := arg.(*ir.ConvExpr) + if arg.X.Type().IsUnsafePtr() { + x := o.copyExpr(arg.X) + arg.X = x + x.SetAddrtaken(true) // ensure SSA keeps the x variable + n.KeepAlive = append(n.KeepAlive, x) + } } } } - // Check for "unsafe-uintptr" tag provided by escape analysis. - for i, param := range n.X.Type().Params().FieldSlice() { - if param.Note == escape.UnsafeUintptrNote || param.Note == escape.UintptrEscapesNote { - if arg := n.Args[i]; arg.Op() == ir.OSLICELIT { - arg := arg.(*ir.CompLitExpr) - for _, elt := range arg.List { - keepAlive(elt) - } - } else { - keepAlive(arg) - } - } + last := len(n.Args) - 1 + if n.IsDDD && n.Args[last].Op() == ir.OSLICELIT { + keepAlive(n.Args[:last]) + keepAlive(n.Args[last].(*ir.CompLitExpr).List) + } else { + keepAlive(n.Args) } } |