diff options
author | Xinliang David Li <davidxl@google.com> | 2015-12-09 22:46:49 +0000 |
---|---|---|
committer | Xinliang David Li <davidxl@google.com> | 2015-12-09 22:46:49 +0000 |
commit | 7960a36478db1ebfc99962c8a81387fbc651f4f1 (patch) | |
tree | d54b5d889a8bfe4a37078b737c56f83fb256c56a /lib/profile | |
parent | 7fbd9917dcc3cb590205331b82d8efc7322de09b (diff) |
[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
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@255173 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/profile')
-rw-r--r-- | lib/profile/CMakeLists.txt | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/lib/profile/CMakeLists.txt b/lib/profile/CMakeLists.txt index 0da9e0147..0e726d83b 100644 --- a/lib/profile/CMakeLists.txt +++ b/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; + } +" 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 |