[compiler-rt] r269719 - [profile] Add portability macro for atomic fetch_and_add

Xinliang David Li via llvm-commits llvm-commits at lists.llvm.org
Mon May 16 16:01:03 PDT 2016


Author: davidxl
Date: Mon May 16 18:01:03 2016
New Revision: 269719

URL: http://llvm.org/viewvc/llvm-project?rev=269719&view=rev
Log:
[profile] Add portability macro for atomic fetch_and_add

This is another enabler patch to support value profiling
without dynamic memory allocation.


Modified:
    compiler-rt/trunk/lib/profile/InstrProfilingPort.h
    compiler-rt/trunk/lib/profile/InstrProfilingUtil.c
    compiler-rt/trunk/lib/profile/InstrProfilingUtil.h

Modified: compiler-rt/trunk/lib/profile/InstrProfilingPort.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/profile/InstrProfilingPort.h?rev=269719&r1=269718&r2=269719&view=diff
==============================================================================
--- compiler-rt/trunk/lib/profile/InstrProfilingPort.h (original)
+++ compiler-rt/trunk/lib/profile/InstrProfilingPort.h Mon May 16 18:01:03 2016
@@ -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, ...)                                                  \

Modified: compiler-rt/trunk/lib/profile/InstrProfilingUtil.c
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/profile/InstrProfilingUtil.c?rev=269719&r1=269718&r2=269719&view=diff
==============================================================================
--- compiler-rt/trunk/lib/profile/InstrProfilingUtil.c (original)
+++ compiler-rt/trunk/lib/profile/InstrProfilingUtil.c Mon May 16 18:01:03 2016
@@ -51,6 +51,13 @@ uint32_t lprofBoolCmpXchg(void **Ptr, vo
   }
   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

Modified: compiler-rt/trunk/lib/profile/InstrProfilingUtil.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/profile/InstrProfilingUtil.h?rev=269719&r1=269718&r2=269719&view=diff
==============================================================================
--- compiler-rt/trunk/lib/profile/InstrProfilingUtil.h (original)
+++ compiler-rt/trunk/lib/profile/InstrProfilingUtil.h Mon May 16 18:01:03 2016
@@ -23,5 +23,6 @@ static inline char *getenv(const char *n
 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 */




More information about the llvm-commits mailing list