diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2022-05-31 22:13:24 -0700 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2022-05-31 22:13:24 -0700 |
| commit | 8c0f4e6f54eefc56f69bf8def333ff8cf67c0783 (patch) | |
| tree | 51cf6b0968040f2ecea06d7b9a908a509c392d7f /src/codegen/llvm.zig | |
| parent | 2f9533f639311f680f3080747aa03b411ca63100 (diff) | |
| download | zig-8c0f4e6f54eefc56f69bf8def333ff8cf67c0783.tar.gz zig-8c0f4e6f54eefc56f69bf8def333ff8cf67c0783.zip | |
LLVM: add target-cpu and target-features fn attributes
Diffstat (limited to 'src/codegen/llvm.zig')
| -rw-r--r-- | src/codegen/llvm.zig | 21 |
1 files changed, 14 insertions, 7 deletions
diff --git a/src/codegen/llvm.zig b/src/codegen/llvm.zig index 80fd93bbbe..179216a52f 100644 --- a/src/codegen/llvm.zig +++ b/src/codegen/llvm.zig @@ -2302,19 +2302,21 @@ pub const DeclGen = struct { } fn addCommonFnAttributes(dg: *DeclGen, llvm_fn: *const llvm.Value) void { - if (!dg.module.comp.bin_file.options.red_zone) { + const comp = dg.module.comp; + + if (!comp.bin_file.options.red_zone) { dg.addFnAttr(llvm_fn, "noredzone"); } - if (dg.module.comp.bin_file.options.omit_frame_pointer) { + if (comp.bin_file.options.omit_frame_pointer) { dg.addFnAttrString(llvm_fn, "frame-pointer", "none"); } else { dg.addFnAttrString(llvm_fn, "frame-pointer", "all"); } dg.addFnAttr(llvm_fn, "nounwind"); - if (dg.module.comp.unwind_tables) { + if (comp.unwind_tables) { dg.addFnAttr(llvm_fn, "uwtable"); } - if (dg.module.comp.bin_file.options.skip_linker_dependencies) { + if (comp.bin_file.options.skip_linker_dependencies) { // The intent here is for compiler-rt and libc functions to not generate // infinite recursion. For example, if we are compiling the memcpy function, // and llvm detects that the body is equivalent to memcpy, it may replace the @@ -2322,14 +2324,19 @@ pub const DeclGen = struct { // overflow instead of performing memcpy. dg.addFnAttr(llvm_fn, "nobuiltin"); } - if (dg.module.comp.bin_file.options.optimize_mode == .ReleaseSmall) { + if (comp.bin_file.options.optimize_mode == .ReleaseSmall) { dg.addFnAttr(llvm_fn, "minsize"); dg.addFnAttr(llvm_fn, "optsize"); } - if (dg.module.comp.bin_file.options.tsan) { + if (comp.bin_file.options.tsan) { dg.addFnAttr(llvm_fn, "sanitize_thread"); } - // TODO add target-cpu and target-features fn attributes + if (comp.getTarget().cpu.model.llvm_name) |s| { + llvm_fn.addFunctionAttr("target-cpu", s); + } + if (comp.bin_file.options.llvm_cpu_features) |s| { + llvm_fn.addFunctionAttr("target-features", s); + } } fn resolveGlobalDecl(dg: *DeclGen, decl_index: Module.Decl.Index) Error!*const llvm.Value { |
