diff options
| author | gingerBill <bill@gingerbill.org> | 2021-04-14 17:15:28 +0100 |
|---|---|---|
| committer | gingerBill <bill@gingerbill.org> | 2021-04-14 17:15:28 +0100 |
| commit | 9adec628c1c6b3d24f7a8642bbf5c0c84586d161 (patch) | |
| tree | 7f4785bcb7615922f71fc657bab029218f9be996 /src/llvm_backend.cpp | |
| parent | 3e54cddf641e7d8ca79b0cbb12e1595727a9e888 (diff) | |
Add `@(cold)` attribute to procedure declarations
Diffstat (limited to 'src/llvm_backend.cpp')
| -rw-r--r-- | src/llvm_backend.cpp | 35 |
1 files changed, 33 insertions, 2 deletions
diff --git a/src/llvm_backend.cpp b/src/llvm_backend.cpp index eb4f3c300..16c2e35e5 100644 --- a/src/llvm_backend.cpp +++ b/src/llvm_backend.cpp @@ -2464,9 +2464,12 @@ void lb_add_proc_attribute_at_index(lbProcedure *p, isize index, char const *nam } void lb_add_proc_attribute_at_index(lbProcedure *p, isize index, char const *name) { - lb_add_proc_attribute_at_index(p, index, name, cast(u64)true); + lb_add_proc_attribute_at_index(p, index, name, 0); } +void lb_add_attribute_to_proc(lbModule *m, LLVMValueRef proc_value, char const *name, u64 value=0) { + LLVMAddAttributeAtIndex(proc_value, LLVMAttributeIndex_FunctionIndex, lb_create_enum_attribute(m->ctx, name, value)); +} void lb_ensure_abi_function_type(lbModule *m, lbProcedure *p) { @@ -2556,6 +2559,23 @@ lbProcedure *lb_create_procedure(lbModule *m, Entity *entity) { LLVMSetFunctionCallConv(p->value, cc_kind); } + if (entity->flags & EntityFlag_Cold) { + lb_add_attribute_to_proc(m, p->value, "cold"); + } + + if (pt->Proc.diverging) { + lb_add_attribute_to_proc(m, p->value, "noreturn"); + } + + switch (p->inlining) { + case ProcInlining_inline: + lb_add_attribute_to_proc(m, p->value, "alwaysinline"); + break; + case ProcInlining_no_inline: + lb_add_attribute_to_proc(m, p->value, "noinline"); + break; + } + // lbCallingConventionKind cc_kind = lbCallingConvention_C; // // TODO(bill): Clean up this logic // if (build_context.metrics.os != TargetOs_js) { @@ -8073,7 +8093,18 @@ lbValue lb_emit_call_internal(lbProcedure *p, lbValue value, lbValue return_ptr, } LLVMValueRef ret = LLVMBuildCall2(p->builder, fnp, fn, args, arg_count, ""); - // LLVMValueRef ret = LLVMBuildCall(p->builder, fn, args, arg_count, ""); + + switch (inlining) { + case ProcInlining_none: + break; + case ProcInlining_inline: + // LLVMAddAttributeAtIndex(ret, LLVMAttributeIndex_FunctionIndex, lb_create_enum_attribute(p->module->ctx, "alwaysinline")); + break; + case ProcInlining_no_inline: + // LLVMAddAttributeAtIndex(ret, LLVMAttributeIndex_FunctionIndex, lb_create_enum_attribute(p->module->ctx, "noinline")); + break; + } + lbValue res = {}; res.value = ret; res.type = abi_rt; |