mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00: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
7 changed files with 30 additions and 40 deletions
|
|
@ -748,7 +748,6 @@ type Link struct {
|
||||||
Pc int64
|
Pc int64
|
||||||
DiagFunc func(string, ...interface{})
|
DiagFunc func(string, ...interface{})
|
||||||
DebugInfo func(fn *LSym) []*dwarf.Var
|
DebugInfo func(fn *LSym) []*dwarf.Var
|
||||||
Mode int
|
|
||||||
Cursym *LSym
|
Cursym *LSym
|
||||||
Version int
|
Version int
|
||||||
Errors int
|
Errors int
|
||||||
|
|
|
||||||
|
|
@ -29,7 +29,10 @@
|
||||||
|
|
||||||
package mips
|
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
|
//go:generate go run ../stringer.go -i $GOFILE -o anames.go -p mips
|
||||||
|
|
||||||
|
|
@ -218,8 +221,8 @@ const (
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
Mips32 = 32
|
Mips32 = sys.MIPS
|
||||||
Mips64 = 64
|
Mips64 = sys.MIPS64
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
|
|
||||||
|
|
@ -31,6 +31,7 @@ package mips
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"cmd/internal/obj"
|
"cmd/internal/obj"
|
||||||
|
"cmd/internal/sys"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"sort"
|
"sort"
|
||||||
|
|
@ -47,14 +48,14 @@ const (
|
||||||
)
|
)
|
||||||
|
|
||||||
type Optab struct {
|
type Optab struct {
|
||||||
as obj.As
|
as obj.As
|
||||||
a1 uint8
|
a1 uint8
|
||||||
a2 uint8
|
a2 uint8
|
||||||
a3 uint8
|
a3 uint8
|
||||||
type_ int8
|
type_ int8
|
||||||
size int8
|
size int8
|
||||||
param int16
|
param int16
|
||||||
mode int
|
family sys.ArchFamily // 0 means both Mips32 and Mips64
|
||||||
}
|
}
|
||||||
|
|
||||||
var optab = []Optab{
|
var optab = []Optab{
|
||||||
|
|
@ -465,7 +466,7 @@ func span0(ctxt *obj.Link, cursym *obj.LSym) {
|
||||||
|
|
||||||
cursym.Size = c
|
cursym.Size = c
|
||||||
}
|
}
|
||||||
if ctxt.Mode&Mips64 != 0 {
|
if ctxt.Arch.Family == sys.MIPS64 {
|
||||||
c += -c & (mips64FuncAlign - 1)
|
c += -c & (mips64FuncAlign - 1)
|
||||||
}
|
}
|
||||||
cursym.Size = c
|
cursym.Size = c
|
||||||
|
|
@ -702,7 +703,7 @@ func oplook(ctxt *obj.Link, p *obj.Prog) *Optab {
|
||||||
c3 := &xcmp[a3]
|
c3 := &xcmp[a3]
|
||||||
for i := range ops {
|
for i := range ops {
|
||||||
op := &ops[i]
|
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)
|
p.Optab = uint16(cap(optab) - cap(ops) + i + 1)
|
||||||
return op
|
return op
|
||||||
}
|
}
|
||||||
|
|
@ -1068,7 +1069,7 @@ func asmout(ctxt *obj.Link, p *obj.Prog, o *Optab, out []uint32) {
|
||||||
|
|
||||||
add := AADDU
|
add := AADDU
|
||||||
|
|
||||||
if ctxt.Mode&Mips64 != 0 {
|
if ctxt.Arch.Family == sys.MIPS64 {
|
||||||
add = AADDVU
|
add = AADDVU
|
||||||
}
|
}
|
||||||
switch o.type_ {
|
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 */
|
case 1: /* mov r1,r2 ==> OR r1,r0,r2 */
|
||||||
a := AOR
|
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
|
a = AADDU // sign-extended to high 32 bits
|
||||||
}
|
}
|
||||||
o1 = OP_RRR(oprrr(ctxt, a), uint32(REGZERO), uint32(p.From.Reg), uint32(p.To.Reg))
|
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) {
|
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.From.Class = 0
|
||||||
p.To.Class = 0
|
p.To.Class = 0
|
||||||
|
|
||||||
|
|
@ -89,7 +77,7 @@ func progedit(ctxt *obj.Link, p *obj.Prog) {
|
||||||
case AMOVD:
|
case AMOVD:
|
||||||
if p.From.Type == obj.TYPE_FCONST {
|
if p.From.Type == obj.TYPE_FCONST {
|
||||||
i64 := math.Float64bits(p.From.Val.(float64))
|
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.As = AMOVV
|
||||||
p.From.Type = obj.TYPE_REG
|
p.From.Type = obj.TYPE_REG
|
||||||
p.From.Reg = REGZERO
|
p.From.Reg = REGZERO
|
||||||
|
|
@ -285,7 +273,7 @@ func preprocess(ctxt *obj.Link, cursym *obj.LSym) {
|
||||||
}
|
}
|
||||||
|
|
||||||
var mov, add obj.As
|
var mov, add obj.As
|
||||||
if ctxt.Mode&Mips64 != 0 {
|
if ctxt.Arch.Family == sys.MIPS64 {
|
||||||
add = AADDV
|
add = AADDV
|
||||||
mov = AMOVV
|
mov = AMOVV
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -303,7 +291,7 @@ func preprocess(ctxt *obj.Link, cursym *obj.LSym) {
|
||||||
autosize = int32(textstksiz + ctxt.FixedFrameSize())
|
autosize = int32(textstksiz + ctxt.FixedFrameSize())
|
||||||
if (p.Mark&LEAF != 0) && autosize <= int32(ctxt.FixedFrameSize()) {
|
if (p.Mark&LEAF != 0) && autosize <= int32(ctxt.FixedFrameSize()) {
|
||||||
autosize = 0
|
autosize = 0
|
||||||
} else if autosize&4 != 0 && ctxt.Mode&Mips64 != 0 {
|
} else if autosize&4 != 0 && ctxt.Arch.Family == sys.MIPS64 {
|
||||||
autosize += 4
|
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
|
// rewrite MOVD into two MOVF in 32-bit mode to avoid unaligned memory access
|
||||||
for p = cursym.Text; p != nil; p = p1 {
|
for p = cursym.Text; p != nil; p = p1 {
|
||||||
p1 = p.Link
|
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
|
var mov, add, sub obj.As
|
||||||
|
|
||||||
if ctxt.Mode&Mips64 != 0 {
|
if ctxt.Arch.Family == sys.MIPS64 {
|
||||||
add = AADDV
|
add = AADDV
|
||||||
mov = AMOVV
|
mov = AMOVV
|
||||||
sub = ASUBVU
|
sub = ASUBVU
|
||||||
|
|
|
||||||
|
|
@ -32,6 +32,7 @@ package x86
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"cmd/internal/obj"
|
"cmd/internal/obj"
|
||||||
|
"cmd/internal/sys"
|
||||||
"encoding/binary"
|
"encoding/binary"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"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 {
|
if ycover[ft+int(yt.from)] != 0 && ycover[f3t+int(yt.from3)] != 0 && ycover[tt+int(yt.to)] != 0 {
|
||||||
switch o.prefix {
|
switch o.prefix {
|
||||||
case Px1: /* first option valid only in 32-bit mode */
|
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
|
z += int(yt.zoffset) + xo
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -73,11 +73,8 @@ func CanUse1InsnTLS(ctxt *obj.Link) bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
func progedit(ctxt *obj.Link, p *obj.Prog) {
|
func progedit(ctxt *obj.Link, p *obj.Prog) {
|
||||||
// Maintain information about code generation mode.
|
// TODO(josharian): eliminate Prog.Mode
|
||||||
if ctxt.Mode == 0 {
|
p.Mode = int8(ctxt.Arch.RegSize * 8)
|
||||||
ctxt.Mode = ctxt.Arch.RegSize * 8
|
|
||||||
}
|
|
||||||
p.Mode = int8(ctxt.Mode)
|
|
||||||
|
|
||||||
// Thread-local storage references use the TLS pseudo-register.
|
// Thread-local storage references use the TLS pseudo-register.
|
||||||
// As a register, TLS refers to the thread-local storage base, and it
|
// As a register, TLS refers to the thread-local storage base, and it
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,8 @@ import "encoding/binary"
|
||||||
type ArchFamily byte
|
type ArchFamily byte
|
||||||
|
|
||||||
const (
|
const (
|
||||||
AMD64 ArchFamily = iota
|
NoArch ArchFamily = iota
|
||||||
|
AMD64
|
||||||
ARM
|
ARM
|
||||||
ARM64
|
ARM64
|
||||||
I386
|
I386
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue