mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-06 20:13:40 +00:00
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:
@@ -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.
|
||||
|
||||
Vendored
+1
@@ -6,6 +6,7 @@ target triple = "wasm32-unknown-wasi"
|
||||
@extern_global = external global [0 x i8], align 1
|
||||
@main.alignedGlobal = hidden global [4 x i32] zeroinitializer, align 32
|
||||
@main.alignedGlobal16 = hidden global [4 x i32] zeroinitializer, align 16
|
||||
@llvm.used = appending global [2 x ptr] [ptr @extern_func, ptr @exportedFunctionInSection]
|
||||
@main.globalInSection = hidden global i32 0, section ".special_global_section", align 4
|
||||
@undefinedGlobalNotInSection = external global i32, align 4
|
||||
@main.multipleGlobalPragmas = hidden global i32 0, section ".global_section", align 1024
|
||||
|
||||
Reference in New Issue
Block a user