aboutsummaryrefslogtreecommitdiffhomepage
path: root/transform/optimizer.go
diff options
context:
space:
mode:
authorAyke van Laethem <[email protected]>2022-02-07 15:19:25 +0100
committerRon Evans <[email protected]>2022-03-12 12:55:38 +0100
commit603fff78d496445ab3d614c45c75894a9f94999e (patch)
treed981e4616bb52bb29e7a29cbd53cfb16bcfb432a /transform/optimizer.go
parentd4b1467e4c7f1c9e89a8b9efb89a25e9cd6067b2 (diff)
downloadtinygo-603fff78d496445ab3d614c45c75894a9f94999e.tar.gz
tinygo-603fff78d496445ab3d614c45c75894a9f94999e.zip
all: add support for ThinLTO
ThinLTO optimizes across LLVM modules at link time. This means that optimizations (such as inlining and const-propagation) are possible between C and Go. This makes this change especially useful for CGo, but not just for CGo. By doing some optimizations at link time, the linker can discard some unused functions and this leads to a size reduction on average. It does increase code size in some cases, but that's true for most optimizations. I've excluded a number of targets for now (wasm, avr, xtensa, windows, macos). They can probably be supported with some more work, but that should be done in separate PRs. Overall, this change results in an average 3.24% size reduction over all the tinygo.org/x/drivers smoke tests. TODO: this commit runs part of the pass pipeline twice. We should set the PrepareForThinLTO flag in the PassManagerBuilder for even further reduced code size (0.7%) and improved compilation speed.
Diffstat (limited to 'transform/optimizer.go')
-rw-r--r--transform/optimizer.go1
1 files changed, 1 insertions, 0 deletions
diff --git a/transform/optimizer.go b/transform/optimizer.go
index 0c1d8a8f2..8e2ef7a83 100644
--- a/transform/optimizer.go
+++ b/transform/optimizer.go
@@ -151,6 +151,7 @@ func Optimize(mod llvm.Module, config *compileopts.Config, optLevel, sizeLevel i
funcPasses.FinalizeFunc()
// Run module passes.
+ // TODO: somehow set the PrepareForThinLTO flag in the pass manager builder.
modPasses := llvm.NewPassManager()
defer modPasses.Dispose()
builder.Populate(modPasses)