]> Cypherpunks repositories - gostls13.git/commitdiff
[dev.regabi] cmd/compile: use LinksymOffsetExpr in walkConvInterface
authorMatthew Dempsky <mdempsky@google.com>
Sun, 17 Jan 2021 09:13:34 +0000 (01:13 -0800)
committerMatthew Dempsky <mdempsky@google.com>
Sun, 17 Jan 2021 11:17:54 +0000 (11:17 +0000)
This CL updates walkConvInterface to use LinksymOffsetExpr for
referencing runtime.staticuint64s and runtime.zerobase.

Passes toolstash -cmp (surprisingly).

Change-Id: Iad7e30371f89c8a5e176b5ddbc53faf57012ba0d
Reviewed-on: https://go-review.googlesource.com/c/go/+/284229
Trust: Matthew Dempsky <mdempsky@google.com>
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
src/cmd/compile/internal/ir/expr.go
src/cmd/compile/internal/ir/symtab.go
src/cmd/compile/internal/ssagen/ssa.go
src/cmd/compile/internal/walk/convert.go

index 8aad25d625ec32498e392e2f0d1e7828e13fdb7b..e944a0b1550ebd49693c54cdd9ab55ae9779b5da 100644 (file)
@@ -477,6 +477,13 @@ func NewLinksymOffsetExpr(pos src.XPos, lsym *obj.LSym, offset int64, typ *types
        return n
 }
 
+// NewLinksymExpr is NewLinksymOffsetExpr, but with offset fixed at 0.
+func NewLinksymExpr(pos src.XPos, lsym *obj.LSym, typ *types.Type) *LinksymOffsetExpr {
+       return NewLinksymOffsetExpr(pos, lsym, 0, typ)
+}
+
+// NewNameOffsetExpr is NewLinksymOffsetExpr, but taking a *Name
+// representing a global variable instead of an *obj.LSym directly.
 func NewNameOffsetExpr(pos src.XPos, name *Name, offset int64, typ *types.Type) *LinksymOffsetExpr {
        if name == nil || IsBlank(name) || !(name.Op() == ONAME && name.Class == PEXTERN) {
                base.FatalfAt(pos, "cannot take offset of nil, blank name or non-global variable: %v", name)
index df694f6c848ead5444bb46d8823b1a9007b8c5a0..80e457176490ce1359dda7f202dde2aceb795af8 100644 (file)
@@ -9,12 +9,6 @@ import (
        "cmd/internal/obj"
 )
 
-// Names holds known names.
-var Names struct {
-       Staticuint64s *Name
-       Zerobase      *Name
-}
-
 // Syms holds known symbols.
 var Syms struct {
        AssertE2I       *obj.LSym
@@ -46,6 +40,7 @@ var Syms struct {
        Racewriterange  *obj.LSym
        // Wasm
        SigPanic        *obj.LSym
+       Staticuint64s   *obj.LSym
        Typedmemclr     *obj.LSym
        Typedmemmove    *obj.LSym
        Udiv            *obj.LSym
index beef0d8234668b14426c2998da08961bc9c14d40..02aff7a8cf1fc6f3baa6941d18c35f8f7e2f04ec 100644 (file)
@@ -124,6 +124,7 @@ func InitConfig() {
        ir.Syms.X86HasFMA = typecheck.LookupRuntimeVar("x86HasFMA")             // bool
        ir.Syms.ARMHasVFPv4 = typecheck.LookupRuntimeVar("armHasVFPv4")         // bool
        ir.Syms.ARM64HasATOMICS = typecheck.LookupRuntimeVar("arm64HasATOMICS") // bool
+       ir.Syms.Staticuint64s = typecheck.LookupRuntimeVar("staticuint64s")
        ir.Syms.Typedmemclr = typecheck.LookupRuntimeFunc("typedmemclr")
        ir.Syms.Typedmemmove = typecheck.LookupRuntimeFunc("typedmemmove")
        ir.Syms.Udiv = typecheck.LookupRuntimeVar("udiv")                 // asm func with special ABI
index d143c1084fd2ce7e1efff5aae8909d8acb8ead55..fa8e2c0bb8db485d88d280e1f9b1c9eb43facfd4 100644 (file)
@@ -66,17 +66,6 @@ func walkConvInterface(n *ir.ConvExpr, init *ir.Nodes) ir.Node {
                return l
        }
 
-       if ir.Names.Staticuint64s == nil {
-               ir.Names.Staticuint64s = typecheck.NewName(ir.Pkgs.Runtime.Lookup("staticuint64s"))
-               ir.Names.Staticuint64s.Class = ir.PEXTERN
-               // The actual type is [256]uint64, but we use [256*8]uint8 so we can address
-               // individual bytes.
-               ir.Names.Staticuint64s.SetType(types.NewArray(types.Types[types.TUINT8], 256*8))
-               ir.Names.Zerobase = typecheck.NewName(ir.Pkgs.Runtime.Lookup("zerobase"))
-               ir.Names.Zerobase.Class = ir.PEXTERN
-               ir.Names.Zerobase.SetType(types.Types[types.TUINTPTR])
-       }
-
        // Optimize convT2{E,I} for many cases in which T is not pointer-shaped,
        // by using an existing addressable value identical to n.Left
        // or creating one on the stack.
@@ -85,7 +74,7 @@ func walkConvInterface(n *ir.ConvExpr, init *ir.Nodes) ir.Node {
        case fromType.Size() == 0:
                // n.Left is zero-sized. Use zerobase.
                cheapExpr(n.X, init) // Evaluate n.Left for side-effects. See issue 19246.
-               value = ir.Names.Zerobase
+               value = ir.NewLinksymExpr(base.Pos, ir.Syms.Zerobase, types.Types[types.TUINTPTR])
        case fromType.IsBoolean() || (fromType.Size() == 1 && fromType.IsInteger()):
                // n.Left is a bool/byte. Use staticuint64s[n.Left * 8] on little-endian
                // and staticuint64s[n.Left * 8 + 7] on big-endian.
@@ -95,7 +84,10 @@ func walkConvInterface(n *ir.ConvExpr, init *ir.Nodes) ir.Node {
                if ssagen.Arch.LinkArch.ByteOrder == binary.BigEndian {
                        index = ir.NewBinaryExpr(base.Pos, ir.OADD, index, ir.NewInt(7))
                }
-               xe := ir.NewIndexExpr(base.Pos, ir.Names.Staticuint64s, index)
+               // The actual type is [256]uint64, but we use [256*8]uint8 so we can address
+               // individual bytes.
+               staticuint64s := ir.NewLinksymExpr(base.Pos, ir.Syms.Staticuint64s, types.NewArray(types.Types[types.TUINT8], 256*8))
+               xe := ir.NewIndexExpr(base.Pos, staticuint64s, index)
                xe.SetBounded(true)
                value = xe
        case n.X.Op() == ir.ONAME && n.X.(*ir.Name).Class == ir.PEXTERN && n.X.(*ir.Name).Readonly():