]> Cypherpunks repositories - gostls13.git/commitdiff
[dev.regabi] cmd/compile: separate misc for gc split
authorRuss Cox <rsc@golang.org>
Mon, 21 Dec 2020 06:20:20 +0000 (01:20 -0500)
committerRuss Cox <rsc@golang.org>
Tue, 22 Dec 2020 19:32:16 +0000 (19:32 +0000)
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>
src/cmd/compile/internal/gc/escape.go
src/cmd/compile/internal/gc/iimport.go
src/cmd/compile/internal/gc/main.go
src/cmd/compile/internal/gc/obj.go
src/cmd/compile/internal/gc/reflect.go
src/cmd/compile/internal/gc/timings.go
src/cmd/compile/internal/ir/stmt.go

index 235cef47eaaa9493e46f911a44431c3e0b535a61..3351cfe968dada1c926c8fcbe563bed588216284 100644 (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 := ""
index cd66d39b66792b72eba3da3311d3b621b2742bd3..358fdef294d3f6f37a7af0f2a3e1183c737a7db6 100644 (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)
index 4aa2a2ca47f4c8195c1015e11953511237dc4f77..80b17ebbf80d37ff28a3452346c15f7f5ef2746d 100644 (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() {
index 094c3862188961e9cbf4724c5c4597c283264161..c6625da1daff42f9f2c6cc91498f170b0a24a54b 100644 (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")
        }
 }
index 8e2c6f62e11dcc4f9e5ee4f6607339b57e8d72f8..92b04f20d5039645323f8b71af45098c13710602 100644 (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
index 56b3899e2f6ae1e6fe9e62552baa4e2178753756..ac12d78d1e0884f0119c489bfc2754f9a83a3070 100644 (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.
index 12811821ad9eea79a6b4ee8f1399445ba2311d0b..e2543a554149f70e8ac9416fe323c70c872396f1 100644 (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