Skip to content

Commit

Permalink
transform: use thinlto-pre-link passes
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
aykevl committed Jul 31, 2024
1 parent 6184a6c commit 84c3761
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions transform/optimizer.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,11 +142,13 @@ func Optimize(mod llvm.Module, config *compileopts.Config) []error {
fn.SetLinkage(llvm.InternalLinkage)
}

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

0 comments on commit 84c3761

Please sign in to comment.