wasm: support ThinLTO

Using ThinLTO manages to optimize binaries quite significantly. The
exact amount varies a lot by program but it's about 10-15% usually.

Don't remove non-ThinLTO support yet. It would not surprise me if this
triggered some unintended side effect. Eventually, non-ThinLTO support
should be removed though.
This commit is contained in:
Ayke van Laethem
2022-11-25 02:27:27 +01:00
committed by Ayke
parent 7fa13ed0a6
commit da362b8a24
3 changed files with 10 additions and 10 deletions
+5
View File
@@ -1099,6 +1099,11 @@ func (b *builder) createFunctionStart(intrinsic bool) {
// otherwise the function is not exported.
functionAttr := b.ctx.CreateStringAttribute("wasm-export-name", b.info.linkName)
b.llvmFn.AddFunctionAttr(functionAttr)
// Unlike most targets, exported functions are actually visible in
// WebAssembly (even if it's not called from within the WebAssembly
// module). But LTO generally optimizes such functions away. Therefore,
// exported functions must be explicitly marked as used.
llvmutil.AppendToGlobal(b.mod, "llvm.used", b.llvmFn)
}
// Some functions have a pragma controlling the inlining level.