LLVM 18 support

This commit is contained in:
Ayke van Laethem
2024-05-18 12:55:35 +02:00
committed by Ron Evans
parent c2776dcf78
commit 81ce7fb738
35 changed files with 139 additions and 94 deletions
+8 -2
View File
@@ -8,6 +8,7 @@ import (
"github.com/tinygo-org/tinygo/compileopts"
"github.com/tinygo-org/tinygo/compiler/ircheck"
"github.com/tinygo-org/tinygo/compiler/llvmutil"
"tinygo.org/x/go-llvm"
)
@@ -52,7 +53,12 @@ func Optimize(mod llvm.Module, config *compileopts.Config) []error {
// Run some preparatory passes for the Go optimizer.
po := llvm.NewPassBuilderOptions()
defer po.Dispose()
err := mod.RunPasses("globaldce,globalopt,ipsccp,instcombine,adce,function-attrs", llvm.TargetMachine{}, po)
optPasses := "globaldce,globalopt,ipsccp,instcombine<no-verify-fixpoint>,adce,function-attrs"
if llvmutil.Version() < 18 {
// LLVM 17 doesn't have the no-verify-fixpoint flag.
optPasses = "globaldce,globalopt,ipsccp,instcombine,adce,function-attrs"
}
err := mod.RunPasses(optPasses, llvm.TargetMachine{}, po)
if err != nil {
return []error{fmt.Errorf("could not build pass pipeline: %w", err)}
}
@@ -75,7 +81,7 @@ func Optimize(mod llvm.Module, config *compileopts.Config) []error {
// After interfaces are lowered, there are many more opportunities for
// interprocedural optimizations. To get them to work, function
// attributes have to be updated first.
err = mod.RunPasses("globaldce,globalopt,ipsccp,instcombine,adce,function-attrs", llvm.TargetMachine{}, po)
err = mod.RunPasses(optPasses, llvm.TargetMachine{}, po)
if err != nil {
return []error{fmt.Errorf("could not build pass pipeline: %w", err)}
}