[compiler-rt] [XRay][SystemZ] Use stckf for non-clang compilers (PR #125289)
via llvm-commits
llvm-commits at lists.llvm.org
Fri Jan 31 12:40:43 PST 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-xray
Author: Kai Nacke (redstar)
<details>
<summary>Changes</summary>
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.
---
Full diff: https://github.com/llvm/llvm-project/pull/125289.diff
1 Files Affected:
- (modified) compiler-rt/lib/xray/xray_tsc.h (+6)
``````````diff
diff --git a/compiler-rt/lib/xray/xray_tsc.h b/compiler-rt/lib/xray/xray_tsc.h
index 17e06c7035d85c..06f509cd1b09b9 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 {
``````````
</details>
https://github.com/llvm/llvm-project/pull/125289
More information about the llvm-commits
mailing list