[PATCH] D15248: [PGO] Add check in cmake to detect if atomics operations are available for target

David Li via llvm-commits llvm-commits at lists.llvm.org
Fri Dec 4 14:52:10 PST 2015


davidxl created this revision.
davidxl added a reviewer: beanz.
davidxl added a subscriber: llvm-commits.

The check is similar to the one in cmake/modules/CheckAtomic.cmake

http://reviews.llvm.org/D15248

Files:
  lib/profile/CMakeLists.txt

Index: lib/profile/CMakeLists.txt
===================================================================
--- lib/profile/CMakeLists.txt
+++ lib/profile/CMakeLists.txt
@@ -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;
+      }
+" LLVM_TARGET_HAS_ATOMICS)
+
 add_custom_target(profile)
 
 set(PROFILE_SOURCES
@@ -21,6 +45,12 @@
      -fPIC)
 endif()
 
+if(LLVM_TARGET_HAS_ATOMICS)
+ set(EXTRA_FLAGS
+     ${EXTRA_FLAGS}
+     -DLLVM_HAS_ATOMICS=1)
+endif() 
+
 if(APPLE)
   add_compiler_rt_runtime(clang_rt.profile
     STATIC


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D15248.41944.patch
Type: text/x-patch
Size: 1066 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20151204/1f82654e/attachment.bin>


More information about the llvm-commits mailing list