Skip to content

Commit 2d503b9

Browse files
authored
[LLVM] Simplify GPU runtimes flag handling (llvm#159802)
Summary: The AMDGPU hack can be removed, and we no longer need to skip 90% of the `HandleLLVMOptions` if we work around NVPTX earlier. Simplifies the interface by removing duplicated logic and keeps the GPU targets from being weirdly divergent on some flags.
1 parent 8fcb712 commit 2d503b9

File tree

6 files changed

+6
-38
lines changed

6 files changed

+6
-38
lines changed

compiler-rt/cmake/Modules/CompilerRTUtils.cmake

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -418,11 +418,9 @@ macro(construct_compiler_rt_default_triple)
418418
# Pass the necessary flags to make flag detection work.
419419
if("${COMPILER_RT_DEFAULT_TARGET_ARCH}" MATCHES "amdgcn")
420420
set(COMPILER_RT_GPU_BUILD ON)
421-
set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -nogpulib")
422421
elseif("${COMPILER_RT_DEFAULT_TARGET_ARCH}" MATCHES "nvptx")
423422
set(COMPILER_RT_GPU_BUILD ON)
424-
set(CMAKE_REQUIRED_FLAGS
425-
"${CMAKE_REQUIRED_FLAGS} -flto -c -Wno-unused-command-line-argument")
423+
set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -flto -c")
426424
endif()
427425
endif()
428426

flang-rt/CMakeLists.txt

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -221,15 +221,6 @@ endif()
221221
# System Introspection #
222222
########################
223223

224-
# The GPU targets require a few mandatory arguments to make the standard CMake
225-
# check flags happy.
226-
if ("${LLVM_RUNTIMES_TARGET}" MATCHES "^amdgcn")
227-
set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -nogpulib")
228-
elseif ("${LLVM_RUNTIMES_TARGET}" MATCHES "^nvptx")
229-
set(CMAKE_REQUIRED_FLAGS
230-
"${CMAKE_REQUIRED_FLAGS} -flto -c -Wno-unused-command-line-argument")
231-
endif()
232-
233224
include(CheckCXXSymbolExists)
234225
include(CheckCXXSourceCompiles)
235226
check_cxx_symbol_exists(strerror_r string.h HAVE_STRERROR_R)

libc/cmake/modules/prepare_libc_gpu_build.cmake

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,6 @@ endif()
2020
if(LIBC_TARGET_TRIPLE)
2121
set(CMAKE_REQUIRED_FLAGS "--target=${LIBC_TARGET_TRIPLE}")
2222
endif()
23-
if(LIBC_TARGET_ARCHITECTURE_IS_AMDGPU)
24-
set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -nogpulib")
25-
elseif(LIBC_TARGET_ARCHITECTURE_IS_NVPTX)
26-
set(CMAKE_REQUIRED_FLAGS
27-
"${CMAKE_REQUIRED_FLAGS} -flto -c -Wno-unused-command-line-argument")
28-
endif()
2923

3024
# Optionally set up a job pool to limit the number of GPU tests run in parallel.
3125
# This is sometimes necessary as running too many tests in parallel can cause

llvm/cmake/modules/HandleLLVMOptions.cmake

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -144,12 +144,6 @@ if( LLVM_ENABLE_ASSERTIONS )
144144
endif()
145145
endif()
146146

147-
# If we are targeting a GPU architecture in a runtimes build we want to ignore
148-
# all the standard flag handling.
149-
if(LLVM_RUNTIMES_GPU_BUILD)
150-
return()
151-
endif()
152-
153147
if(LLVM_ENABLE_EXPENSIVE_CHECKS)
154148
# When LLVM_ENABLE_EXPENSIVE_CHECKS is ON, LLVM will intercept errors
155149
# using assert(). An explicit check is performed here.

openmp/CMakeLists.txt

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -99,14 +99,6 @@ else()
9999
set(CMAKE_CXX_EXTENSIONS NO)
100100
endif()
101101

102-
# Targeting the GPU directly requires a few flags to make CMake happy.
103-
if("${CMAKE_CXX_COMPILER_TARGET}" MATCHES "^amdgcn")
104-
set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -nogpulib")
105-
elseif("${CMAKE_CXX_COMPILER_TARGET}" MATCHES "^nvptx")
106-
set(CMAKE_REQUIRED_FLAGS
107-
"${CMAKE_REQUIRED_FLAGS} -flto -c -Wno-unused-command-line-argument")
108-
endif()
109-
110102
# Check and set up common compiler flags.
111103
include(config-ix)
112104
include(HandleOpenMPOptions)

runtimes/CMakeLists.txt

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -181,15 +181,14 @@ if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
181181
endif()
182182
endif()
183183

184+
# The NVPTX target needs to override linking to pass compiler flag checks.
185+
if("${LLVM_RUNTIMES_TARGET}" MATCHES "^nvptx")
186+
set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -flto -c")
187+
endif()
188+
184189
# Avoid checking whether the compiler is working.
185190
set(LLVM_COMPILER_CHECKED ON)
186191

187-
# This can be used to detect whether we're targeting a GPU architecture.
188-
if("${LLVM_RUNTIMES_TARGET}" MATCHES "^amdgcn" OR
189-
"${LLVM_RUNTIMES_TARGET}" MATCHES "^nvptx64")
190-
set(LLVM_RUNTIMES_GPU_BUILD ON)
191-
endif()
192-
193192
# Handle common options used by all runtimes.
194193
include(AddLLVM)
195194
include(HandleLLVMOptions)

0 commit comments

Comments
 (0)