]> Cypherpunks repositories - gostls13.git/commitdiff
[dev.regabi] cmd/compile: some more manual shuffling
authorMatthew Dempsky <mdempsky@google.com>
Fri, 1 Jan 2021 07:39:15 +0000 (23:39 -0800)
committerMatthew Dempsky <mdempsky@google.com>
Fri, 1 Jan 2021 10:52:27 +0000 (10:52 +0000)
More minor reshuffling of passes.

Passes toolstash -cmp.

Change-Id: I22633b3741f668fc5ee8579d7d610035ed57df1f
Reviewed-on: https://go-review.googlesource.com/c/go/+/280975
Trust: Matthew Dempsky <mdempsky@google.com>
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
src/cmd/compile/internal/gc/abiutils_test.go
src/cmd/compile/internal/gc/main.go
src/cmd/compile/internal/noder/noder.go
src/cmd/compile/internal/typecheck/dcl.go
src/cmd/compile/internal/typecheck/syms.go
src/cmd/compile/internal/typecheck/typecheck.go
src/cmd/compile/internal/typecheck/universe.go

index d535a6a34bf44317d1b775819c7972336f19601f..6fd0af1b1fbf9178ada108a5a5eb87def3b927fe 100644 (file)
@@ -38,7 +38,7 @@ func TestMain(m *testing.M) {
        base.Ctxt.Bso = bufio.NewWriter(os.Stdout)
        types.PtrSize = ssagen.Arch.LinkArch.PtrSize
        types.RegSize = ssagen.Arch.LinkArch.RegSize
-       typecheck.Init()
+       typecheck.InitUniverse()
        os.Exit(m.Run())
 }
 
