mirror of
https://github.com/golang/go
synced 2024-11-18 08:04:40 -07:00
cmd/internal/obj: eliminate Ctxt.Mode
Replace Ctxt.Mode with a method, Ctxt.RegWidth, which is calculated directly off the arch info. I believe that Prog.Mode can also be removed; future CL. This is a step towards obj.Link immutability. Passes toolstash-check -all. Updates #15756 Change-Id: Ifd7f8f6ed0a2fdc032d1dd306fcd695a14aa5bc5 Reviewed-on: https://go-review.googlesource.com/38446 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Cherry Zhang <cherryyz@google.com>
This commit is contained in:
parent
0a94daa378
commit
a470e5d4b8
@ -748,7 +748,6 @@ type Link struct {
|
||||
Pc int64
|
||||
DiagFunc func(string, ...interface{})
|
||||
DebugInfo func(fn *LSym) []*dwarf.Var
|
||||
Mode int
|
||||
Cursym *LSym
|
||||
Version int
|
||||
Errors int
|
||||
|
@ -29,7 +29,10 @@
|
||||
|
||||
package mips
|
||||
|
||||
import "cmd/internal/obj"
|
||||
import (
|
||||
"cmd/internal/obj"
|
||||
"cmd/internal/sys"
|
||||
)
|
||||
|
||||
//go:generate go run ../stringer.go -i $GOFILE -o anames.go -p mips
|
||||
|
||||
@ -218,8 +221,8 @@ const (
|
||||
)
|
||||
|
||||
const (
|
||||
Mips32 = 32
|
||||
Mips64 = 64
|
||||
Mips32 = sys.MIPS
|
||||
Mips64 = sys.MIPS64
|
||||
)
|
||||
|
||||
const (
|
||||
|
@ -31,6 +31,7 @@ package mips
|
||||
|
||||
import (
|
||||
"cmd/internal/obj"
|
||||
"cmd/internal/sys"
|
||||
"fmt"
|
||||
"log"
|
||||
"sort"
|
||||
@ -47,14 +48,14 @@ const (
|
||||
)
|
||||
|
||||
type Optab struct {
|
||||
as obj.As
|
||||
a1 uint8
|
||||
a2 uint8
|
||||
a3 uint8
|
||||
type_ int8
|
||||
size int8
|
||||
param int16
|
||||
mode int
|
||||
as obj.As
|
||||
a1 uint8
|
||||
a2 uint8
|
||||
a3 uint8
|
||||
type_ int8
|
||||
size int8
|
||||
param int16
|
||||
family sys.ArchFamily // 0 means both Mips32 and Mips64
|
||||
}
|
||||
|
||||
var optab = []Optab{
|
||||
@ -465,7 +466,7 @@ func span0(ctxt *obj.Link, cursym *obj.LSym) {
|
||||
|
||||
cursym.Size = c
|
||||
}
|
||||
if ctxt.Mode&Mips64 != 0 {
|
||||
if ctxt.Arch.Family == sys.MIPS64 {
|
||||
c += -c & (mips64FuncAlign - 1)
|
||||
}
|
||||
cursym.Size = c
|
||||
@ -702,7 +703,7 @@ func oplook(ctxt *obj.Link, p *obj.Prog) *Optab {
|
||||
c3 := &xcmp[a3]
|
||||
for i := range ops {
|
||||
op := &ops[i]
|
||||
if int(op.a2) == a2 && c1[op.a1] && c3[op.a3] && (ctxt.Mode&op.mode == op.mode) {
|
||||
if int(op.a2) == a2 && c1[op.a1] && c3[op.a3] && (op.family == 0 || ctxt.Arch.Family == op.family) {
|
||||
p.Optab = uint16(cap(optab) - cap(ops) + i + 1)
|
||||
return op
|
||||
}
|
||||
@ -1068,7 +1069,7 @@ func asmout(ctxt *obj.Link, p *obj.Prog, o *Optab, out []uint32) {
|
||||
|
||||
add := AADDU
|
||||
|
||||
if ctxt.Mode&Mips64 != 0 {
|
||||
if ctxt.Arch.Family == sys.MIPS64 {
|
||||
add = AADDVU
|
||||
}
|
||||
switch o.type_ {
|
||||
@ -1081,7 +1082,7 @@ func asmout(ctxt *obj.Link, p *obj.Prog, o *Optab, out []uint32) {
|
||||
|
||||
case 1: /* mov r1,r2 ==> OR r1,r0,r2 */
|
||||
a := AOR
|
||||
if p.As == AMOVW && ctxt.Mode&Mips64 != 0 {
|
||||
if p.As == AMOVW && ctxt.Arch.Family == sys.MIPS64 {
|
||||
a = AADDU // sign-extended to high 32 bits
|
||||
}
|
||||
o1 = OP_RRR(oprrr(ctxt, a), uint32(REGZERO), uint32(p.From.Reg), uint32(p.To.Reg))
|
||||
|
@ -38,18 +38,6 @@ import (
|
||||
)
|
||||
|
||||
func progedit(ctxt *obj.Link, p *obj.Prog) {
|
||||
// Maintain information about code generation mode.
|
||||
if ctxt.Mode == 0 {
|
||||
switch ctxt.Arch.Family {
|
||||
default:
|
||||
ctxt.Diag("unsupported arch family")
|
||||
case sys.MIPS:
|
||||
ctxt.Mode = Mips32
|
||||
case sys.MIPS64:
|
||||
ctxt.Mode = Mips64
|
||||
}
|
||||
}
|
||||
|
||||
p.From.Class = 0
|
||||
p.To.Class = 0
|
||||
|
||||
@ -89,7 +77,7 @@ func progedit(ctxt *obj.Link, p *obj.Prog) {
|
||||
case AMOVD:
|
||||
if p.From.Type == obj.TYPE_FCONST {
|
||||
i64 := math.Float64bits(p.From.Val.(float64))
|
||||
if i64 == 0 && ctxt.Mode&Mips64 != 0 {
|
||||
if i64 == 0 && ctxt.Arch.Family == sys.MIPS64 {
|
||||
p.As = AMOVV
|
||||
p.From.Type = obj.TYPE_REG
|
||||
p.From.Reg = REGZERO
|
||||
@ -285,7 +273,7 @@ func preprocess(ctxt *obj.Link, cursym *obj.LSym) {
|
||||
}
|
||||
|
||||
var mov, add obj.As
|
||||
if ctxt.Mode&Mips64 != 0 {
|
||||
if ctxt.Arch.Family == sys.MIPS64 {
|
||||
add = AADDV
|
||||
mov = AMOVV
|
||||
} else {
|
||||
@ -303,7 +291,7 @@ func preprocess(ctxt *obj.Link, cursym *obj.LSym) {
|
||||
autosize = int32(textstksiz + ctxt.FixedFrameSize())
|
||||
if (p.Mark&LEAF != 0) && autosize <= int32(ctxt.FixedFrameSize()) {
|
||||
autosize = 0
|
||||
} else if autosize&4 != 0 && ctxt.Mode&Mips64 != 0 {
|
||||
} else if autosize&4 != 0 && ctxt.Arch.Family == sys.MIPS64 {
|
||||
autosize += 4
|
||||
}
|
||||
|
||||
@ -534,7 +522,7 @@ func preprocess(ctxt *obj.Link, cursym *obj.LSym) {
|
||||
}
|
||||
}
|
||||
|
||||
if ctxt.Mode&Mips32 != 0 {
|
||||
if ctxt.Arch.Family == sys.MIPS {
|
||||
// rewrite MOVD into two MOVF in 32-bit mode to avoid unaligned memory access
|
||||
for p = cursym.Text; p != nil; p = p1 {
|
||||
p1 = p.Link
|
||||
@ -633,7 +621,7 @@ func stacksplit(ctxt *obj.Link, p *obj.Prog, framesize int32) *obj.Prog {
|
||||
|
||||
var mov, add, sub obj.As
|
||||
|
||||
if ctxt.Mode&Mips64 != 0 {
|
||||
if ctxt.Arch.Family == sys.MIPS64 {
|
||||
add = AADDV
|
||||
mov = AMOVV
|
||||
sub = ASUBVU
|
||||
|
@ -32,6 +32,7 @@ package x86
|
||||
|
||||
import (
|
||||
"cmd/internal/obj"
|
||||
"cmd/internal/sys"
|
||||
"encoding/binary"
|
||||
"fmt"
|
||||
"log"
|
||||
@ -3299,7 +3300,7 @@ func doasm(ctxt *obj.Link, p *obj.Prog) {
|
||||
if ycover[ft+int(yt.from)] != 0 && ycover[f3t+int(yt.from3)] != 0 && ycover[tt+int(yt.to)] != 0 {
|
||||
switch o.prefix {
|
||||
case Px1: /* first option valid only in 32-bit mode */
|
||||
if ctxt.Mode == 64 && z == 0 {
|
||||
if ctxt.Arch.Family == sys.AMD64 && z == 0 {
|
||||
z += int(yt.zoffset) + xo
|
||||
continue
|
||||
}
|
||||
|
@ -73,11 +73,8 @@ func CanUse1InsnTLS(ctxt *obj.Link) bool {
|
||||
}
|
||||
|
||||
func progedit(ctxt *obj.Link, p *obj.Prog) {
|
||||
// Maintain information about code generation mode.
|
||||
if ctxt.Mode == 0 {
|
||||
ctxt.Mode = ctxt.Arch.RegSize * 8
|
||||
}
|
||||
p.Mode = int8(ctxt.Mode)
|
||||
// TODO(josharian): eliminate Prog.Mode
|
||||
p.Mode = int8(ctxt.Arch.RegSize * 8)
|
||||
|
||||
// Thread-local storage references use the TLS pseudo-register.
|
||||
// As a register, TLS refers to the thread-local storage base, and it
|
||||
|
@ -12,7 +12,8 @@ import "encoding/binary"
|
||||
type ArchFamily byte
|
||||
|
||||
const (
|
||||
AMD64 ArchFamily = iota
|
||||
NoArch ArchFamily = iota
|
||||
AMD64
|
||||
ARM
|
||||
ARM64
|
||||
I386
|
||||
|
Loading…
Reference in New Issue
Block a user