authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-05-31 22:13:24-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-05-31 22:13:24-07:00
log8c0f4e6f54eefc56f69bf8def333ff8cf67c0783
tree51cf6b0968040f2ecea06d7b9a908a509c392d7f
parent2f9533f639311f680f3080747aa03b411ca63100

LLVM: add target-cpu and target-features fn attributes


2 files changed, 17 insertions(+), 7 deletions(-)

src/codegen/llvm.zig+14-7
...@@ -2302,19 +2302,21 @@ pub const DeclGen = struct {...@@ -2302,19 +2302,21 @@ pub const DeclGen = struct {
2302 }2302 }
23032303
2304 fn addCommonFnAttributes(dg: *DeclGen, llvm_fn: *const llvm.Value) void {2304 fn addCommonFnAttributes(dg: *DeclGen, llvm_fn: *const llvm.Value) void {
2305 if (!dg.module.comp.bin_file.options.red_zone) {2305 const comp = dg.module.comp;
2306
2307 if (!comp.bin_file.options.red_zone) {
2306 dg.addFnAttr(llvm_fn, "noredzone");2308 dg.addFnAttr(llvm_fn, "noredzone");
2307 }2309 }
2308 if (dg.module.comp.bin_file.options.omit_frame_pointer) {2310 if (comp.bin_file.options.omit_frame_pointer) {
2309 dg.addFnAttrString(llvm_fn, "frame-pointer", "none");2311 dg.addFnAttrString(llvm_fn, "frame-pointer", "none");
2310 } else {2312 } else {
2311 dg.addFnAttrString(llvm_fn, "frame-pointer", "all");2313 dg.addFnAttrString(llvm_fn, "frame-pointer", "all");
2312 }2314 }
2313 dg.addFnAttr(llvm_fn, "nounwind");2315 dg.addFnAttr(llvm_fn, "nounwind");
2314 if (dg.module.comp.unwind_tables) {2316 if (comp.unwind_tables) {
2315 dg.addFnAttr(llvm_fn, "uwtable");2317 dg.addFnAttr(llvm_fn, "uwtable");
2316 }2318 }
2317 if (dg.module.comp.bin_file.options.skip_linker_dependencies) {2319 if (comp.bin_file.options.skip_linker_dependencies) {
2318 // The intent here is for compiler-rt and libc functions to not generate2320 // The intent here is for compiler-rt and libc functions to not generate
2319 // infinite recursion. For example, if we are compiling the memcpy function,2321 // infinite recursion. For example, if we are compiling the memcpy function,
2320 // and llvm detects that the body is equivalent to memcpy, it may replace the2322 // and llvm detects that the body is equivalent to memcpy, it may replace the
...@@ -2322,14 +2324,19 @@ pub const DeclGen = struct {...@@ -2322,14 +2324,19 @@ pub const DeclGen = struct {
2322 // overflow instead of performing memcpy.2324 // overflow instead of performing memcpy.
2323 dg.addFnAttr(llvm_fn, "nobuiltin");2325 dg.addFnAttr(llvm_fn, "nobuiltin");
2324 }2326 }
2325 if (dg.module.comp.bin_file.options.optimize_mode == .ReleaseSmall) {2327 if (comp.bin_file.options.optimize_mode == .ReleaseSmall) {
2326 dg.addFnAttr(llvm_fn, "minsize");2328 dg.addFnAttr(llvm_fn, "minsize");
2327 dg.addFnAttr(llvm_fn, "optsize");2329 dg.addFnAttr(llvm_fn, "optsize");
2328 }2330 }
2329 if (dg.module.comp.bin_file.options.tsan) {2331 if (comp.bin_file.options.tsan) {
2330 dg.addFnAttr(llvm_fn, "sanitize_thread");2332 dg.addFnAttr(llvm_fn, "sanitize_thread");
2331 }2333 }
2332 // TODO add target-cpu and target-features fn attributes2334 if (comp.getTarget().cpu.model.llvm_name) |s| {
2335 llvm_fn.addFunctionAttr("target-cpu", s);
2336 }
2337 if (comp.bin_file.options.llvm_cpu_features) |s| {
2338 llvm_fn.addFunctionAttr("target-features", s);
2339 }
2333 }2340 }
23342341
2335 fn resolveGlobalDecl(dg: *DeclGen, decl_index: Module.Decl.Index) Error!*const llvm.Value {2342 fn resolveGlobalDecl(dg: *DeclGen, decl_index: Module.Decl.Index) Error!*const llvm.Value {
src/codegen/llvm/bindings.zig+3
...@@ -239,6 +239,9 @@ pub const Value = opaque {...@@ -239,6 +239,9 @@ pub const Value = opaque {
239239
240 pub const getAlignment = LLVMGetAlignment;240 pub const getAlignment = LLVMGetAlignment;
241 extern fn LLVMGetAlignment(V: *const Value) c_uint;241 extern fn LLVMGetAlignment(V: *const Value) c_uint;
242
243 pub const addFunctionAttr = ZigLLVMAddFunctionAttr;
244 extern fn ZigLLVMAddFunctionAttr(Fn: *const Value, attr_name: [*:0]const u8, attr_value: [*:0]const u8) void;
242};245};
243246
244pub const Type = opaque {247pub const Type = opaque {