<div dir="ltr">On Thu, Aug 11, 2016 at 6:29 PM, Chris Bieneman via llvm-commits <span dir="ltr"><<a href="mailto:llvm-commits@lists.llvm.org" target="_blank">llvm-commits@lists.llvm.org</a>></span> wrote:<br><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: cbieneman<br>
Date: Thu Aug 11 20:29:26 2016<br>
New Revision: 278454<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=278454&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project?rev=278454&view=rev</a><br>
Log:<br>
[CMake] If the compiler supports _Atomic include atomic.c in builtins libraries<br>
<br>
This fixes a long-standing TODO by implementing a compiler check for supporting the _Atomic keyword. If the _Atomic keyword is supported by the compiler we should include it in the builtin library sources.<br>
<br>
Modified:<br>
    compiler-rt/trunk/cmake/<wbr>Modules/BuiltinTests.cmake<br>
    compiler-rt/trunk/cmake/<wbr>builtin-config-ix.cmake<br>
    compiler-rt/trunk/lib/<wbr>builtins/CMakeLists.txt<br></blockquote><div><br></div><div>I think this belongs in 3.9 as well as otherwise you end up with the builtins missing the atomics which are needed for sizes which cannot be lowered directly to instructions.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Modified: compiler-rt/trunk/cmake/<wbr>Modules/BuiltinTests.cmake<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/cmake/Modules/BuiltinTests.cmake?rev=278454&r1=278453&r2=278454&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/compiler-rt/trunk/<wbr>cmake/Modules/BuiltinTests.<wbr>cmake?rev=278454&r1=278453&r2=<wbr>278454&view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- compiler-rt/trunk/cmake/<wbr>Modules/BuiltinTests.cmake (original)<br>
