Skip to content

Commit

Permalink
Enable access to counter frequency for debugging
Browse files Browse the repository at this point in the history
  • Loading branch information
mfelsche committed Oct 13, 2024
1 parent 5dff420 commit 58af96e
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_cntfrq_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.cntfrq_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, CNTFRQ_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 void make_pmccntr_el0(compile_t *c) {
if (target_is_arm(c->opt->triple)) {
// i64 @internal.aarch64
Expand Down Expand Up @@ -1976,6 +1998,7 @@ void genprim_builtins(compile_t *c) {
make_cpuid(c);
make_rdtscp(c);
make_cntvct_el0(c);
make_cntfrq_el0(c);
make_pmccntr_el0(c);
}

Expand Down

0 comments on commit 58af96e

Please sign in to comment.