| ... | ... | @@ -2302,19 +2302,21 @@ pub const DeclGen = struct { |
| 2302 | 2302 | } |
| 2303 | 2303 | |
| 2304 | 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 | 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 | 2311 | dg.addFnAttrString(llvm_fn, "frame-pointer", "none"); |
| 2310 | 2312 | } else { |
| 2311 | 2313 | dg.addFnAttrString(llvm_fn, "frame-pointer", "all"); |
| 2312 | 2314 | } |
| 2313 | 2315 | dg.addFnAttr(llvm_fn, "nounwind"); |
| 2314 | | if (dg.module.comp.unwind_tables) { |
| 2316 | if (comp.unwind_tables) { |
| 2315 | 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 | 2320 | // The intent here is for compiler-rt and libc functions to not generate |
| 2319 | 2321 | // infinite recursion. For example, if we are compiling the memcpy function, |
| 2320 | 2322 | // and llvm detects that the body is equivalent to memcpy, it may replace the |
| ... | ... | @@ -2322,14 +2324,19 @@ pub const DeclGen = struct { |
| 2322 | 2324 | // overflow instead of performing memcpy. |
| 2323 | 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 | 2328 | dg.addFnAttr(llvm_fn, "minsize"); |
| 2327 | 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 | 2332 | dg.addFnAttr(llvm_fn, "sanitize_thread"); |
| 2331 | 2333 | } |
| 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 | } |
| 2333 | 2340 | } |
| 2334 | 2341 | |
| 2335 | 2342 | fn resolveGlobalDecl(dg: *DeclGen, decl_index: Module.Decl.Index) Error!*const llvm.Value { |