mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-24 06:19:04 +00:00
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.
This commit is contained in:
@@ -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)
|
||||||
|
|||||||
@@ -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)
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user