diff options
author | Xinliang David Li <davidxl@google.com> | 2016-05-16 23:01:03 +0000 |
---|---|---|
committer | Xinliang David Li <davidxl@google.com> | 2016-05-16 23:01:03 +0000 |
commit | e3e27c07259bbfe1cc4615ad518f51d143cda0cc (patch) | |
tree | 601ce8793a7b841d774615864f7f1d38db6f464f /lib | |
parent | c87f7410a648527864dee5c0c887a4ecaa09579a (diff) |
[profile] Add portability macro for atomic fetch_and_add
This is another enabler patch to support value profiling
without dynamic memory allocation.
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@269719 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r-- | lib/profile/InstrProfilingPort.h | 10 | ||||
-rw-r--r-- | lib/profile/InstrProfilingUtil.c | 7 | ||||
-rw-r--r-- | lib/profile/InstrProfilingUtil.h | 3 |
3 files changed, 19 insertions, 1 deletions
diff --git a/lib/profile/InstrProfilingPort.h b/lib/profile/InstrProfilingPort.h index 94c2e13b4..aeb0021c6 100644 --- a/lib/profile/InstrProfilingPort.h +++ b/lib/profile/InstrProfilingPort.h @@ -44,19 +44,29 @@ #define COMPILER_RT_BOOL_CMPXCHG(Ptr, OldV, NewV) \ (InterlockedCompareExchange64((LONGLONG volatile *)Ptr, (LONGLONG)NewV, \ (LONGLONG)OldV) == (LONGLONG)OldV) +#define COMPILER_RT_PTR_FETCH_ADD(DomType, PtrVar, PtrIncr) \ + (DomType *)InterlockedExchangeAdd64((LONGLONG volatile *)&PtrVar, \ + (LONGLONG)sizeof(DomType) * PtrIncr) #else /* !defined(_WIN64) */ #define COMPILER_RT_BOOL_CMPXCHG(Ptr, OldV, NewV) \ (InterlockedCompareExchange((LONG volatile *)Ptr, (LONG)NewV, (LONG)OldV) == \ (LONG)OldV) +#define COMPILER_RT_PTR_FETCH_ADD(DomType, PtrVar, PtrIncr) \ + (DomType *)InterlockedExchangeAdd((LONG volatile *)&PtrVar, \ + (LONG)sizeof(DomType) * PtrIncr) #endif #else /* !defined(_MSC_VER) */ #define COMPILER_RT_BOOL_CMPXCHG(Ptr, OldV, NewV) \ __sync_bool_compare_and_swap(Ptr, OldV, NewV) +#define COMPILER_RT_PTR_FETCH_ADD(DomType, PtrVar, PtrIncr) \ + (DomType *)__sync_fetch_and_add((long *)&PtrVar, sizeof(DomType) * PtrIncr) #endif #else /* COMPILER_RT_HAS_ATOMICS != 1 */ #include "InstrProfilingUtil.h" #define COMPILER_RT_BOOL_CMPXCHG(Ptr, OldV, NewV) \ lprofBoolCmpXchg((void **)Ptr, OldV, NewV) +#define COMPILER_RT_PTR_FETCH_ADD(DomType, PtrVar, PtrIncr) \ + (DomType *)lprofPtrFetchAdd((void **)&PtrVar, sizeof(DomType) * PtrIncr) #endif #define PROF_ERR(Format, ...) \ diff --git a/lib/profile/InstrProfilingUtil.c b/lib/profile/InstrProfilingUtil.c index 04bdb3e4c..eb79d4222 100644 --- a/lib/profile/InstrProfilingUtil.c +++ b/lib/profile/InstrProfilingUtil.c @@ -51,6 +51,13 @@ uint32_t lprofBoolCmpXchg(void **Ptr, void *OldV, void *NewV) { } return 0; } +COMPILER_RT_VISIBILITY +void *lprofPtrFetchAdd(void **Mem, long ByteIncr) { + void *Old = *Mem; + *((char **)Mem) += ByteIncr; + return Old; +} + #endif #ifdef COMPILER_RT_HAS_UNAME diff --git a/lib/profile/InstrProfilingUtil.h b/lib/profile/InstrProfilingUtil.h index aa40e1c2f..b2bdd6519 100644 --- a/lib/profile/InstrProfilingUtil.h +++ b/lib/profile/InstrProfilingUtil.h @@ -23,5 +23,6 @@ static inline char *getenv(const char *name) { return NULL; } int lprofGetHostName(char *Name, int Len); unsigned lprofBoolCmpXchg(void **Ptr, void *OldV, void *NewV); +void *lprofPtrFetchAdd(void **Mem, long ByteIncr); -#endif /* PROFILE_INSTRPROFILINGUTIL_H */ +#endif /* PROFILE_INSTRPROFILINGUTIL_H */ |