mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +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
7 changed files with 29 additions and 33 deletions
|
|
@ -38,7 +38,7 @@ func TestMain(m *testing.M) {
|
||||||
base.Ctxt.Bso = bufio.NewWriter(os.Stdout)
|
base.Ctxt.Bso = bufio.NewWriter(os.Stdout)
|
||||||
types.PtrSize = ssagen.Arch.LinkArch.PtrSize
|
types.PtrSize = ssagen.Arch.LinkArch.PtrSize
|
||||||
types.RegSize = ssagen.Arch.LinkArch.RegSize
|
types.RegSize = ssagen.Arch.LinkArch.RegSize
|
||||||
typecheck.Init()
|
typecheck.InitUniverse()
|
||||||
os.Exit(m.Run())
|
os.Exit(m.Run())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -200,23 +200,15 @@ func Main(archInit func(*ssagen.ArchInfo)) {
|
||||||
|
|
||||||
base.AutogeneratedPos = makePos(src.NewFileBase("<autogenerated>", "<autogenerated>"), 1, 0)
|
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()
|
dwarfgen.RecordPackageName()
|
||||||
|
ssagen.CgoSymABIs()
|
||||||
|
|
||||||
// Typecheck.
|
// Compute Addrtaken for names.
|
||||||
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.
|
|
||||||
// We need to wait until typechecking is done so that when we see &x[i]
|
// 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 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.
|
// We compute Addrtaken in bulk here.
|
||||||
|
|
@ -227,7 +219,7 @@ func Main(archInit func(*ssagen.ArchInfo)) {
|
||||||
}
|
}
|
||||||
typecheck.IncrementalAddrtaken = true
|
typecheck.IncrementalAddrtaken = true
|
||||||
|
|
||||||
// Phase 7: Eliminate some obviously dead code.
|
// Eliminate some obviously dead code.
|
||||||
// Must happen after typechecking.
|
// Must happen after typechecking.
|
||||||
for _, n := range typecheck.Target.Decls {
|
for _, n := range typecheck.Target.Decls {
|
||||||
if n.Op() == ir.ODCLFUNC {
|
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,
|
// This needs to run before escape analysis,
|
||||||
// because variables captured by value do not escape.
|
// because variables captured by value do not escape.
|
||||||
base.Timer.Start("fe", "capturevars")
|
base.Timer.Start("fe", "capturevars")
|
||||||
|
|
@ -256,6 +248,7 @@ func Main(archInit func(*ssagen.ArchInfo)) {
|
||||||
// otherwise lazily when used or re-exported.
|
// otherwise lazily when used or re-exported.
|
||||||
typecheck.AllImportedBodies()
|
typecheck.AllImportedBodies()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Build init task.
|
// Build init task.
|
||||||
if initTask := pkginit.Task(); initTask != nil {
|
if initTask := pkginit.Task(); initTask != nil {
|
||||||
typecheck.Export(initTask)
|
typecheck.Export(initTask)
|
||||||
|
|
@ -311,6 +304,7 @@ func Main(archInit func(*ssagen.ArchInfo)) {
|
||||||
// Prepare for SSA compilation.
|
// Prepare for SSA compilation.
|
||||||
// This must be before peekitabs, because peekitabs
|
// This must be before peekitabs, because peekitabs
|
||||||
// can trigger function compilation.
|
// can trigger function compilation.
|
||||||
|
typecheck.InitRuntime()
|
||||||
ssagen.InitConfig()
|
ssagen.InitConfig()
|
||||||
|
|
||||||
// Just before compilation, compile itabs found on
|
// Just before compilation, compile itabs found on
|
||||||
|
|
|
||||||
|
|
@ -25,6 +25,20 @@ import (
|
||||||
"cmd/internal/src"
|
"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.
|
// ParseFiles concurrently parses files into *syntax.File structures.
|
||||||
// Each declaration in every *syntax.File is converted to a syntax tree
|
// Each declaration in every *syntax.File is converted to a syntax tree
|
||||||
// and its root represented by *Node is appended to Target.Decls.
|
// and its root represented by *Node is appended to Target.Decls.
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,7 @@ import (
|
||||||
"cmd/internal/src"
|
"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 {
|
func DeclFunc(sym *types.Sym, tfn ir.Ntype) *ir.Func {
|
||||||
if tfn.Op() != ir.OTFUNC {
|
if tfn.Op() != ir.OTFUNC {
|
||||||
|
|
|
||||||
|
|
@ -65,11 +65,9 @@ func Lookup(name string) *types.Sym {
|
||||||
// so that the compiler can generate calls to them,
|
// so that the compiler can generate calls to them,
|
||||||
// but does not make them visible to user code.
|
// but does not make them visible to user code.
|
||||||
func InitRuntime() {
|
func InitRuntime() {
|
||||||
|
base.Timer.Start("fe", "loadsys")
|
||||||
types.Block = 1
|
types.Block = 1
|
||||||
|
|
||||||
inimport = true
|
|
||||||
TypecheckAllowed = true
|
|
||||||
|
|
||||||
typs := runtimeTypes()
|
typs := runtimeTypes()
|
||||||
for _, d := range &runtimeDecls {
|
for _, d := range &runtimeDecls {
|
||||||
sym := ir.Pkgs.Runtime.Lookup(d.name)
|
sym := ir.Pkgs.Runtime.Lookup(d.name)
|
||||||
|
|
@ -83,9 +81,6 @@ func InitRuntime() {
|
||||||
base.Fatalf("unhandled declaration tag %v", d.tag)
|
base.Fatalf("unhandled declaration tag %v", d.tag)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
TypecheckAllowed = false
|
|
||||||
inimport = false
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// LookupRuntimeFunc looks up Go function name in package runtime. This function
|
// LookupRuntimeFunc looks up Go function name in package runtime. This function
|
||||||
|
|
|
||||||
|
|
@ -31,13 +31,6 @@ var (
|
||||||
NeedRuntimeType = func(*types.Type) {}
|
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 AssignExpr(n ir.Node) ir.Node { return typecheck(n, ctxExpr|ctxAssign) }
|
||||||
func Expr(n ir.Node) ir.Node { return typecheck(n, ctxExpr) }
|
func Expr(n ir.Node) ir.Node { return typecheck(n, ctxExpr) }
|
||||||
func Stmt(n ir.Node) ir.Node { return typecheck(n, ctxStmt) }
|
func Stmt(n ir.Node) ir.Node { return typecheck(n, ctxStmt) }
|
||||||
|
|
|
||||||
|
|
@ -90,8 +90,8 @@ var unsafeFuncs = [...]struct {
|
||||||
{"Sizeof", ir.OSIZEOF},
|
{"Sizeof", ir.OSIZEOF},
|
||||||
}
|
}
|
||||||
|
|
||||||
// initUniverse initializes the universe block.
|
// InitUniverse initializes the universe block.
|
||||||
func initUniverse() {
|
func InitUniverse() {
|
||||||
if types.PtrSize == 0 {
|
if types.PtrSize == 0 {
|
||||||
base.Fatalf("typeinit before betypeinit")
|
base.Fatalf("typeinit before betypeinit")
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue