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 {
23022302 }
23032303
23042304 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) {
23062308 dg.addFnAttr(llvm_fn, "noredzone");
23072309 }
2308 if (dg.module.comp.bin_file.options.omit_frame_pointer) {
2310 if (comp.bin_file.options.omit_frame_pointer) {
23092311 dg.addFnAttrString(llvm_fn, "frame-pointer", "none");
23102312 } else {
23112313 dg.addFnAttrString(llvm_fn, "frame-pointer", "all");
23122314 }
23132315 dg.addFnAttr(llvm_fn, "nounwind");
2314 if (dg.module.comp.unwind_tables) {
2316 if (comp.unwind_tables) {
23152317 dg.addFnAttr(llvm_fn, "uwtable");
23162318 }
2317 if (dg.module.comp.bin_file.options.skip_linker_dependencies) {
2319 if (comp.bin_file.options.skip_linker_dependencies) {
23182320 // The intent here is for compiler-rt and libc functions to not generate
23192321 // infinite recursion. For example, if we are compiling the memcpy function,
23202322 // and llvm detects that the body is equivalent to memcpy, it may replace the
......@@ -2322,14 +2324,19 @@ pub const DeclGen = struct {
23222324 // overflow instead of performing memcpy.
23232325 dg.addFnAttr(llvm_fn, "nobuiltin");
23242326 }
2325 if (dg.module.comp.bin_file.options.optimize_mode == .ReleaseSmall) {
2327 if (comp.bin_file.options.optimize_mode == .ReleaseSmall) {
23262328 dg.addFnAttr(llvm_fn, "minsize");
23272329 dg.addFnAttr(llvm_fn, "optsize");
23282330 }
2329 if (dg.module.comp.bin_file.options.tsan) {
2331 if (comp.bin_file.options.tsan) {
23302332 dg.addFnAttr(llvm_fn, "sanitize_thread");
23312333 }
2332 // TODO add target-cpu and target-features fn attributes
2334 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 }
23332340 }
23342341
23352342 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 {
239239
240240 pub const getAlignment = LLVMGetAlignment;
241241 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;
242245};
243246
244247pub const Type = opaque {