mirror of
https://github.com/golang/go
synced 2024-10-14 20:05:36 +00:00
[dev.regabi] cmd/compile: some more manual shuffling
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>
This commit is contained in:
parent
0f1d2129c4
commit
3a4474cdfd
|
@ -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())
|
||||
}
|
||||
|
||||
|
|
|
@ -200,23 +200,15 @@ func Main(archInit func(*ssagen.ArchInfo)) {
|
|||
|
||||
base.AutogeneratedPos = makePos(src.NewFileBase("<autogenerated>", "<autogenerated>"), 1, 0)
|
||||
|
||||
typecheck.Init()
|
||||
typecheck.InitUniverse()
|
||||
|
||||
// Parse and typecheck input.
|
||||
noder.LoadPackage(flag.Args())
|
||||
|
||||
// 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()
|
||||
ssagen.CgoSymABIs()
|
||||
|
||||
// Typecheck.
|
||||
noder.Package()
|
||||
|
||||
// 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
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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) }
|
||||
|
|
|
@ -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")
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue