]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/internal/obj: eagerly initialize assemblers
authorJosh Bleecher Snyder <josharian@gmail.com>
Thu, 6 Apr 2017 20:42:31 +0000 (13:42 -0700)
committerJosh Bleecher Snyder <josharian@gmail.com>
Fri, 7 Apr 2017 16:57:03 +0000 (16:57 +0000)
CL 38662 changed the x86 assembler to be eagerly
initialized, for a concurrent backend.

This CL puts in place a proper mechanism for doing so,
and switches all architectures to use it.

Passes toolstash-check -all.

Updates #15756

Change-Id: Id2aa527d3a8259c95797d63a2f0d1123e3ca2a1c
Reviewed-on: https://go-review.googlesource.com/39917
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
19 files changed:
src/cmd/asm/internal/arch/arch.go
src/cmd/asm/internal/asm/endtoend_test.go
src/cmd/asm/main.go
src/cmd/compile/internal/amd64/galign.go
src/cmd/compile/internal/gc/main.go
src/cmd/compile/internal/x86/galign.go
src/cmd/internal/obj/arm/asm5.go
src/cmd/internal/obj/arm/obj5.go
src/cmd/internal/obj/arm64/asm7.go
src/cmd/internal/obj/arm64/obj7.go
src/cmd/internal/obj/link.go
src/cmd/internal/obj/mips/asm0.go
src/cmd/internal/obj/mips/obj0.go
src/cmd/internal/obj/ppc64/asm9.go
src/cmd/internal/obj/ppc64/obj9.go
src/cmd/internal/obj/s390x/asmz.go
src/cmd/internal/obj/s390x/objz.go
src/cmd/internal/obj/x86/asm6.go
src/cmd/internal/obj/x86/obj6.go