+++ compiler-rt/trunk/cmake/<wbr>Modules/BuiltinTests.cmake Thu Aug 11 20:29:26 2016<br>
@@ -3,11 +3,15 @@ include(<wbr>CMakeCheckCompilerFlagCommonPa<wbr>tt<br>
 # This function takes an OS and a list of architectures and identifies the<br>
 # subset of the architectures list that the installed toolchain can target.<br>
 function(try_compile_only output)<br>
+  cmake_parse_arguments(ARG "" "" "SOURCE;FLAGS" ${ARGN})<br>
+  if(NOT ARG_SOURCE)<br>
+    set(ARG_SOURCE "int foo(int x, int y) { return x + y; }\n")<br>
+  endif()<br>
   set(SIMPLE_C ${CMAKE_BINARY_DIR}${CMAKE_<wbr>FILES_DIRECTORY}/src.c)<br>
-  file(WRITE ${SIMPLE_C} "int foo(int x, int y) { return x + y; }\n")<br>
+  file(WRITE ${SIMPLE_C} "${ARG_SOURCE}\n")<br>
   string(REGEX MATCHALL "<[A-Za-z0-9_]*>" substitutions<br>
          ${CMAKE_C_COMPILE_OBJECT})<br>
-  string(REPLACE ";" " " extra_flags "${ARGN}")<br>
+  string(REPLACE ";" " " extra_flags "${ARG_FLAGS}")<br>
<br>
   set(test_compile_command "${CMAKE_C_COMPILE_OBJECT}")<br>
   foreach(substitution ${substitutions})<br>
@@ -63,7 +67,20 @@ endfunction()<br>
 function(builtin_check_c_<wbr>compiler_flag flag output)<br>
   if(NOT DEFINED ${output})<br>
     message(STATUS "Performing Test ${output}")<br>
-    try_compile_only(result ${flag})<br>
+    try_compile_only(result FLAGS ${flag})<br>
+    set(${output} ${result} CACHE INTERNAL "Compiler supports ${flag}")<br>
+    if(${result})<br>
+      message(STATUS "Performing Test ${output} - Success")<br>
+    else()<br>
+      message(STATUS "Performing Test ${output} - Failed")<br>
+    endif()<br>
+  endif()<br>
+endfunction()<br>
+<br>
+function(builtin_check_c_<wbr>compiler_source output source)<br>
+  if(NOT DEFINED ${output})<br>
+    message(STATUS "Performing Test ${output}")<br>
+    try_compile_only(result SOURCE ${source})<br>
     set(${output} ${result} CACHE INTERNAL "Compiler supports ${flag}")<br>
     if(${result})<br>
       message(STATUS "Performing Test ${output} - Success")<br>
<br>
Modified: compiler-rt/trunk/cmake/<wbr>builtin-config-ix.cmake<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/cmake/builtin-config-ix.cmake?rev=278454&r1=278453&r2=278454&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/compiler-rt/trunk/<wbr>cmake/builtin-config-ix.cmake?<wbr>rev=278454&r1=278453&r2=<wbr>278454&view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- compiler-rt/trunk/cmake/<wbr>builtin-config-ix.cmake (original)<br>
+++ compiler-rt/trunk/cmake/<wbr>builtin-config-ix.cmake Thu Aug 11 20:29:26 2016<br>
@@ -1,4 +1,5 @@<br>
 include(BuiltinTests)<br>
+include(CheckCSourceCompiles)<br>
<br>
 # Make all the tests only check the compiler<br>
 set(TEST_COMPILE_ONLY On)<br>
@@ -14,6 +15,15 @@ builtin_check_c_compiler_flag(<wbr>-mfloat-ab<br>
 builtin_check_c_compiler_flag(<wbr>-mfloat-abi=hard      COMPILER_RT_HAS_FLOAT_ABI_<wbr>HARD_FLAG)<br>
 builtin_check_c_compiler_flag(<wbr>-static               COMPILER_RT_HAS_STATIC_FLAG)<br>
<br>
+builtin_check_c_compiler_<wbr>source(COMPILER_RT_SUPPORTS_<wbr>ATOMIC_KEYWORD<br>
+"<br>
+int foo(int x, int y) {<br>
+ _Atomic int result = x * y;<br>
+ return result;<br>
+}<br>
+")<br>
+<br>
+<br>
 set(ARM64 aarch64)<br>
 set(ARM32 arm armhf)<br>
 set(X86 i386 i686)<br>
<br>
Modified: compiler-rt/trunk/lib/<wbr>builtins/CMakeLists.txt<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/builtins/CMakeLists.txt?rev=278454&r1=278453&r2=278454&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/compiler-rt/trunk/lib/<wbr>builtins/CMakeLists.txt?rev=<wbr>278454&r1=278453&r2=278454&<wbr>view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- compiler-rt/trunk/lib/<wbr>builtins/CMakeLists.txt (original)<br>
+++ compiler-rt/trunk/lib/<wbr>builtins/CMakeLists.txt Thu Aug 11 20:29:26 2016<br>
@@ -42,8 +42,6 @@ set(GENERIC_SOURCES<br>
   ashlti3.c<br>
   ashrdi3.c<br>
   ashrti3.c<br>
-  # FIXME: atomic.c may only be compiled if host compiler understands _Atomic<br>
-  # atomic.c<br>
   clear_cache.c<br>
   clzdi2.c<br>
   clzsi2.c<br>
@@ -166,6 +164,12 @@ set(GENERIC_SOURCES<br>
   umodsi3.c<br>
   umodti3.c)<br>
<br>
+if(COMPILER_RT_SUPPORTS_<wbr>ATOMIC_KEYWORD)<br>
+  set(GENERIC_SOURCES<br>
+    ${GENERIC_SOURCES}<br>
+    atomic.c)<br>
+endif()<br>
+<br>
 set(MSVC_SOURCES<br>
  divsc3.c<br>
  divdc3.c<br>
<br>
<br>
______________________________<wbr>_________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@lists.llvm.org">llvm-commits@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/<wbr>mailman/listinfo/llvm-commits</a><br>
</blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature" data-smartmail="gmail_signature">Saleem Abdulrasool<br>compnerd (at) compnerd (dot) org</div>
</div></div>