[clang] [CIR] Support __builtin_readcyclecounter (PR #231531)
Steffen Larsen via cfe-commits
cfe-commits at lists.llvm.org
Tue Oct 13 08:48:41 PDT 2026
================
@@ -0,0 +1,11 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fclangir -emit-cir %s -o - | FileCheck %s -check-prefix=CIR
+// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fclangir -emit-llvm %s -o - | FileCheck %s -check-prefix=LLVM
+// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -emit-llvm %s -o - | FileCheck %s -check-prefix=LLVM
+
+// CIR-LABEL: cir.func {{.*}} @read_cycles(
+// CIR: %{{.+}} = cir.call_llvm_intrinsic "readcyclecounter" : () -> !u64i
+// LLVM-LABEL: @read_cycles(
+// LLVM: %{{.+}} = call i64 @llvm.readcyclecounter()
+unsigned long long read_cycles(void) {
+ return __builtin_readcyclecounter();
+}
----------------
steffenlarsen wrote:
Seems a very small thing to have an entire builtin test file for. Might there be another file it fits into? Or maybe we can implement `__builtin_readsteadycounter` as well and make it a "counter" builtin test file?
https://github.com/llvm/llvm-project/pull/231531
More information about the cfe-commits
mailing list