index f325e9366d656fda61cd83a088bb874c8e413bf8..b4ce2fd8ae6cc1fca65d543577cd76011e5313a4 100644 (file)
@@ -171,8 +171,6 @@ func archX86(linkArch *obj.LinkArch) *Arch {
        instructions["PSRLDQ"] = x86.APSRLO
        instructions["PADDD"] = x86.APADDL
 
-       x86.InstInit()
-
        return &Arch{
                LinkArch:       linkArch,
                Instructions:   instructions,
index a105ce725fa13fda94c60a94ac33ff4a009511a9..f9d95ebc8ca63d0bf19c6dcd3d5cba0d1320884b 100644 (file)
@@ -28,6 +28,7 @@ import (
 func testEndToEnd(t *testing.T, goarch, file string) {
        input := filepath.Join("testdata", file+".s")
        architecture, ctxt := setArch(goarch)
+       architecture.Init(ctxt)
        lexer := lex.NewLexer(input)
        parser := NewParser(ctxt, architecture, lexer)
        pList := new(obj.Plist)
index 3aab0d00a260efe6ae26b68f5f7ee290c58d2a39..737d2f102cf5cc1dfd9a47eb4302c108ccd7427e 100644 (file)
@@ -42,6 +42,8 @@ func main() {
        ctxt.Bso = bufio.NewWriter(os.Stdout)
        defer ctxt.Bso.Flush()
 
+       architecture.Init(ctxt)
+
        // Create object file, write header.
        out, err := os.Create(*flags.OutputFile)
        if err != nil {
index 59484b1537d685e1bea5b6de172bae3cacd6acb8..90ee895364dfe54bf4ed77bd95286f807d663894 100644 (file)
@@ -27,6 +27,4 @@ func Init(arch *gc.Arch) {
        arch.SSAMarkMoves = ssaMarkMoves
        arch.SSAGenValue = ssaGenValue
        arch.SSAGenBlock = ssaGenBlock
-
-       x86.InstInit()
 }
index d6872126f1e1ef342e1cb6eca521d935016beb77..00d44d885baa861c9e70b37a334c794898be822e 100644 (file)
@@ -238,6 +238,8 @@ func Main(archInit func(*Arch)) {
                usage()
        }
 
+       thearch.LinkArch.Init(Ctxt)
+
        if outfile == "" {
                p := flag.Arg(0)
                if i := strings.LastIndex(p, "/"); i >= 0 {
index 5255e9c60ec802ac559e58a6b6de2238acc361ea..b5cf044bc7457992a17d6dda340f817f408b154f 100644 (file)
@@ -33,6 +33,4 @@ func Init(arch *gc.Arch) {
        arch.Ginsnop = ginsnop
 
        arch.SSAMarkMoves = ssaMarkMoves
-
-       x86.InstInit()
 }
index c755e90b23a7fc56b766fa733c081391e8b027a6..56ee7aa2f9dfd148973fbbe7f59423ca306f9263 100644 (file)
@@ -557,7 +557,7 @@ func span5(ctxt *obj.Link, cursym *obj.LSym, newprog obj.ProgAlloc) {
        }
 
        if oprange[AAND&obj.AMask] == nil {
-               buildop(ctxt)
+               ctxt.Diag("arm ops not initialized, call arm.buildop first")
        }
 
        ctxt.Cursym = cursym
@@ -1296,6 +1296,13 @@ func opset(a, b0 obj.As) {
 }
 
 func buildop(ctxt *obj.Link) {
+       if oprange[AAND&obj.AMask] != nil {
+               // Already initialized; stop now.
+               // This happens in the cmd/asm tests,
+               // each of which re-initializes the arch.
+               return
+       }
+
        var n int
 
        for i := 0; i < C_GOK; i++ {
index f14577e2fadae0d3cccecf14cae9a08bf6a27880..89cf299bef664e9088f137d15dd808202d56aa16 100644 (file)
@@ -880,6 +880,7 @@ var unaryDst = map[obj.As]bool{
 
 var Linkarm = obj.LinkArch{
        Arch:       sys.ArchARM,
+       Init:       buildop,
        Preprocess: preprocess,
        Assemble:   span5,
        Progedit:   progedit,
index c0a19d2d2aaacd42604afe66269a7fafcd9a2efd..65c48d3e01f2f430350f8cb1bcf0be3609ccc18f 100644 (file)
@@ -537,7 +537,7 @@ func span7(ctxt *obj.Link, cursym *obj.LSym, newprog obj.ProgAlloc) {
        ctxt.Autosize = int32(p.To.Offset&0xffffffff) + 8
 
        if oprange[AAND&obj.AMask] == nil {
-               buildop(ctxt)
+               ctxt.Diag("arm64 ops not initialized, call arm64.buildop first")
        }
 
        bflag := 1
@@ -1438,6 +1438,13 @@ func oprangeset(a obj.As, t []Optab) {
 }
 
 func buildop(ctxt *obj.Link) {
+       if oprange[AAND&obj.AMask] != nil {
+               // Already initialized; stop now.
+               // This happens in the cmd/asm tests,
+               // each of which re-initializes the arch.
+               return
+       }
+
        var n int
        for i := 0; i < C_GOK; i++ {
                for n = 0; n < C_GOK; n++ {
index b09454445aad922cd18c1884651a0416a9ddd067..52c4c594cb9a2c3f5ffb8a6ce3f46ad9838e32b4 100644 (file)
@@ -799,6 +799,7 @@ var unaryDst = map[obj.As]bool{
 
 var Linkarm64 = obj.LinkArch{
        Arch:       sys.ArchARM64,
+       Init:       buildop,
        Preprocess: preprocess,
        Assemble:   span7,
        Progedit:   progedit,
index 53a9428e72eda91e935456036d39a7be5de051b1..fd07851f3b0e38454bdd2a07426c727252fba438 100644 (file)
@@ -786,6 +786,7 @@ type SymVer struct {
 // LinkArch is the definition of a single architecture.
 type LinkArch struct {
        *sys.Arch
+       Init       func(*Link)
        Preprocess func(*Link, *LSym, ProgAlloc)
        Assemble   func(*Link, *LSym, ProgAlloc)
        Progedit   func(*Link, *Prog, ProgAlloc)
index 30ffc0d3d738aa5d53e428c4766c9cb0c1bdbf6b..4151f6ad351a2ca078ff4ee9e1e999ea9fee7e41 100644 (file)
@@ -382,7 +382,7 @@ func span0(ctxt *obj.Link, cursym *obj.LSym, newprog obj.ProgAlloc) {
        ctxt.Autosize = int32(p.To.Offset + ctxt.FixedFrameSize())
 
        if oprange[AOR&obj.AMask] == nil {
-               buildop(ctxt)
+               ctxt.Diag("mips ops not initialized, call mips.buildop first")
        }
 
        c := int64(0)
@@ -668,7 +668,7 @@ func prasm(p *obj.Prog) {
 
 func oplook(ctxt *obj.Link, p *obj.Prog) *Optab {
        if oprange[AOR&obj.AMask] == nil {
-               buildop(ctxt)
+               ctxt.Diag("mips ops not initialized, call mips.buildop first")
        }
 
        a1 := int(p.Optab)
@@ -833,6 +833,13 @@ func opset(a, b0 obj.As) {
 }
 
 func buildop(ctxt *obj.Link) {
+       if oprange[AOR&obj.AMask] != nil {
+               // Already initialized; stop now.
+               // This happens in the cmd/asm tests,
+               // each of which re-initializes the arch.
+               return
+       }
+
        var n int
 
        for i := 0; i < C_NCLASS; i++ {
index 3724808be11699d585f680279afd68016552a27a..e5f32778854f6ec5367e0d7edd359a753952b936 100644 (file)
@@ -1398,6 +1398,7 @@ func compound(ctxt *obj.Link, p *obj.Prog) bool {
 
 var Linkmips64 = obj.LinkArch{
        Arch:       sys.ArchMIPS64,
+       Init:       buildop,
        Preprocess: preprocess,
        Assemble:   span0,
        Progedit:   progedit,
@@ -1405,6 +1406,7 @@ var Linkmips64 = obj.LinkArch{
 
 var Linkmips64le = obj.LinkArch{
        Arch:       sys.ArchMIPS64LE,
+       Init:       buildop,
        Preprocess: preprocess,
        Assemble:   span0,
        Progedit:   progedit,
@@ -1412,6 +1414,7 @@ var Linkmips64le = obj.LinkArch{
 
 var Linkmips = obj.LinkArch{
        Arch:       sys.ArchMIPS,
+       Init:       buildop,
        Preprocess: preprocess,
        Assemble:   span0,
        Progedit:   progedit,
@@ -1419,6 +1422,7 @@ var Linkmips = obj.LinkArch{
 
 var Linkmipsle = obj.LinkArch{
        Arch:       sys.ArchMIPSLE,
+       Init:       buildop,
        Preprocess: preprocess,
        Assemble:   span0,
        Progedit:   progedit,
index a6a359da23e39d9e0bd142085af40e0da0ccb972..523448b0d9f8e0d1515b0f83c1f4ff0fd4c2fbb5 100644 (file)
@@ -561,7 +561,7 @@ func span9(ctxt *obj.Link, cursym *obj.LSym, newprog obj.ProgAlloc) {
        ctxt.Autosize = int32(p.To.Offset)
 
        if oprange[AANDN&obj.AMask] == nil {
-               buildop(ctxt)
+               ctxt.Diag("ppc64 ops not initialized, call ppc64.buildop first")
        }
 
        c := int64(0)
@@ -1052,6 +1052,13 @@ func opset(a, b0 obj.As) {
 }
 
 func buildop(ctxt *obj.Link) {
+       if oprange[AANDN&obj.AMask] != nil {
+               // Already initialized; stop now.
+               // This happens in the cmd/asm tests,
+               // each of which re-initializes the arch.
+               return
+       }
+
        var n int
 
        for i := 0; i < C_NCLASS; i++ {
index 6e93cc399685d496d86e9234dd5bf0984ed62671..1349075043d73e24484238c0c201a1329851abf9 100644 (file)
@@ -1051,6 +1051,7 @@ func stacksplit(ctxt *obj.Link, p *obj.Prog, newprog obj.ProgAlloc, framesize in
 
 var Linkppc64 = obj.LinkArch{
        Arch:       sys.ArchPPC64,
+       Init:       buildop,
        Preprocess: preprocess,
        Assemble:   span9,
        Progedit:   progedit,
@@ -1058,6 +1059,7 @@ var Linkppc64 = obj.LinkArch{
 
 var Linkppc64le = obj.LinkArch{
        Arch:       sys.ArchPPC64LE,
+       Init:       buildop,
        Preprocess: preprocess,
        Assemble:   span9,
        Progedit:   progedit,
index 25109dda3c796cfa55295766b3af0e4981aa0794..a7dafdffa086859eb6060f74effd4ae289ade03b 100644 (file)
@@ -394,7 +394,7 @@ func spanz(ctxt *obj.Link, cursym *obj.LSym, newprog obj.ProgAlloc) {
        ctxt.Autosize = int32(p.To.Offset)
 
        if oprange[AORW&obj.AMask] == nil {
-               buildop(ctxt)
+               ctxt.Diag("s390x ops not initialized, call s390x.buildop first")
        }
 
        buffer := make([]byte, 0)
@@ -772,6 +772,13 @@ func opset(a, b obj.As) {
 }
 
 func buildop(ctxt *obj.Link) {
+       if oprange[AORW&obj.AMask] != nil {
+               // Already initialized; stop now.
+               // This happens in the cmd/asm tests,
+               // each of which re-initializes the arch.
+               return
+       }
+
        for i := 0; i < C_NCLASS; i++ {
                for n := 0; n < C_NCLASS; n++ {
                        if cmp(n, i) {
index 3815db51fc9eb052ca7958584e955681e2cc7eba..4e9935dce728721a44aca072352c3bb044d9db8f 100644 (file)
@@ -715,6 +715,7 @@ var unaryDst = map[obj.As]bool{
 
 var Links390x = obj.LinkArch{
        Arch:       sys.ArchS390X,
+       Init:       buildop,
        Preprocess: preprocess,
        Assemble:   spanz,
        Progedit:   progedit,
index 8e372709d35973c028d6cf518e88d520fe5b1863..3fd5052e65ed07bb5808ed09fbf68740259aba83 100644 (file)
@@ -883,8 +883,8 @@ var ymmxmm0f38 = []ytab{
  * two values match the Ytypes of the p->from and p->to operands.  The function
  * oclass in span.c computes the specific Ytype of an operand and then the set
  * of more general Ytypes that it satisfies is implied by the ycover table, set
- * up in InstInit.  For example, oclass distinguishes the constants 0 and 1
- * from the more general 8-bit constants, but InstInit says
+ * up in instinit.  For example, oclass distinguishes the constants 0 and 1
+ * from the more general 8-bit constants, but instinit says
  *
  *        ycover[Yi0*Ymax + Ys32] = 1;
  *        ycover[Yi1*Ymax + Ys32] = 1;
@@ -1768,7 +1768,7 @@ func span6(ctxt *obj.Link, s *obj.LSym, newprog obj.ProgAlloc) {
        }
 
        if ycover[0] == 0 {
-               ctxt.Diag("x86 tables not initialized, call x86.InstInit first")
+               ctxt.Diag("x86 tables not initialized, call x86.instinit first")
        }
 
        var asmbuf AsmBuf
@@ -1965,7 +1965,7 @@ func span6(ctxt *obj.Link, s *obj.LSym, newprog obj.ProgAlloc) {
        }
 }
 
-func InstInit() {
+func instinit(ctxt *obj.Link) {
        if ycover[0] != 0 {
                // Already initialized; stop now.
                // This happens in the cmd/asm tests,
@@ -1976,7 +1976,7 @@ func InstInit() {
        for i := 1; optab[i].as != 0; i++ {
                c := optab[i].as
                if opindex[c&obj.AMask] != nil {
-                       log.Fatalf("phase error in optab: %d (%v)", i, c)
+                       ctxt.Diag("phase error in optab: %d (%v)", i, c)
                }
                opindex[c&obj.AMask] = &optab[i]
        }
index 29ec849893f7faf6cce2eb4b3d1e7ae7893be917..54c7a53829e1db042b81daab675bf490e59aeb16 100644 (file)
@@ -1234,6 +1234,7 @@ var unaryDst = map[obj.As]bool{
 
 var Linkamd64 = obj.LinkArch{
        Arch:       sys.ArchAMD64,
+       Init:       instinit,
        Preprocess: preprocess,
        Assemble:   span6,
        Progedit:   progedit,
@@ -1242,6 +1243,7 @@ var Linkamd64 = obj.LinkArch{
 
 var Linkamd64p32 = obj.LinkArch{
        Arch:       sys.ArchAMD64P32,
+       Init:       instinit,
        Preprocess: preprocess,
        Assemble:   span6,
        Progedit:   progedit,
@@ -1250,6 +1252,7 @@ var Linkamd64p32 = obj.LinkArch{
 
 var Link386 = obj.LinkArch{
        Arch:       sys.Arch386,
+       Init:       instinit,
        Preprocess: preprocess,
        Assemble:   span6,
        Progedit:   progedit,