builder: move some code to transform package
The transform package is the more appropriate location for package-level optimizations, to match `transform.Optimize` for whole-program optimizations. This is just a refactor, to make later changes easier to read.
Этот коммит содержится в:
родитель
04ace4de5f
коммит
9246899b30
2 изменённых файлов: 29 добавлений и 21 удалений
|
@ -439,27 +439,7 @@ func Build(pkgName, outpath string, config *compileopts.Config, action func(Buil
|
||||||
return errors.New("verification error after interpreting " + pkgInit.Name())
|
return errors.New("verification error after interpreting " + pkgInit.Name())
|
||||||
}
|
}
|
||||||
|
|
||||||
// Run function passes for each function in the module.
|
transform.OptimizePackage(mod, config)
|
||||||
// These passes are intended to be run on each function right
|
|
||||||
// after they're created to reduce IR size (and maybe also for
|
|
||||||
// cache locality to improve performance), but for now they're
|
|
||||||
// run here for each function in turn. Maybe this can be
|
|
||||||
// improved in the future.
|
|
||||||
builder := llvm.NewPassManagerBuilder()
|
|
||||||
defer builder.Dispose()
|
|
||||||
builder.SetOptLevel(optLevel)
|
|
||||||
builder.SetSizeLevel(sizeLevel)
|
|
||||||
funcPasses := llvm.NewFunctionPassManagerForModule(mod)
|
|
||||||
defer funcPasses.Dispose()
|
|
||||||
builder.PopulateFunc(funcPasses)
|
|
||||||
funcPasses.InitializeFunc()
|
|
||||||
for fn := mod.FirstFunction(); !fn.IsNil(); fn = llvm.NextFunction(fn) {
|
|
||||||
if fn.IsDeclaration() {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
funcPasses.RunFunc(fn)
|
|
||||||
}
|
|
||||||
funcPasses.FinalizeFunc()
|
|
||||||
|
|
||||||
// Serialize the LLVM module as a bitcode file.
|
// Serialize the LLVM module as a bitcode file.
|
||||||
// Write to a temporary path that is renamed to the destination
|
// Write to a temporary path that is renamed to the destination
|
||||||
|
|
|
@ -11,6 +11,34 @@ import (
|
||||||
"tinygo.org/x/go-llvm"
|
"tinygo.org/x/go-llvm"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// OptimizePackage runs optimization passes over the LLVM module for the given
|
||||||
|
// Go package.
|
||||||
|
func OptimizePackage(mod llvm.Module, config *compileopts.Config) {
|
||||||
|
optLevel, sizeLevel, _ := config.OptLevels()
|
||||||
|
|
||||||
|
// Run function passes for each function in the module.
|
||||||
|
// These passes are intended to be run on each function right
|
||||||
|
// after they're created to reduce IR size (and maybe also for
|
||||||
|
// cache locality to improve performance), but for now they're
|
||||||
|
// run here for each function in turn. Maybe this can be
|
||||||
|
// improved in the future.
|
||||||
|
builder := llvm.NewPassManagerBuilder()
|
||||||
|
defer builder.Dispose()
|
||||||
|
builder.SetOptLevel(optLevel)
|
||||||
|
builder.SetSizeLevel(sizeLevel)
|
||||||
|
funcPasses := llvm.NewFunctionPassManagerForModule(mod)
|
||||||
|
defer funcPasses.Dispose()
|
||||||
|
builder.PopulateFunc(funcPasses)
|
||||||
|
funcPasses.InitializeFunc()
|
||||||
|
for fn := mod.FirstFunction(); !fn.IsNil(); fn = llvm.NextFunction(fn) {
|
||||||
|
if fn.IsDeclaration() {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
funcPasses.RunFunc(fn)
|
||||||
|
}
|
||||||
|
funcPasses.FinalizeFunc()
|
||||||
|
}
|
||||||
|
|
||||||
// Optimize runs a number of optimization and transformation passes over the
|
// Optimize runs a number of optimization and transformation passes over the
|
||||||
// given module. Some passes are specific to TinyGo, others are generic LLVM
|
// given module. Some passes are specific to TinyGo, others are generic LLVM
|
||||||
// passes. You can set a preferred performance (0-3) and size (0-2) level and
|
// passes. You can set a preferred performance (0-3) and size (0-2) level and
|
||||||
|
|
Загрузка…
Создание таблицы
Сослаться в новой задаче