[compiler-rt] [compiler-rt] Initial support for builtins on GPU targets (PR #95304)

Saleem Abdulrasool via llvm-commits llvm-commits at lists.llvm.org
Wed Jun 12 14:24:47 PDT 2024


================
@@ -388,6 +394,31 @@ macro(construct_compiler_rt_default_triple)
     set(COMPILER_RT_DEFAULT_TARGET_ARCH "i386")
   endif()
 
+  # If we are directly targeting a GPU we need to check that the compiler is
+  # compatible and pass some default arguments.
+  if(COMPILER_RT_DEFAULT_TARGET_ONLY)
+    if("${COMPILER_RT_DEFAULT_TARGET_ARCH}" MATCHES "amdgcn|nvptx")
+      # Ensure the compiler is a valid clang when building the GPU target.
+      set(req_ver "${LLVM_VERSION_MAJOR}.${LLVM_VERSION_MINOR}.${LLVM_VERSION_PATCH}")
+      if(LLVM_VERSION_MAJOR AND NOT (CMAKE_CXX_COMPILER_ID MATCHES "[Cc]lang" AND
+         ${CMAKE_CXX_COMPILER_VERSION} VERSION_EQUAL "${req_ver}"))
+        message(FATAL_ERROR "Cannot build compiler-rt for GPU. CMake compiler "
+                            "'${CMAKE_CXX_COMPILER_ID} ${CMAKE_CXX_COMPILER_VERSION}' "
+                            " is not 'Clang ${req_ver}'.")
+      endif()
+      set(COMPILER_RT_GPU_TARGET TRUE)
+    endif()
+
+    # Pass the necessary flags to make flag detection work.
+    if("${COMPILER_RT_DEFAULT_TARGET_ARCH}" MATCHES "amdgcn")
+      set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -nogpulib")
+    elseif("${COMPILER_RT_DEFAULT_TARGET_ARCH}" MATCHES "nvptx")
+      # FIXME: This doesn't work with no CUDA installation.
+      set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -march=sm_75")
+      message(WARNING ${CMAKE_REQUIRED_FLAGS})
----------------
compnerd wrote:

I was specifically referring to `message(WARNING ...)`. The alteration of `CMAKE_REQUIRED_FLAGS` makes sense for the testing of the compiler. However, is that needed with `CMAKE_C_COMPILER_WORKS`?

https://github.com/llvm/llvm-project/pull/95304


More information about the llvm-commits mailing list