Skip to content

Commit

Permalink
Add builtin function for accessing pmu cycle counter on aarch64
Browse files Browse the repository at this point in the history
  • Loading branch information
mfelsche committed Oct 13, 2024
1 parent 3bcf79b commit 55af8d6
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/libponyc/codegen/genprim.c
Original file line number Diff line number Diff line change
Expand Up @@ -1888,6 +1888,28 @@ static void make_cntvct_el0(compile_t *c) {
}
}

static void make_pmccntr_el0(compile_t *c) {
if (target_is_arm(c->opt->triple)) {
// i64 @internal.aarch64
LLVMTypeRef f_type_f = LLVMFunctionType(c->i64, &c->void_type, 0, false);
LLVMValueRef fun =
codegen_addfun(c, "internal.aarch64.pmccntr_el0", f_type_f, false);

LLVMSetFunctionCallConv(fun, LLVMCCallConv);
codegen_startfun(c, fun, NULL, NULL, NULL, false);
LLVMValueRef get_cntvct_el0 =
LLVMGetInlineAsm(f_type_f, "MRS $0, PMCCNTR_EL0", 18, "=r", 2, false,
false, LLVMInlineAsmDialectATT, false);

LLVMValueRef result =
LLVMBuildCall2(c->builder, f_type_f, get_cntvct_el0, NULL, 0, "");
genfun_build_ret(c, result);
codegen_finishfun(c);
} else {
(void)c;
}
}

static LLVMValueRef make_signature_array(compile_t *c, compile_type_t *c_t,
const char *signature) {
LLVMValueRef args[SIGNATURE_LENGTH];
Expand Down Expand Up @@ -1954,6 +1976,7 @@ void genprim_builtins(compile_t *c) {
make_cpuid(c);
make_rdtscp(c);
make_cntvct_el0(c);
make_pmccntr_el0(c);
}

void genprim_reachable_init(compile_t *c, ast_t *program) {
Expand Down

0 comments on commit 55af8d6

Please sign in to comment.