1
0
mirror of https://github.com/golang/go synced 2024-11-26 02:47:58 -07:00

[dev.regabi] cmd/compile: separate misc for gc split

Misc cleanup for splitting package gc: API tweaks
and boundary adjustments.

The change in ir.NewBlockStmt makes it a drop-in
replacement for liststmt.

Change-Id: I9455fe8ccae7d71fe8ccf390ac96672389bf4f3d
Reviewed-on: https://go-review.googlesource.com/c/go/+/279305
Trust: Russ Cox <rsc@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
This commit is contained in:
Russ Cox 2020-12-21 01:20:20 -05:00
parent 572f168ed2
commit 51ba53f5c2
7 changed files with 44 additions and 21 deletions

View File

@ -143,10 +143,6 @@ type EscEdge struct {
notes *EscNote
}
func init() {
ir.EscFmt = escFmt
}
// escFmt is called from node printing to print information about escape analysis results.
func escFmt(n ir.Node) string {
text := ""

View File

@ -685,6 +685,21 @@ func (r *importReader) typeExt(t *types.Type) {
// so we can use index to reference the symbol.
var typeSymIdx = make(map[*types.Type][2]int64)
func BaseTypeIndex(t *types.Type) int64 {
tbase := t
if t.IsPtr() && t.Sym() == nil && t.Elem().Sym() != nil {
tbase = t.Elem()
}
i, ok := typeSymIdx[tbase]
if !ok {
return -1
}
if t != tbase {
return i[1]
}
return i[0]
}
func (r *importReader) doInline(fn *ir.Func) {
if len(fn.Inl.Body) != 0 {
base.Fatalf("%v already has inline body", fn)

View File

@ -54,9 +54,6 @@ func hidePanic() {
// Target is the package being compiled.
var Target *ir.Package
// timing data for compiler phases
var timings Timings
// Main parses flags and Go source files specified in the command-line
// arguments, type-checks the parsed Go package, compiles functions to machine
// code, and finally writes the compiled package definition to disk.
@ -189,6 +186,7 @@ func Main(archInit func(*Arch)) {
logopt.LogJsonOption(base.Flag.JSON)
}
ir.EscFmt = escFmt
IsIntrinsicCall = isIntrinsicCall
SSADumpInline = ssaDumpInline
initSSAEnv()
@ -962,9 +960,11 @@ type lang struct {
// any language version is supported.
var langWant lang
// langSupported reports whether language version major.minor is
// supported in a particular package.
func langSupported(major, minor int, pkg *types.Pkg) bool {
// AllowsGoVersion reports whether a particular package
// is allowed to use Go version major.minor.
// We assume the imported packages have all been checked,
// so we only have to check the local package against the -lang flag.
func AllowsGoVersion(pkg *types.Pkg, major, minor int) bool {
if pkg == nil {
// TODO(mdempsky): Set Pkg for local types earlier.
pkg = types.LocalPkg
@ -973,13 +973,16 @@ func langSupported(major, minor int, pkg *types.Pkg) bool {
// Assume imported packages passed type-checking.
return true
}
if langWant.major == 0 && langWant.minor == 0 {
return true
}
return langWant.major > major || (langWant.major == major && langWant.minor >= minor)
}
func langSupported(major, minor int, pkg *types.Pkg) bool {
return AllowsGoVersion(pkg, major, minor)
}
// checkLang verifies that the -lang flag holds a valid value, and
// exits if not. It initializes data used by langSupported.
func checkLang() {

View File

@ -127,8 +127,7 @@ func dumpdata() {
addsignats(Target.Externs)
dumpsignats()
dumptabs()
ptabsLen := len(ptabs)
itabsLen := len(itabs)
numPTabs, numITabs := CountTabs()
dumpimportstrings()
dumpbasictypes()
dumpembeds()
@ -168,10 +167,11 @@ func dumpdata() {
if numExports != len(Target.Exports) {
base.Fatalf("Target.Exports changed after compile functions loop")
}
if ptabsLen != len(ptabs) {
newNumPTabs, newNumITabs := CountTabs()
if newNumPTabs != numPTabs {
base.Fatalf("ptabs changed after compile functions loop")
}
if itabsLen != len(itabs) {
if newNumITabs != numITabs {
base.Fatalf("itabs changed after compile functions loop")
}
}

View File

@ -34,6 +34,10 @@ type ptabEntry struct {
t *types.Type
}
func CountTabs() (numPTabs, numITabs int) {
return len(ptabs), len(itabs)
}
// runtime interface and reflection data structures
var (
signatmu sync.Mutex // protects signatset and signatslice
@ -1158,13 +1162,9 @@ func dtypesym(t *types.Type) *obj.LSym {
if base.Ctxt.Pkgpath != "runtime" || (tbase != types.Types[tbase.Kind()] && tbase != types.ByteType && tbase != types.RuneType && tbase != types.ErrorType) { // int, float, etc
// named types from other files are defined only by those files
if tbase.Sym() != nil && tbase.Sym().Pkg != types.LocalPkg {
if i, ok := typeSymIdx[tbase]; ok {
if i := BaseTypeIndex(t); i >= 0 {
lsym.Pkg = tbase.Sym().Pkg.Prefix
if t != tbase {
lsym.SymIdx = int32(i[1])
} else {
lsym.SymIdx = int32(i[0])
}
lsym.SymIdx = int32(i)
lsym.Set(obj.AttrIndexed, true)
}
return lsym

View File

@ -11,6 +11,8 @@ import (
"time"
)
var timings Timings
// Timings collects the execution times of labeled phases
// which are added trough a sequence of Start/Stop calls.
// Events may be associated with each phase via AddEvent.

View File

@ -5,6 +5,7 @@
package ir
import (
"cmd/compile/internal/base"
"cmd/compile/internal/types"
"cmd/internal/src"
)
@ -164,6 +165,12 @@ type BlockStmt struct {
func NewBlockStmt(pos src.XPos, list []Node) *BlockStmt {
n := &BlockStmt{}
n.pos = pos
if !pos.IsKnown() {
n.pos = base.Pos
if len(list) > 0 {
n.pos = list[0].Pos()
}
}
n.op = OBLOCK
n.List_.Set(list)
return n