Commit 63c1aff6 authored by Josh Bleecher Snyder's avatar Josh Bleecher Snyder

cmd/internal/obj: eagerly initialize assemblers

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: default avatarBrad Fitzpatrick <bradfitz@golang.org>
parent 817c1023
......@@ -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,
......
......@@ -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)
......
......@@ -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 {
......
......@@ -27,6 +27,4 @@ func Init(arch *gc.Arch) {
arch.SSAMarkMoves = ssaMarkMoves
arch.SSAGenValue = ssaGenValue
arch.SSAGenBlock = ssaGenBlock
x86.InstInit()
}
......@@ -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 {
......
......@@ -33,6 +33,4 @@ func Init(arch *gc.Arch) {
arch.Ginsnop = ginsnop
arch.SSAMarkMoves = ssaMarkMoves
x86.InstInit()
}
......@@ -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++ {
......
......@@ -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,
......
......@@ -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++ {
......
......@@ -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,
......
......@@ -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)
......
......@@ -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++ {
......
......@@ -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,
......
......@@ -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++ {
......
......@@ -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,
......
......@@ -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) {
......
......@@ -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,
......
......@@ -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]
}
......
......@@ -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,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment