Skip to content

Commit

Permalink
[dev.regabi] cmd/compile: group known symbols, packages, names [gener…
Browse files Browse the repository at this point in the history
…ated]

There are a handful of pre-computed magic symbols known by
package gc, and we need a place to store them.

If we keep them together, the need for type *ir.Name means that
package ir is the lowest package in the import hierarchy that they
can go in. And package ir needs gopkg for methodSymSuffix
(in a later CL), so they can't go any higher either, at least not all together.
So package ir it is.

Rather than dump them all into the top-level package ir
namespace, however, we introduce global structs, Syms, Pkgs, and Names,
and make the known symbols, packages, and names fields of those.

[git-generate]
cd src/cmd/compile/internal/gc

rf '
	add go.go:$ \
		// Names holds known names. \
		var Names struct{} \
		\
		// Syms holds known symbols. \
		var Syms struct {} \
		\
		// Pkgs holds known packages. \
		var Pkgs struct {} \

	mv staticuint64s Names.Staticuint64s
	mv zerobase Names.Zerobase

	mv assertE2I Syms.AssertE2I
	mv assertE2I2 Syms.AssertE2I2
	mv assertI2I Syms.AssertI2I
	mv assertI2I2 Syms.AssertI2I2
	mv deferproc Syms.Deferproc
	mv deferprocStack Syms.DeferprocStack
	mv Deferreturn Syms.Deferreturn
	mv Duffcopy Syms.Duffcopy
	mv Duffzero Syms.Duffzero
	mv gcWriteBarrier Syms.GCWriteBarrier
	mv goschedguarded Syms.Goschedguarded
	mv growslice Syms.Growslice
	mv msanread Syms.Msanread
	mv msanwrite Syms.Msanwrite
	mv msanmove Syms.Msanmove
	mv newobject Syms.Newobject
	mv newproc Syms.Newproc
	mv panicdivide Syms.Panicdivide
	mv panicshift Syms.Panicshift
	mv panicdottypeE Syms.PanicdottypeE
	mv panicdottypeI Syms.PanicdottypeI
	mv panicnildottype Syms.Panicnildottype
	mv panicoverflow Syms.Panicoverflow
	mv raceread Syms.Raceread
	mv racereadrange Syms.Racereadrange
	mv racewrite Syms.Racewrite
	mv racewriterange Syms.Racewriterange
	mv SigPanic Syms.SigPanic
	mv typedmemclr Syms.Typedmemclr
	mv typedmemmove Syms.Typedmemmove
	mv Udiv Syms.Udiv
	mv writeBarrier Syms.WriteBarrier
	mv zerobaseSym Syms.Zerobase
	mv arm64HasATOMICS Syms.ARM64HasATOMICS
	mv armHasVFPv4 Syms.ARMHasVFPv4
	mv x86HasFMA Syms.X86HasFMA
	mv x86HasPOPCNT Syms.X86HasPOPCNT
	mv x86HasSSE41 Syms.X86HasSSE41
	mv WasmDiv Syms.WasmDiv
	mv WasmMove Syms.WasmMove
	mv WasmZero Syms.WasmZero
	mv WasmTruncS Syms.WasmTruncS
	mv WasmTruncU Syms.WasmTruncU

	mv gopkg Pkgs.Go
	mv itabpkg Pkgs.Itab
	mv itablinkpkg Pkgs.Itablink
	mv mappkg Pkgs.Map
	mv msanpkg Pkgs.Msan
	mv racepkg Pkgs.Race
	mv Runtimepkg Pkgs.Runtime
	mv trackpkg Pkgs.Track
	mv unsafepkg Pkgs.Unsafe

	mv Names Syms Pkgs symtab.go
	mv symtab.go cmd/compile/internal/ir
'

Change-Id: Ic143862148569a3bcde8e70b26d75421aa2d00f3
Reviewed-on: https://go-review.googlesource.com/c/go/+/279235
Trust: Russ Cox <rsc@golang.org>
Run-TryBot: Russ Cox <rsc@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
  • Loading branch information
rsc committed Dec 23, 2020
1 parent 9ee3092 commit 65c4c6d
Show file tree
Hide file tree
Showing 29 changed files with 255 additions and 231 deletions.
3 changes: 2 additions & 1 deletion src/cmd/compile/internal/amd64/ggen.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ package amd64
import (
"cmd/compile/internal/base"
"cmd/compile/internal/gc"
"cmd/compile/internal/ir"
"cmd/internal/obj"
"cmd/internal/obj/x86"
"cmd/internal/objabi"
Expand Down Expand Up @@ -102,7 +103,7 @@ func zerorange(pp *gc.Progs, p *obj.Prog, off, cnt int64, state *uint32) *obj.Pr
}
p = pp.Appendpp(p, leaptr, obj.TYPE_MEM, x86.REG_SP, off+dzDI(cnt), obj.TYPE_REG, x86.REG_DI, 0)
p = pp.Appendpp(p, obj.ADUFFZERO, obj.TYPE_NONE, 0, 0, obj.TYPE_ADDR, 0, dzOff(cnt))
p.To.Sym = gc.Duffzero
p.To.Sym = ir.Syms.Duffzero

