compiler: move optimizer into the binary
Этот коммит содержится в:
родитель
c109ec0955
коммит
0746d61639
3 изменённых файлов: 14 добавлений и 10 удалений
7
Makefile
7
Makefile
|
@ -94,14 +94,9 @@ build/tgo: *.go
|
|||
go build -o build/tgo -i .
|
||||
|
||||
# Build IR with the Go compiler.
|
||||
build/%.bc: src/examples/% src/examples/%/*.go build/tgo src/runtime/*.go build/runtime-$(TARGET)-combined.bc
|
||||
build/%.o: src/examples/% src/examples/%/*.go build/tgo src/runtime/*.go build/runtime-$(TARGET)-combined.bc
|
||||
./build/tgo $(TGOFLAGS) -runtime build/runtime-$(TARGET)-combined.bc -o $@ $(subst src/,,$<)
|
||||
|
||||
# Compile and optimize bitcode file.
|
||||
build/%.o: build/%.bc
|
||||
$(OPT) -Oz -enable-coroutines -o $< $<
|
||||
$(LLC) -filetype=obj -o $@ $<
|
||||
|
||||
# Compile C sources for the runtime.
|
||||
build/%.bc: src/runtime/%.c src/runtime/*.h
|
||||
@mkdir -p build
|
||||
|
|
13
compiler.go
13
compiler.go
|
@ -2787,21 +2787,28 @@ func (c *Compiler) ApplyFunctionSections() {
|
|||
}
|
||||
}
|
||||
|
||||
func (c *Compiler) Optimize(optLevel, sizeLevel int) {
|
||||
func (c *Compiler) Optimize(optLevel, sizeLevel int, inlinerThreshold uint) {
|
||||
builder := llvm.NewPassManagerBuilder()
|
||||
defer builder.Dispose()
|
||||
builder.SetOptLevel(optLevel)
|
||||
builder.SetSizeLevel(sizeLevel)
|
||||
builder.UseInlinerWithThreshold(200) // TODO depend on opt level, and -Os
|
||||
builder.UseInlinerWithThreshold(inlinerThreshold)
|
||||
builder.AddCoroutinePassesToExtensionPoints()
|
||||
|
||||
// Run function passes for each function.
|
||||
funcPasses := llvm.NewFunctionPassManagerForModule(c.mod)
|
||||
defer funcPasses.Dispose()
|
||||
builder.PopulateFunc(funcPasses)
|
||||
funcPasses.InitializeFunc()
|
||||
for fn := c.mod.FirstFunction(); !fn.IsNil(); fn = llvm.NextFunction(fn) {
|
||||
funcPasses.RunFunc(fn)
|
||||
}
|
||||
funcPasses.FinalizeFunc()
|
||||
|
||||
// Run module passes.
|
||||
modPasses := llvm.NewPassManager()
|
||||
defer modPasses.Dispose()
|
||||
builder.Populate(modPasses)
|
||||
|
||||
modPasses.Run(c.mod)
|
||||
}
|
||||
|
||||
|
|
4
main.go
4
main.go
|
@ -59,7 +59,9 @@ func Compile(pkgName, runtimePath, outpath, target string, printIR, dumpSSA bool
|
|||
if err := c.Verify(); err != nil {
|
||||
return err
|
||||
}
|
||||
//c.Optimize(2, 1) // -O2 -Os
|
||||
|
||||
// TODO: provide a flag to disable (most) optimizations.
|
||||
c.Optimize(2, 2, 5) // -Oz params
|
||||
if err := c.Verify(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
Загрузка…
Создание таблицы
Сослаться в новой задаче