mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-06 23:58:50 +00:00
#Fix 1615 Replace llvm.readcyclecounter with cntvct_el0 on arm64
This commit is contained in:
@@ -1402,14 +1402,23 @@ lbValue lb_build_builtin_proc(lbProcedure *p, Ast *expr, TypeAndValue const &tv,
|
|||||||
|
|
||||||
case BuiltinProc_read_cycle_counter:
|
case BuiltinProc_read_cycle_counter:
|
||||||
{
|
{
|
||||||
char const *name = "llvm.readcyclecounter";
|
|
||||||
unsigned id = LLVMLookupIntrinsicID(name, gb_strlen(name));
|
|
||||||
GB_ASSERT_MSG(id != 0, "Unable to find %s", name);
|
|
||||||
LLVMValueRef ip = LLVMGetIntrinsicDeclaration(p->module->mod, id, nullptr, 0);
|
|
||||||
|
|
||||||
lbValue res = {};
|
lbValue res = {};
|
||||||
res.value = LLVMBuildCall(p->builder, ip, nullptr, 0, "");
|
|
||||||
res.type = tv.type;
|
res.type = tv.type;
|
||||||
|
|
||||||
|
if (build_context.metrics.arch == TargetArch_arm64) {
|
||||||
|
LLVMTypeRef func_type = LLVMFunctionType(LLVMInt64TypeInContext(p->module->ctx), nullptr, 0, false);
|
||||||
|
bool has_side_effects = false;
|
||||||
|
LLVMValueRef the_asm = llvm_get_inline_asm(func_type, str_lit("mrs x9, cntvct_el0"), str_lit("=r"), has_side_effects);
|
||||||
|
GB_ASSERT(the_asm != nullptr);
|
||||||
|
res.value = LLVMBuildCall2(p->builder, func_type, the_asm, nullptr, 0, "");
|
||||||
|
} else {
|
||||||
|
char const *name = "llvm.readcyclecounter";
|
||||||
|
unsigned id = LLVMLookupIntrinsicID(name, gb_strlen(name));
|
||||||
|
GB_ASSERT_MSG(id != 0, "Unable to find %s", name);
|
||||||
|
LLVMValueRef ip = LLVMGetIntrinsicDeclaration(p->module->mod, id, nullptr, 0);
|
||||||
|
|
||||||
|
res.value = LLVMBuildCall(p->builder, ip, nullptr, 0, "");
|
||||||
|
}
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1779,7 +1779,7 @@ LLVMValueRef llvm_get_inline_asm(LLVMTypeRef func_type, String const &str, Strin
|
|||||||
return LLVMGetInlineAsm(func_type,
|
return LLVMGetInlineAsm(func_type,
|
||||||
cast(char *)str.text, cast(size_t)str.len,
|
cast(char *)str.text, cast(size_t)str.len,
|
||||||
cast(char *)clobbers.text, cast(size_t)clobbers.len,
|
cast(char *)clobbers.text, cast(size_t)clobbers.len,
|
||||||
/*HasSideEffects*/true, /*IsAlignStack*/false,
|
has_side_effects, is_align_stack,
|
||||||
dialect
|
dialect
|
||||||
#if LLVM_VERSION_MAJOR >= 13
|
#if LLVM_VERSION_MAJOR >= 13
|
||||||
, /*CanThrow*/false
|
, /*CanThrow*/false
|
||||||
|
|||||||
Reference in New Issue
Block a user