summaryrefslogtreecommitdiff
path: root/lib/profile
diff options
context:
space:
mode:
authorXinliang David Li <davidxl@google.com>2015-12-04 04:22:59 +0000
committerXinliang David Li <davidxl@google.com>2015-12-04 04:22:59 +0000
commitb1bbcff9b249907148d7ae52c263d00a5a3575a2 (patch)
tree7ad1c9a219c1ca6220a7b5be966d998837c663c2 /lib/profile
parent99512f07f811ca50729609674005456abd9cb873 (diff)
[PGO] Fix mips test failure with new test case
cmp&swap is not well supported -- the new test case triggers some assembler error. This is a partial fix to the general problem (lack of atomics operation support for certain targets). git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@254701 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/profile')
-rw-r--r--lib/profile/InstrProfiling.c23
1 files changed, 19 insertions, 4 deletions
diff --git a/lib/profile/InstrProfiling.c b/lib/profile/InstrProfiling.c
index 216452953..e3ad505c4 100644
--- a/lib/profile/InstrProfiling.c
+++ b/lib/profile/InstrProfiling.c
@@ -23,6 +23,22 @@
return 0; \
}
+#ifdef _MIPS_ARCH
+LLVM_LIBRARY_VISIBILITY
+uint32_t BoolCmpXchg(void **Ptr, void *OldV, void *NewV) {
+ void *R = *Ptr;
+ if (R == OldV) {
+ *Ptr = NewV;
+ return 1;
+ }
+ return 0;
+}
+#define BOOL_CMPXCHG(Ptr, OldV, NewV) BoolCmpXchg((void **)Ptr, OldV, NewV)
+#else
+#define BOOL_CMPXCHG(Ptr, OldV, NewV) \
+ __sync_bool_compare_and_swap(Ptr, OldV, NewV)
+#endif
+
LLVM_LIBRARY_VISIBILITY uint64_t __llvm_profile_get_magic(void) {
return sizeof(void *) == sizeof(uint64_t) ? (INSTR_PROF_RAW_MAGIC_64)
: (INSTR_PROF_RAW_MAGIC_32);
@@ -106,7 +122,7 @@ static int allocateValueProfileCounters(__llvm_profile_data *Data) {
(ValueProfNode **)calloc(NumVSites, sizeof(ValueProfNode *));
if (!Mem)
return 0;
- if (!__sync_bool_compare_and_swap(&Data->Values, 0, Mem)) {
+ if (!BOOL_CMPXCHG(&Data->Values, 0, Mem)) {
free(Mem);
return 0;
}
@@ -171,10 +187,9 @@ __llvm_profile_instrument_target(uint64_t TargetValue, void *Data,
uint32_t Success = 0;
if (!ValueCounters[CounterIndex])
- Success = __sync_bool_compare_and_swap(&ValueCounters[CounterIndex], 0,
- CurrentVNode);
+ Success = BOOL_CMPXCHG(&ValueCounters[CounterIndex], 0, CurrentVNode);
else if (PrevVNode && !PrevVNode->Next)
- Success = __sync_bool_compare_and_swap(&(PrevVNode->Next), 0, CurrentVNode);
+ Success = BOOL_CMPXCHG(&(PrevVNode->Next), 0, CurrentVNode);
if (!Success) {
free(CurrentVNode);