Skip to content

Commit d905c7e

Browse files
authored
[XRay][SystemZ] Use stckf for non-clang compilers (#125289)
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.
1 parent da05341 commit d905c7e

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

compiler-rt/lib/xray/xray_tsc.h

+6
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,13 @@ namespace __xray {
9696
inline bool probeRequiredCPUFeatures() XRAY_NEVER_INSTRUMENT { return true; }
9797

9898
ALWAYS_INLINE uint64_t readTSC(uint8_t &CPU) XRAY_NEVER_INSTRUMENT {
99+
#if __has_builtin(__builtin_readcyclecounter)
99100
return __builtin_readcyclecounter();
101+
#else
102+
uint64_t Cycles;
103+
asm volatile("stckf %0" : : "Q"(Cycles) : "cc");
104+
return Cycles;
105+
#endif
100106
}
101107

102108
inline uint64_t getTSCFrequency() XRAY_NEVER_INSTRUMENT {

0 commit comments

Comments
 (0)