compiler: move Optimize() function to a separate file
In the future, there will be more optimizations. Let's keep them in a separate file for separation of concerns.
Этот коммит содержится в:
родитель
c9c9935b9c
коммит
5db43e8d04
2 изменённых файлов: 32 добавлений и 27 удалений
|
@ -3109,33 +3109,6 @@ func (c *Compiler) NonConstGlobals() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Compiler) Optimize(optLevel, sizeLevel int, inlinerThreshold uint) {
|
|
||||||
builder := llvm.NewPassManagerBuilder()
|
|
||||||
defer builder.Dispose()
|
|
||||||
builder.SetOptLevel(optLevel)
|
|
||||||
builder.SetSizeLevel(sizeLevel)
|
|
||||||
if inlinerThreshold != 0 {
|
|
||||||
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)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Emit object file (.o).
|
// Emit object file (.o).
|
||||||
func (c *Compiler) EmitObject(path string) error {
|
func (c *Compiler) EmitObject(path string) error {
|
||||||
llvmBuf, err := c.machine.EmitToMemoryBuffer(c.mod, llvm.ObjectFile)
|
llvmBuf, err := c.machine.EmitToMemoryBuffer(c.mod, llvm.ObjectFile)
|
||||||
|
|
32
compiler/optimizer.go
Обычный файл
32
compiler/optimizer.go
Обычный файл
|
@ -0,0 +1,32 @@
|
||||||
|
package compiler
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/aykevl/go-llvm"
|
||||||
|
)
|
||||||
|
|
||||||
|
func (c *Compiler) Optimize(optLevel, sizeLevel int, inlinerThreshold uint) {
|
||||||
|
builder := llvm.NewPassManagerBuilder()
|
||||||
|
defer builder.Dispose()
|
||||||
|
builder.SetOptLevel(optLevel)
|
||||||
|
builder.SetSizeLevel(sizeLevel)
|
||||||
|
if inlinerThreshold != 0 {
|
||||||
|
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)
|
||||||
|
}
|
Загрузка…
Создание таблицы
Сослаться в новой задаче