[compiler-rt] r255173 - [PGO] Add cmake check to determine atomics op availability

Xinliang David Li via llvm-commits llvm-commits at lists.llvm.org
Wed Dec 9 14:46:50 PST 2015


Author: davidxl
Date: Wed Dec  9 16:46:49 2015
New Revision: 255173

URL: http://llvm.org/viewvc/llvm-project?rev=255173&view=rev
Log:
[PGO] Add cmake check to determine atomics op availability

This allows the profile runtime to pick the right impl
for cmp&swap for a given target.

Differential Revision: http://reviews.llvm.org/D15248



Modified:
    compiler-rt/trunk/lib/profile/CMakeLists.txt

Modified: compiler-rt/trunk/lib/profile/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/profile/CMakeLists.txt?rev=255173&r1=255172&r2=255173&view=diff
==============================================================================
--- compiler-rt/trunk/lib/profile/CMakeLists.txt (original)
+++ compiler-rt/trunk/lib/profile/CMakeLists.txt Wed Dec  9 16:46:49 2015
@@ -1,3 +1,27 @@
+
+CHECK_CXX_SOURCE_COMPILES("
+#ifdef _MSC_VER
+#include <Intrin.h> /* Workaround for PR19898. */
+#include <windows.h>
+#endif
+int main() {
+#ifdef _MSC_VER
+        volatile LONG val = 1;
+        MemoryBarrier();
+        InterlockedCompareExchange(&val, 0, 1);
+        InterlockedIncrement(&val);
+        InterlockedDecrement(&val);
+#else
+        volatile unsigned long val = 1;
+        __sync_synchronize();
+        __sync_val_compare_and_swap(&val, 1, 0);
+        __sync_add_and_fetch(&val, 1);
+        __sync_sub_and_fetch(&val, 1);
+#endif
+        return 0;
+      }
+" COMPILER_RT_TARGET_HAS_ATOMICS)
+
 add_custom_target(profile)
 
 set(PROFILE_SOURCES
@@ -21,6 +45,12 @@ else()
      -fPIC)
 endif()
 
+if(COMPILER_RT_TARGET_HAS_ATOMICS)
+ set(EXTRA_FLAGS
+     ${EXTRA_FLAGS}
+     -DCOMPILER_RT_HAS_ATOMICS=1)
+endif() 
+
 if(APPLE)
   add_compiler_rt_runtime(clang_rt.profile
     STATIC




More information about the llvm-commits mailing list