| author | |
| committer | |
| log | 573f3f8d487dfd1f56ab71b96ad23af1a2d4162e |
| tree | 53b6492aa6c417fa16cc1c590c6238111c00e0b7 |
| parent | 07a71fc3221dfba05caea5a50ebe3dac5c76d643 |
* Only use Cold Calling Convention on x86
* Add the cold attribute to functions marked with coldcc4 files changed, 19 insertions(+), 5 deletions(-)
src/analyze.cpp+7-5| ... | @@ -713,12 +713,14 @@ TypeTableEntry *get_fn_type(CodeGen *g, FnTypeId *fn_type_id) { | ... | @@ -713,12 +713,14 @@ TypeTableEntry *get_fn_type(CodeGen *g, FnTypeId *fn_type_id) { |
| 713 | fn_type->data.fn.fn_type_id = *fn_type_id; | 713 | fn_type->data.fn.fn_type_id = *fn_type_id; |
| 714 | 714 | ||
| 715 | if (fn_type_id->is_cold) { | 715 | if (fn_type_id->is_cold) { |
| 716 | if (g->zig_target.arch.arch == ZigLLVM_arm) { | 716 | // cold calling convention only works on x86. |
| 717 | // TODO we want to use coldcc here but it's causing a segfault on ARM | 717 | // but we can add the cold attribute later. |
| 718 | // https://llvm.org/bugs/show_bug.cgi?id=31875 | 718 | if (g->zig_target.arch.arch == ZigLLVM_x86 || |
| 719 | fn_type->data.fn.calling_convention = LLVMCCallConv; | 719 | g->zig_target.arch.arch == ZigLLVM_x86_64) |
| 720 | } else { | 720 | { |
| 721 | fn_type->data.fn.calling_convention = LLVMColdCallConv; | 721 | fn_type->data.fn.calling_convention = LLVMColdCallConv; |
| 722 | } else { | ||
| 723 | fn_type->data.fn.calling_convention = LLVMFastCallConv; | ||
| 722 | } | 724 | } |
| 723 | } else if (fn_type_id->is_extern) { | 725 | } else if (fn_type_id->is_extern) { |
| 724 | fn_type->data.fn.calling_convention = LLVMCCallConv; | 726 | fn_type->data.fn.calling_convention = LLVMCCallConv; |
src/codegen.cpp+3| ... | @@ -268,6 +268,9 @@ static LLVMValueRef fn_llvm_value(CodeGen *g, FnTableEntry *fn_table_entry) { | ... | @@ -268,6 +268,9 @@ static LLVMValueRef fn_llvm_value(CodeGen *g, FnTableEntry *fn_table_entry) { |
| 268 | LLVMAddFunctionAttr(fn_table_entry->llvm_value, LLVMNoReturnAttribute); | 268 | LLVMAddFunctionAttr(fn_table_entry->llvm_value, LLVMNoReturnAttribute); |
| 269 | } | 269 | } |
| 270 | LLVMSetFunctionCallConv(fn_table_entry->llvm_value, fn_type->data.fn.calling_convention); | 270 | LLVMSetFunctionCallConv(fn_table_entry->llvm_value, fn_type->data.fn.calling_convention); |
| 271 | if (fn_type->data.fn.fn_type_id.is_cold) { | ||
| 272 | ZigLLVMAddFunctionAttrCold(fn_table_entry->llvm_value); | ||
| 273 | } | ||
| 271 | LLVMAddFunctionAttr(fn_table_entry->llvm_value, LLVMNoUnwindAttribute); | 274 | LLVMAddFunctionAttr(fn_table_entry->llvm_value, LLVMNoUnwindAttribute); |
| 272 | if (!g->is_release_build && fn_table_entry->fn_inline != FnInlineAlways) { | 275 | if (!g->is_release_build && fn_table_entry->fn_inline != FnInlineAlways) { |
| 273 | ZigLLVMAddFunctionAttr(fn_table_entry->llvm_value, "no-frame-pointer-elim", "true"); | 276 | ZigLLVMAddFunctionAttr(fn_table_entry->llvm_value, "no-frame-pointer-elim", "true"); |
src/zig_llvm.cpp+8| ... | @@ -561,6 +561,14 @@ void ZigLLVMAddFunctionAttr(LLVMValueRef fn_ref, const char *attr_name, const ch | ... | @@ -561,6 +561,14 @@ void ZigLLVMAddFunctionAttr(LLVMValueRef fn_ref, const char *attr_name, const ch |
| 561 | func->setAttributes(new_attr_set); | 561 | func->setAttributes(new_attr_set); |
| 562 | } | 562 | } |
| 563 | 563 | ||
| 564 | void ZigLLVMAddFunctionAttrCold(LLVMValueRef fn_ref) { | ||
| 565 | Function *func = unwrap<Function>(fn_ref); | ||
| 566 | const AttributeSet attr_set = func->getAttributes(); | ||
| 567 | const AttributeSet new_attr_set = attr_set.addAttribute(func->getContext(), AttributeSet::FunctionIndex, | ||
| 568 | Attribute::Cold); | ||
| 569 | func->setAttributes(new_attr_set); | ||
| 570 | } | ||
| 571 | |||
| 564 | 572 | ||
| 565 | static_assert((Triple::ArchType)ZigLLVM_LastArchType == Triple::LastArchType, ""); | 573 | static_assert((Triple::ArchType)ZigLLVM_LastArchType == Triple::LastArchType, ""); |
| 566 | static_assert((Triple::VendorType)ZigLLVM_LastVendorType == Triple::LastVendorType, ""); | 574 | static_assert((Triple::VendorType)ZigLLVM_LastVendorType == Triple::LastVendorType, ""); |
src/zig_llvm.hpp+1| ... | @@ -165,6 +165,7 @@ ZigLLVMDILocation *ZigLLVMGetDebugLoc(unsigned line, unsigned col, ZigLLVMDIScop | ... | @@ -165,6 +165,7 @@ ZigLLVMDILocation *ZigLLVMGetDebugLoc(unsigned line, unsigned col, ZigLLVMDIScop |
| 165 | void ZigLLVMSetFastMath(LLVMBuilderRef builder_wrapped, bool on_state); | 165 | void ZigLLVMSetFastMath(LLVMBuilderRef builder_wrapped, bool on_state); |
| 166 | 166 | ||
| 167 | void ZigLLVMAddFunctionAttr(LLVMValueRef fn, const char *attr_name, const char *attr_value); | 167 | void ZigLLVMAddFunctionAttr(LLVMValueRef fn, const char *attr_name, const char *attr_value); |
| 168 | void ZigLLVMAddFunctionAttrCold(LLVMValueRef fn); | ||
| 168 | 169 | ||
| 169 | unsigned ZigLLVMGetPrefTypeAlignment(LLVMTargetDataRef TD, LLVMTypeRef Ty); | 170 | unsigned ZigLLVMGetPrefTypeAlignment(LLVMTargetDataRef TD, LLVMTypeRef Ty); |
| 170 | 171 |