if cnt%16 != 0 {
p = pp.Appendpp(p, x86.AMOVUPS, obj.TYPE_REG, x86.REG_X0, 0, obj.TYPE_MEM, x86.REG_DI, -int64(8))
Expand Down
5 changes: 3 additions & 2 deletions src/cmd/compile/internal/amd64/ssa.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (

"cmd/compile/internal/base"
"cmd/compile/internal/gc"
"cmd/compile/internal/ir"
"cmd/compile/internal/logopt"
"cmd/compile/internal/ssa"
"cmd/compile/internal/types"
Expand Down Expand Up @@ -912,7 +913,7 @@ func ssaGenValue(s *gc.SSAGenState, v *ssa.Value) {
}
p = s.Prog(obj.ADUFFZERO)
p.To.Type = obj.TYPE_ADDR
p.To.Sym = gc.Duffzero
p.To.Sym = ir.Syms.Duffzero
p.To.Offset = off
case ssa.OpAMD64MOVOconst:
if v.AuxInt != 0 {
Expand All @@ -923,7 +924,7 @@ func ssaGenValue(s *gc.SSAGenState, v *ssa.Value) {
case ssa.OpAMD64DUFFCOPY:
p := s.Prog(obj.ADUFFCOPY)
p.To.Type = obj.TYPE_ADDR
p.To.Sym = gc.Duffcopy
p.To.Sym = ir.Syms.Duffcopy
if v.AuxInt%16 != 0 {
v.Fatalf("bad DUFFCOPY AuxInt %v", v.AuxInt)
}
Expand Down
3 changes: 2 additions & 1 deletion src/cmd/compile/internal/arm/ggen.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package arm

import (
"cmd/compile/internal/gc"
"cmd/compile/internal/ir"
"cmd/internal/obj"
"cmd/internal/obj/arm"
)
Expand All @@ -28,7 +29,7 @@ func zerorange(pp *gc.Progs, p *obj.Prog, off, cnt int64, r0 *uint32) *obj.Prog
p.Reg = arm.REGSP
p = pp.Appendpp(p, obj.ADUFFZERO, obj.TYPE_NONE, 0, 0, obj.TYPE_MEM, 0, 0)
p.To.Name = obj.NAME_EXTERN
p.To.Sym = gc.Duffzero
p.To.Sym = ir.Syms.Duffzero
p.To.Offset = 4 * (128 - cnt/int64(gc.Widthptr))
} else {
p = pp.Appendpp(p, arm.AADD, obj.TYPE_CONST, 0, 4+off, obj.TYPE_REG, arm.REG_R1, 0)
Expand Down
6 changes: 3 additions & 3 deletions src/cmd/compile/internal/arm/ssa.go
Original file line number Diff line number Diff line change
Expand Up @@ -702,7 +702,7 @@ func ssaGenValue(s *gc.SSAGenState, v *ssa.Value) {
p := s.Prog(obj.ACALL)
p.To.Type = obj.TYPE_MEM
p.To.Name = obj.NAME_EXTERN
p.To.Sym = gc.Udiv
p.To.Sym = ir.Syms.Udiv
case ssa.OpARMLoweredWB:
p := s.Prog(obj.ACALL)
p.To.Type = obj.TYPE_MEM
Expand All @@ -724,13 +724,13 @@ func ssaGenValue(s *gc.SSAGenState, v *ssa.Value) {
p := s.Prog(obj.ADUFFZERO)
p.To.Type = obj.TYPE_MEM
p.To.Name = obj.NAME_EXTERN
p.To.Sym = gc.Duffzero
p.To.Sym = ir.Syms.Duffzero
p.To.Offset = v.AuxInt
case ssa.OpARMDUFFCOPY:
p := s.Prog(obj.ADUFFCOPY)
p.To.Type = obj.TYPE_MEM
p.To.Name = obj.NAME_EXTERN
p.To.Sym = gc.Duffcopy
p.To.Sym = ir.Syms.Duffcopy
p.To.Offset = v.AuxInt
case ssa.OpARMLoweredNilCheck:
// Issue a load which will fault if arg is nil.
Expand Down
3 changes: 2 additions & 1 deletion src/cmd/compile/internal/arm64/ggen.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package arm64

import (
"cmd/compile/internal/gc"
"cmd/compile/internal/ir"
"cmd/internal/obj"
"cmd/internal/obj/arm64"
"cmd/internal/objabi"
Expand Down Expand Up @@ -41,7 +42,7 @@ func zerorange(pp *gc.Progs, p *obj.Prog, off, cnt int64, _ *uint32) *obj.Prog {
p.Reg = arm64.REG_R20
p = pp.Appendpp(p, obj.ADUFFZERO, obj.TYPE_NONE, 0, 0, obj.TYPE_MEM, 0, 0)
p.To.Name = obj.NAME_EXTERN
p.To.Sym = gc.Duffzero
p.To.Sym = ir.Syms.Duffzero
p.To.Offset = 4 * (64 - cnt/(2*int64(gc.Widthptr)))
} else {
// Not using REGTMP, so this is async preemptible (async preemption clobbers REGTMP).
Expand Down
4 changes: 2 additions & 2 deletions src/cmd/compile/internal/arm64/ssa.go
Original file line number Diff line number Diff line change
Expand Up @@ -961,7 +961,7 @@ func ssaGenValue(s *gc.SSAGenState, v *ssa.Value) {
p := s.Prog(obj.ADUFFZERO)
p.To.Type = obj.TYPE_MEM
p.To.Name = obj.NAME_EXTERN
p.To.Sym = gc.Duffzero
p.To.Sym = ir.Syms.Duffzero
p.To.Offset = v.AuxInt
case ssa.OpARM64LoweredZero:
// STP.P (ZR,ZR), 16(R16)
Expand All @@ -987,7 +987,7 @@ func ssaGenValue(s *gc.SSAGenState, v *ssa.Value) {
p := s.Prog(obj.ADUFFCOPY)
p.To.Type = obj.TYPE_MEM
p.To.Name = obj.NAME_EXTERN
p.To.Sym = gc.Duffcopy
p.To.Sym = ir.Syms.Duffcopy
p.To.Offset = v.AuxInt
case ssa.OpARM64LoweredMove:
// MOVD.P 8(R16), Rtmp
Expand Down
14 changes: 7 additions & 7 deletions src/cmd/compile/internal/gc/alg.go
Original file line number Diff line number Diff line change
Expand Up @@ -265,19 +265,19 @@ func hashfor(t *types.Type) ir.Node {
case types.AMEM:
base.Fatalf("hashfor with AMEM type")
case types.AINTER:
sym = Runtimepkg.Lookup("interhash")
sym = ir.Pkgs.Runtime.Lookup("interhash")
case types.ANILINTER:
sym = Runtimepkg.Lookup("nilinterhash")
sym = ir.Pkgs.Runtime.Lookup("nilinterhash")
case types.ASTRING:
sym = Runtimepkg.Lookup("strhash")
sym = ir.Pkgs.Runtime.Lookup("strhash")
case types.AFLOAT32:
sym = Runtimepkg.Lookup("f32hash")
sym = ir.Pkgs.Runtime.Lookup("f32hash")
case types.AFLOAT64:
sym = Runtimepkg.Lookup("f64hash")
sym = ir.Pkgs.Runtime.Lookup("f64hash")
case types.ACPLX64:
sym = Runtimepkg.Lookup("c64hash")
sym = ir.Pkgs.Runtime.Lookup("c64hash")
case types.ACPLX128:
sym = Runtimepkg.Lookup("c128hash")
sym = ir.Pkgs.Runtime.Lookup("c128hash")
default:
// Note: the caller of hashfor ensured that this symbol
// exists and has a body by calling genhash for t.
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/compile/internal/gc/dcl.go
Original file line number Diff line number Diff line change
Expand Up @@ -626,7 +626,7 @@ func methodSymSuffix(recv *types.Type, msym *types.Sym, suffix string) *types.Sy
// Find the package the receiver type appeared in. For
// anonymous receiver types (i.e., anonymous structs with
// embedded fields), use the "go" pseudo-package instead.
rpkg := gopkg
rpkg := ir.Pkgs.Go
if rsym != nil {
rpkg = rsym.Pkg
}
Expand Down
4 changes: 2 additions & 2 deletions src/cmd/compile/internal/gc/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
// sysfunc looks up Go function name in package runtime. This function
// must follow the internal calling convention.
func sysfunc(name string) *obj.LSym {
s := Runtimepkg.Lookup(name)
s := ir.Pkgs.Runtime.Lookup(name)
s.SetFunc(true)
return s.Linksym()
}
Expand All @@ -25,7 +25,7 @@ func sysfunc(name string) *obj.LSym {
// runtime. If this is a function, it may have a special calling
// convention.
func sysvar(name string) *obj.LSym {
return Runtimepkg.Lookup(name).Linksym()
return ir.Pkgs.Runtime.Lookup(name).Linksym()
}

// isParamStackCopy reports whether this is the on-stack copy of a
Expand Down
67 changes: 0 additions & 67 deletions src/cmd/compile/internal/gc/go.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,24 +64,6 @@ var decldepth int32

var inimport bool // set during import

var itabpkg *types.Pkg // fake pkg for itab entries

var itablinkpkg *types.Pkg // fake package for runtime itab entries

var Runtimepkg *types.Pkg // fake package runtime

var racepkg *types.Pkg // package runtime/race

var msanpkg *types.Pkg // package runtime/msan

var unsafepkg *types.Pkg // package unsafe

var trackpkg *types.Pkg // fake package for field tracking

var mappkg *types.Pkg // fake package for map zero value

var gopkg *types.Pkg // pseudo-package for method symbols on anonymous receiver types

var zerosize int64

var (
Expand Down Expand Up @@ -149,57 +131,8 @@ type Arch struct {
var thearch Arch

var (
staticuint64s *ir.Name
zerobase *ir.Name

assertE2I,
assertE2I2,
assertI2I,
assertI2I2,
deferproc,
deferprocStack,
Deferreturn,
Duffcopy,
Duffzero,
gcWriteBarrier,
goschedguarded,
growslice,
msanread,
msanwrite,
msanmove,
newobject,
newproc,
panicdivide,
panicshift,
panicdottypeE,
panicdottypeI,
panicnildottype,
panicoverflow,
raceread,
racereadrange,
racewrite,
racewriterange,
x86HasPOPCNT,
x86HasSSE41,
x86HasFMA,
armHasVFPv4,
arm64HasATOMICS,
typedmemclr,
typedmemmove,
Udiv,
writeBarrier,
zerobaseSym *obj.LSym

BoundsCheckFunc [ssa.BoundsKindCount]*obj.LSym
ExtendCheckFunc [ssa.BoundsKindCount]*obj.LSym

// Wasm
WasmMove,
WasmZero,
WasmDiv,
WasmTruncS,
WasmTruncU,
SigPanic *obj.LSym
)

// GCWriteBarrierReg maps from registers to gcWriteBarrier implementation LSyms.
Expand Down
4 changes: 2 additions & 2 deletions src/cmd/compile/internal/gc/iexport.go
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ func (p *iexporter) pushDecl(n *ir.Name) {
}

// Don't export predeclared declarations.
if n.Sym().Pkg == types.BuiltinPkg || n.Sym().Pkg == unsafepkg {
if n.Sym().Pkg == types.BuiltinPkg || n.Sym().Pkg == ir.Pkgs.Unsafe {
return
}

Expand Down Expand Up @@ -647,7 +647,7 @@ func (w *exportWriter) startType(k itag) {

func (w *exportWriter) doTyp(t *types.Type) {
if t.Sym() != nil {
if t.Sym().Pkg == types.BuiltinPkg || t.Sym().Pkg == unsafepkg {
if t.Sym().Pkg == types.BuiltinPkg || t.Sym().Pkg == ir.Pkgs.Unsafe {
base.Fatalf("builtin type missing from typIndex: %v", t)
}

Expand Down
36 changes: 18 additions & 18 deletions src/cmd/compile/internal/gc/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,32 +86,32 @@ func Main(archInit func(*Arch)) {
types.BuiltinPkg.Prefix = "go.builtin" // not go%2ebuiltin

// pseudo-package, accessed by import "unsafe"
unsafepkg = types.NewPkg("unsafe", "unsafe")
ir.Pkgs.Unsafe = types.NewPkg("unsafe", "unsafe")

// Pseudo-package that contains the compiler's builtin
// declarations for package runtime. These are declared in a
// separate package to avoid conflicts with package runtime's
// actual declarations, which may differ intentionally but
// insignificantly.
Runtimepkg = types.NewPkg("go.runtime", "runtime")
Runtimepkg.Prefix = "runtime"
ir.Pkgs.Runtime = types.NewPkg("go.runtime", "runtime")
ir.Pkgs.Runtime.Prefix = "runtime"

// pseudo-packages used in symbol tables
itabpkg = types.NewPkg("go.itab", "go.itab")
itabpkg.Prefix = "go.itab" // not go%2eitab
ir.Pkgs.Itab = types.NewPkg("go.itab", "go.itab")
ir.Pkgs.Itab.Prefix = "go.itab" // not go%2eitab

itablinkpkg = types.NewPkg("go.itablink", "go.itablink")
itablinkpkg.Prefix = "go.itablink" // not go%2eitablink
ir.Pkgs.Itablink = types.NewPkg("go.itablink", "go.itablink")
ir.Pkgs.Itablink.Prefix = "go.itablink" // not go%2eitablink

trackpkg = types.NewPkg("go.track", "go.track")
trackpkg.Prefix = "go.track" // not go%2etrack
ir.Pkgs.Track = types.NewPkg("go.track", "go.track")
ir.Pkgs.Track.Prefix = "go.track" // not go%2etrack

// pseudo-package used for map zero values
mappkg = types.NewPkg("go.map", "go.map")
mappkg.Prefix = "go.map"
ir.Pkgs.Map = types.NewPkg("go.map", "go.map")
ir.Pkgs.Map.Prefix = "go.map"

// pseudo-package used for methods with anonymous receivers
gopkg = types.NewPkg("go", "")
ir.Pkgs.Go = types.NewPkg("go", "")

base.DebugSSA = ssa.PhaseOption
base.ParseFlags()
Expand Down Expand Up @@ -165,10 +165,10 @@ func Main(archInit func(*Arch)) {
thearch.LinkArch.Init(base.Ctxt)
startProfile()
if base.Flag.Race {
racepkg = types.NewPkg("runtime/race", "")
ir.Pkgs.Race = types.NewPkg("runtime/race", "")
}
if base.Flag.MSan {
msanpkg = types.NewPkg("runtime/msan", "")
ir.Pkgs.Msan = types.NewPkg("runtime/msan", "")
}
if base.Flag.Race || base.Flag.MSan {
base.Flag.Cfg.Instrumenting = true
Expand Down Expand Up @@ -592,13 +592,13 @@ func loadsys() {

typs := runtimeTypes()
for _, d := range &runtimeDecls {
sym := Runtimepkg.Lookup(d.name)
sym := ir.Pkgs.Runtime.Lookup(d.name)
typ := typs[d.typ]
switch d.tag {
case funcTag:
importfunc(Runtimepkg, src.NoXPos, sym, typ)
importfunc(ir.Pkgs.Runtime, src.NoXPos, sym, typ)
case varTag:
importvar(Runtimepkg, src.NoXPos, sym, typ)
importvar(ir.Pkgs.Runtime, src.NoXPos, sym, typ)
default:
base.Fatalf("unhandled declaration tag %v", d.tag)
}
Expand Down Expand Up @@ -647,7 +647,7 @@ func importfile(f constant.Value) *types.Pkg {
}

if path_ == "unsafe" {
return unsafepkg
return ir.Pkgs.Unsafe
}

if islocalname(path_) {
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/compile/internal/gc/noder.go
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ func (p *noder) importDecl(imp *syntax.ImportDecl) {
return
}

if ipkg == unsafepkg {
if ipkg == ir.Pkgs.Unsafe {
p.importedUnsafe = true
}
if ipkg.Path == "embed" {
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/compile/internal/gc/obj.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ func dumpdata() {
dumpglobls(Target.Externs[numExterns:])

if zerosize > 0 {
zero := mappkg.Lookup("zero")
zero := ir.Pkgs.Map.Lookup("zero")
ggloblsym(zero.Linksym(), int32(zerosize), obj.DUPOK|obj.RODATA)
}

Expand Down
4 changes: 2 additions & 2 deletions src/cmd/compile/internal/gc/plive.go
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,7 @@ func (lv *Liveness) markUnsafePoints() {
var load *ssa.Value
v := wbBlock.Controls[0]
for {
if sym, ok := v.Aux.(*obj.LSym); ok && sym == writeBarrier {
if sym, ok := v.Aux.(*obj.LSym); ok && sym == ir.Syms.WriteBarrier {
load = v
break
}
Expand Down Expand Up @@ -690,7 +690,7 @@ func (lv *Liveness) hasStackMap(v *ssa.Value) bool {
// typedmemclr and typedmemmove are write barriers and
// deeply non-preemptible. They are unsafe points and
// hence should not have liveness maps.
if sym, ok := v.Aux.(*ssa.AuxCall); ok && (sym.Fn == typedmemclr || sym.Fn == typedmemmove) {
if sym, ok := v.Aux.(*ssa.AuxCall); ok && (sym.Fn == ir.Syms.Typedmemclr || sym.Fn == ir.Syms.Typedmemmove) {
return false
}
return true
Expand Down
Loading

0 comments on commit 65c4c6d

Please sign in to comment.