Skip to content

Commit 84c3761

Browse files
committed
transform: use thinlto-pre-link passes
This improves compilation performance by about 5% in my quick test, while increasing binary size on average by 0.13% when comparing the smoke tests in the drivers repo (and about two thirds of that 0.13% is actually caused by a single smoke test). I think this is a good idea because it aligns the TinyGo optimization sequence with what ThinLTO expects.
1 parent 6184a6c commit 84c3761

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

transform/optimizer.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -142,11 +142,13 @@ func Optimize(mod llvm.Module, config *compileopts.Config) []error {
142142
fn.SetLinkage(llvm.InternalLinkage)
143143
}
144144

145-
// Run the default pass pipeline.
146-
// TODO: set the PrepareForThinLTO flag somehow.
145+
// Run the ThinLTO pre-link passes, meant to be run on each individual
146+
// module. This saves compilation time compared to "default<#>" and is meant
147+
// to better match the optimization passes that are happening during
148+
// ThinLTO.
147149
po := llvm.NewPassBuilderOptions()
148150
defer po.Dispose()
149-
passes := fmt.Sprintf("default<%s>", optLevel)
151+
passes := fmt.Sprintf("thinlto-pre-link<%s>", optLevel)
150152
err := mod.RunPasses(passes, llvm.TargetMachine{}, po)
151153
if err != nil {
152154
return []error{fmt.Errorf("could not build pass pipeline: %w", err)}

0 commit comments

Comments
 (0)