all: allow -O0 optimization level
Этот коммит содержится в:
родитель
6191d4e1ac
коммит
c9ae72a105
2 изменённых файлов: 25 добавлений и 32 удалений
|
@ -361,22 +361,18 @@ func (c *Compiler) Compile(mainPath string) error {
|
||||||
}
|
}
|
||||||
c.builder.CreateRetVoid()
|
c.builder.CreateRetVoid()
|
||||||
|
|
||||||
// Adjust main function.
|
mainWrapper := c.mod.NamedFunction("runtime.mainWrapper")
|
||||||
|
block = c.ctx.AddBasicBlock(mainWrapper, "entry")
|
||||||
|
c.builder.SetInsertPointAtEnd(block)
|
||||||
realMain := c.mod.NamedFunction(c.ir.MainPkg().Pkg.Path() + ".main")
|
realMain := c.mod.NamedFunction(c.ir.MainPkg().Pkg.Path() + ".main")
|
||||||
if c.ir.NeedsScheduler() {
|
if c.ir.NeedsScheduler() {
|
||||||
c.mod.NamedFunction("runtime.main_mainAsync").ReplaceAllUsesWith(realMain)
|
coroutine := c.builder.CreateCall(realMain, []llvm.Value{llvm.ConstPointerNull(c.i8ptrType)}, "")
|
||||||
|
scheduler := c.mod.NamedFunction("runtime.scheduler")
|
||||||
|
c.builder.CreateCall(scheduler, []llvm.Value{coroutine}, "")
|
||||||
} else {
|
} else {
|
||||||
c.mod.NamedFunction("runtime.main_main").ReplaceAllUsesWith(realMain)
|
c.builder.CreateCall(realMain, nil, "")
|
||||||
}
|
|
||||||
|
|
||||||
// Only use a scheduler when necessary.
|
|
||||||
if c.ir.NeedsScheduler() {
|
|
||||||
// Enable the scheduler.
|
|
||||||
hasScheduler := c.mod.NamedGlobal("runtime.hasScheduler")
|
|
||||||
hasScheduler.SetInitializer(llvm.ConstInt(llvm.Int1Type(), 1, false))
|
|
||||||
hasScheduler.SetGlobalConstant(true)
|
|
||||||
hasScheduler.SetUnnamedAddr(true)
|
|
||||||
}
|
}
|
||||||
|
c.builder.CreateRetVoid()
|
||||||
|
|
||||||
// Initialize runtime type information, for interfaces.
|
// Initialize runtime type information, for interfaces.
|
||||||
// See src/runtime/interface.go for more details.
|
// See src/runtime/interface.go for more details.
|
||||||
|
|
|
@ -10,14 +10,18 @@ const Compiler = "tgo"
|
||||||
// package.
|
// package.
|
||||||
func initAll()
|
func initAll()
|
||||||
|
|
||||||
// These signatures are used to call the correct main function: with scheduling
|
// The compiler will insert the call to main.main() here, depending on whether
|
||||||
// or without scheduling.
|
// the scheduler is necessary.
|
||||||
func main_main()
|
//
|
||||||
func main_mainAsync(parent *coroutine) *coroutine
|
// Without scheduler:
|
||||||
|
//
|
||||||
// The compiler will change this to true if there are 'go' statements in the
|
// main.main()
|
||||||
// compiled program and turn it into a const.
|
//
|
||||||
var hasScheduler bool
|
// With scheduler:
|
||||||
|
//
|
||||||
|
// coroutine := main.main(nil)
|
||||||
|
// scheduler(coroutine)
|
||||||
|
func mainWrapper()
|
||||||
|
|
||||||
// Entry point for Go. Initialize all packages and call main.main().
|
// Entry point for Go. Initialize all packages and call main.main().
|
||||||
//go:export main
|
//go:export main
|
||||||
|
@ -31,18 +35,11 @@ func main() int {
|
||||||
// Enable interrupts etc.
|
// Enable interrupts etc.
|
||||||
postinit()
|
postinit()
|
||||||
|
|
||||||
// This branch must be optimized away. Only one of the targets must remain,
|
// Compiler-generated wrapper to main.main().
|
||||||
// or there will be link errors.
|
mainWrapper()
|
||||||
if hasScheduler {
|
|
||||||
// Initialize main and run the scheduler.
|
// For libc compatibility.
|
||||||
coro := main_mainAsync(nil)
|
return 0
|
||||||
scheduler(coro)
|
|
||||||
return 0
|
|
||||||
} else {
|
|
||||||
// No scheduler is necessary. Call main directly.
|
|
||||||
main_main()
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func GOMAXPROCS(n int) int {
|
func GOMAXPROCS(n int) int {
|
||||||
|
|
Загрузка…
Создание таблицы
Сослаться в новой задаче