index 603619eb5a521c98830cc6c3fb4c33223052daa6..df6a9d8e4518f601bcfc762dea90905ce7f08f37 100644 (file)
@@ -200,23 +200,15 @@ func Main(archInit func(*ssagen.ArchInfo)) {
 
        base.AutogeneratedPos = makePos(src.NewFileBase("<autogenerated>", "<autogenerated>"), 1, 0)
 
-       typecheck.Init()
+       typecheck.InitUniverse()
 
-       // Parse input.
-       base.Timer.Start("fe", "parse")
-       lines := noder.ParseFiles(flag.Args())
-       ssagen.CgoSymABIs()
-       base.Timer.Stop()
-       base.Timer.AddEvent(int64(lines), "lines")
-       dwarfgen.RecordPackageName()
+       // Parse and typecheck input.
+       noder.LoadPackage(flag.Args())
 
-       // Typecheck.
-       noder.Package()
+       dwarfgen.RecordPackageName()
+       ssagen.CgoSymABIs()
 
-       // With all user code typechecked, it's now safe to verify unused dot imports.
-       noder.CheckDotImports()
-       base.ExitIfErrors()
-       // Phase 6: Compute Addrtaken for names.
+       // Compute Addrtaken for names.
        // We need to wait until typechecking is done so that when we see &x[i]
        // we know that x has its address taken if x is an array, but not if x is a slice.
        // We compute Addrtaken in bulk here.
@@ -227,7 +219,7 @@ func Main(archInit func(*ssagen.ArchInfo)) {
        }
        typecheck.IncrementalAddrtaken = true
 
-       // Phase 7: Eliminate some obviously dead code.
+       // Eliminate some obviously dead code.
        // Must happen after typechecking.
        for _, n := range typecheck.Target.Decls {
                if n.Op() == ir.ODCLFUNC {
@@ -235,7 +227,7 @@ func Main(archInit func(*ssagen.ArchInfo)) {
                }
        }
 
-       // Phase 8: Decide how to capture closed variables.
+       // Decide how to capture closed variables.
        // This needs to run before escape analysis,
        // because variables captured by value do not escape.
        base.Timer.Start("fe", "capturevars")
@@ -256,6 +248,7 @@ func Main(archInit func(*ssagen.ArchInfo)) {
                // otherwise lazily when used or re-exported.
                typecheck.AllImportedBodies()
        }
+
        // Build init task.
        if initTask := pkginit.Task(); initTask != nil {
                typecheck.Export(initTask)
@@ -311,6 +304,7 @@ func Main(archInit func(*ssagen.ArchInfo)) {
        // Prepare for SSA compilation.
        // This must be before peekitabs, because peekitabs
        // can trigger function compilation.
+       typecheck.InitRuntime()
        ssagen.InitConfig()
 
        // Just before compilation, compile itabs found on
index 40569af31711192c131c3e0b71e9c783ff9388e1..29bfde3ff23cc0cea3c2150fd98ed150cf345466 100644 (file)
@@ -25,6 +25,20 @@ import (
        "cmd/internal/src"
 )
 
+func LoadPackage(filenames []string) {
+       base.Timer.Start("fe", "parse")
+       lines := ParseFiles(filenames)
+       base.Timer.Stop()
+       base.Timer.AddEvent(int64(lines), "lines")
+
+       // Typecheck.
+       Package()
+
+       // With all user code typechecked, it's now safe to verify unused dot imports.
+       CheckDotImports()
+       base.ExitIfErrors()
+}
+
 // ParseFiles concurrently parses files into *syntax.File structures.
 // Each declaration in every *syntax.File is converted to a syntax tree
 // and its root represented by *Node is appended to Target.Decls.
index fd55f472abe7cf8f0412815c3975e060874615f4..daec9848d0fb0808268daf8249ad2a191730bfe4 100644 (file)
@@ -15,7 +15,7 @@ import (
        "cmd/internal/src"
 )
 
-var DeclContext ir.Class // PEXTERN/PAUTO
+var DeclContext ir.Class = ir.PEXTERN // PEXTERN/PAUTO
 
 func DeclFunc(sym *types.Sym, tfn ir.Ntype) *ir.Func {
        if tfn.Op() != ir.OTFUNC {
index f0e230432a0bac4d181c8e27c9924fb940a93ac0..2251062e16c6e63af43a8b58e21641d6fb72373f 100644 (file)
@@ -65,11 +65,9 @@ func Lookup(name string) *types.Sym {
 // so that the compiler can generate calls to them,
 // but does not make them visible to user code.
 func InitRuntime() {
+       base.Timer.Start("fe", "loadsys")
        types.Block = 1
 
-       inimport = true
-       TypecheckAllowed = true
-
        typs := runtimeTypes()
        for _, d := range &runtimeDecls {
                sym := ir.Pkgs.Runtime.Lookup(d.name)
@@ -83,9 +81,6 @@ func InitRuntime() {
                        base.Fatalf("unhandled declaration tag %v", d.tag)
                }
        }
-
-       TypecheckAllowed = false
-       inimport = false
 }
 
 // LookupRuntimeFunc looks up Go function name in package runtime. This function
index 4c6ac21fc68f72c340bd39cf5b46dcbd73b1e744..c8d82443a18c4dfbc021204495fdf737773aac4d 100644 (file)
@@ -31,13 +31,6 @@ var (
        NeedRuntimeType = func(*types.Type) {}
 )
 
-func Init() {
-       initUniverse()
-       DeclContext = ir.PEXTERN
-       base.Timer.Start("fe", "loadsys")
-       InitRuntime()
-}
-
 func AssignExpr(n ir.Node) ir.Node { return typecheck(n, ctxExpr|ctxAssign) }
 func Expr(n ir.Node) ir.Node       { return typecheck(n, ctxExpr) }
 func Stmt(n ir.Node) ir.Node       { return typecheck(n, ctxStmt) }
index 054f094cd3119d7ae36b1648c91d85d3795aa321..f1e7ed427307f955f6573ce2ac72bc7346f6b9ce 100644 (file)
@@ -90,8 +90,8 @@ var unsafeFuncs = [...]struct {
        {"Sizeof", ir.OSIZEOF},
 }
 
-// initUniverse initializes the universe block.
-func initUniverse() {
+// InitUniverse initializes the universe block.
+func InitUniverse() {
        if types.PtrSize == 0 {
                base.Fatalf("typeinit before betypeinit")
        }