[compiler-rt] [compiler-rt] Initial support for builtins on GPU targets (PR #95304)
Joseph Huber via llvm-commits
llvm-commits at lists.llvm.org
Wed Jun 12 15:34:54 PDT 2024
================
@@ -388,6 +394,30 @@ 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")
+ endif()
+ endif()
----------------
jhuber6 wrote:
True, but I'm just going off of the expected case where the compiler has an implicit `--target=` version. I'm assuming the base logic just checks if it can target any of them? The only logic I saw for that was in `base-config-ix.cmake` and it went off of the default target, so I'm unsure where else to modify.
https://github.com/llvm/llvm-project/pull/95304
More information about the llvm-commits
mailing list