[compiler-rt] [XRay][SystemZ] Use stckf for non-clang compilers (PR #125289)
Kai Nacke via llvm-commits
llvm-commits at lists.llvm.org
Thu Feb 6 12:24:45 PST 2025
https://github.com/redstar updated https://github.com/llvm/llvm-project/pull/125289
>From f73b34410cbc59212f4d99724523a728670f2327 Mon Sep 17 00:00:00 2001
From: Kai Nacke <kai.peter.nacke at ibm.com>
Date: Fri, 31 Jan 2025 15:38:48 -0500
Subject: [PATCH 1/2] [XRay][SystemZ] Use stckf for non-clang compilers
Turns out there are users who use gcc to compile compiler-rt. Using the clang-specific builtin function `__builtin_readcyclecounter()` does not work in this case.
Solution is to use inline assembly using the stckf instruction in case the compiler is not clang.
---
compiler-rt/lib/xray/xray_tsc.h | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/compiler-rt/lib/xray/xray_tsc.h b/compiler-rt/lib/xray/xray_tsc.h
index 17e06c7035d85cc..06f509cd1b09b93 100644
--- a/compiler-rt/lib/xray/xray_tsc.h
+++ b/compiler-rt/lib/xray/xray_tsc.h
@@ -96,7 +96,13 @@ namespace __xray {
inline bool probeRequiredCPUFeatures() XRAY_NEVER_INSTRUMENT { return true; }
ALWAYS_INLINE uint64_t readTSC(uint8_t &CPU) XRAY_NEVER_INSTRUMENT {
+#if defined(__clang__)
return __builtin_readcyclecounter();
+#else
+ uint64_t Cycles;
+ asm volatile("stckf %0" : /* No output. */ : "Q"(Cycles) : "cc");
+ return Cycles;
+#endif
}
inline uint64_t getTSCFrequency() XRAY_NEVER_INSTRUMENT {
>From f157cbe613b6ef1500e53e911bd3f52f54297e6c Mon Sep 17 00:00:00 2001
From: Kai Nacke <kai.peter.nacke at ibm.com>
Date: Thu, 6 Feb 2025 15:24:33 -0500
Subject: [PATCH 2/2] Address review comments.
---
compiler-rt/lib/xray/xray_tsc.h | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/compiler-rt/lib/xray/xray_tsc.h b/compiler-rt/lib/xray/xray_tsc.h
index 06f509cd1b09b93..118b6f00e33ea53 100644
--- a/compiler-rt/lib/xray/xray_tsc.h
+++ b/compiler-rt/lib/xray/xray_tsc.h
@@ -96,11 +96,11 @@ namespace __xray {
inline bool probeRequiredCPUFeatures() XRAY_NEVER_INSTRUMENT { return true; }
ALWAYS_INLINE uint64_t readTSC(uint8_t &CPU) XRAY_NEVER_INSTRUMENT {
-#if defined(__clang__)
+#if __has_builtin(__builtin_readcyclecounter)
return __builtin_readcyclecounter();
#else
uint64_t Cycles;
- asm volatile("stckf %0" : /* No output. */ : "Q"(Cycles) : "cc");
+ asm volatile("stckf %0" : : "Q"(Cycles) : "cc");
return Cycles;
#endif
}
More information about the llvm-commits
mailing list