From 0d4b6ac7417d1094ac972981b0241444ce2380ba Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Fri, 22 Jan 2021 23:36:30 -0700 Subject: add LTO support The CLI gains -flto and -fno-lto options to override the default. However, the cool thing about this is that the defaults are great! In general when you use build-exe in release mode, Zig will enable LTO if it would work and it would help. zig cc supports detecting and honoring the -flto and -fno-lto flags as well. The linkWithLld functions are improved to all be the same with regards to copying the artifact instead of trying to pass single objects through LLD with -r. There is possibly a future improvement here as well; see the respective TODOs. stage1 is updated to support outputting LLVM bitcode instead of machine code when lto is enabled. This allows LLVM to optimize across the Zig and C/C++ code boundary. closes #2845 --- src/codegen/llvm/bindings.zig | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'src/codegen') diff --git a/src/codegen/llvm/bindings.zig b/src/codegen/llvm/bindings.zig index 8774260a08..6474957b1c 100644 --- a/src/codegen/llvm/bindings.zig +++ b/src/codegen/llvm/bindings.zig @@ -243,7 +243,13 @@ pub const TargetMachine = opaque { extern fn LLVMDisposeTargetMachine(T: *const TargetMachine) void; pub const emitToFile = LLVMTargetMachineEmitToFile; - extern fn LLVMTargetMachineEmitToFile(*const TargetMachine, M: *const Module, Filename: [*:0]const u8, codegen: CodeGenFileType, ErrorMessage: *[*:0]const u8) LLVMBool; + extern fn LLVMTargetMachineEmitToFile( + *const TargetMachine, + M: *const Module, + Filename: [*:0]const u8, + codegen: CodeGenFileType, + ErrorMessage: *[*:0]const u8, + ) LLVMBool; }; pub const CodeMode = extern enum { -- cgit v1.2.3