motiejus/zig

fork of https://codeberg.org/ziglang/zig
git clone https://git.jakstys.lt/motiejus/zig.git
Log | Tree | Refs | README | LICENSE

commit b52a28a8026d552e10cb18c3b7b1f7b10d23bf81 (tree)
parent 51717314e4c955f696919aea6f17d758b4b6430f
Author: LemonBoy <thatlemon@gmail.com>
Date:   Thu, 12 Nov 2020 09:27:29 +0100

stage1: Ask LLVM to produce compact code in ReleaseSize mode

Let's follow what Clang does for -Oz and apply the `minsize` and
`optsize` attributes by default.

Closes #7048
Supersedes #7077

Diffstat:
Msrc/stage1/codegen.cpp | 6++++++
1 file changed, 6 insertions(+), 0 deletions(-)

diff --git a/src/stage1/codegen.cpp b/src/stage1/codegen.cpp @@ -484,6 +484,12 @@ static LLVMValueRef make_fn_llvm_value(CodeGen *g, ZigFn *fn) { addLLVMFnAttrInt(llvm_fn, "alignstack", fn->alignstack_value); } + if (g->build_mode == BuildModeSmallRelease) { + // Optimize for small code size. + addLLVMFnAttr(llvm_fn, "minsize"); + addLLVMFnAttr(llvm_fn, "optsize"); + } + addLLVMFnAttr(llvm_fn, "nounwind"); add_uwtable_attr(g, llvm_fn); addLLVMFnAttr(llvm_fn, "nobuiltin");