Skip to content

Commit 33f285d

Browse files
committed
[libc] Only enable LLVM_FULL_BUILD_MODE by default for GPU targets
Summary: Currently we have a conditional that turns the full build on by default if it is a default target. This used to work fine when the GPU was the only target that was ever present. However, we've recently changed to allow building multiple of these at the same time. That means we should have the ability to build overlay mode in the CPU mode and full build in the GPU mode. This patch makes some simple adjustments to pass the arguments per-triple. This slightly extends the existing `-DRUNTIMES_` argument support to also transform any extra CMake inputs rather than just the passed CMake variables.
1 parent 29762e3 commit 33f285d

File tree

2 files changed

+37
-22
lines changed

2 files changed

+37
-22
lines changed

llvm/CMakeLists.txt

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -173,16 +173,15 @@ endforeach()
173173
set(NEED_LIBC_HDRGEN FALSE)
174174
if("libc" IN_LIST LLVM_ENABLE_RUNTIMES)
175175
set(NEED_LIBC_HDRGEN TRUE)
176-
else()
177-
foreach(_name ${LLVM_RUNTIME_TARGETS})
178-
if("libc" IN_LIST RUNTIMES_${_name}_LLVM_ENABLE_RUNTIMES)
179-
set(NEED_LIBC_HDRGEN TRUE)
180-
if("${_name}" STREQUAL "amdgcn-amd-amdhsa" OR "${_name}" STREQUAL "nvptx64-nvidia-cuda")
181-
set(LLVM_LIBC_GPU_BUILD ON)
182-
endif()
183-
endif()
184-
endforeach()
185176
endif()
177+
foreach(_name ${LLVM_RUNTIME_TARGETS})
178+
if("libc" IN_LIST RUNTIMES_${_name}_LLVM_ENABLE_RUNTIMES)
179+
set(NEED_LIBC_HDRGEN TRUE)
180+
if("${_name}" STREQUAL "amdgcn-amd-amdhsa" OR "${_name}" STREQUAL "nvptx64-nvidia-cuda")
181+
set(LLVM_LIBC_GPU_BUILD ON)
182+
endif()
183+
endif()
184+
endforeach()
186185
if(NEED_LIBC_HDRGEN)
187186
# To build the libc runtime, we need to be able to build few libc build
188187
# tools from the "libc" project. So, we add it to the list of enabled

llvm/runtimes/CMakeLists.txt

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,14 @@ function(runtime_register_target name)
358358
endif()
359359
endif()
360360
endforeach()
361+
foreach(variable_name ${${name}_extra_args})
362+
string(FIND "${variable_name}" "-DRUNTIMES_${extra_name}_" out)
363+
if("${out}" EQUAL 0)
364+
string(REPLACE "-DRUNTIMES_${extra_name}_" "" new_name ${variable_name})
365+
string(REPLACE ";" "|" new_value "${new_name}")
366+
list(APPEND ${name}_extra_args "-D${new_value}")
367+
endif()
368+
endforeach()
361369
endforeach()
362370

363371
set_enable_per_target_runtime_dir()
@@ -438,21 +446,29 @@ if(runtimes)
438446
if(NOT hdrgen_exe)
439447
message(FATAL_ERROR "libc-hdrgen executable missing")
440448
endif()
441-
set(libc_cmake_args "-DLIBC_HDRGEN_EXE=${hdrgen_exe}"
442-
"-DLLVM_LIBC_FULL_BUILD=ON")
449+
list(APPEND libc_cmake_args "-DLIBC_HDRGEN_EXE=${hdrgen_exe}")
443450
list(APPEND extra_deps ${hdrgen_deps})
444-
if(LLVM_LIBC_GPU_BUILD)
445-
list(APPEND libc_cmake_args "-DLLVM_LIBC_GPU_BUILD=ON")
446-
# The `libc` project may require '-DCUDAToolkit_ROOT' in GPU mode.
447-
if(CUDAToolkit_ROOT)
448-
list(APPEND libc_cmake_args "-DCUDAToolkit_ROOT=${CUDAToolkit_ROOT}")
449-
endif()
450-
foreach(dep clang-offload-packager nvptx-arch amdgpu-arch)
451-
if(TARGET ${dep})
452-
list(APPEND extra_deps ${dep})
453-
endif()
454-
endforeach()
451+
endif()
452+
if(LLVM_LIBC_GPU_BUILD)
453+
list(APPEND libc_cmake_args "-DLLVM_LIBC_GPU_BUILD=ON")
454+
if("libc" IN_LIST RUNTIMES_amdgcn-amd-amdhsa_LLVM_ENABLE_RUNTIMES)
455+
list(APPEND libc_cmake_args "-DRUNTIMES_amdgcn-amd-amdhsa_LLVM_LIBC_FULL_BUILD=ON")
455456
endif()
457+
if("libc" IN_LIST RUNTIMES_nvptx64-nvidia-cuda_LLVM_ENABLE_RUNTIMES)
458+
list(APPEND libc_cmake_args "-DRUNTIMES_nvptx64-nvidia-cuda_LLVM_LIBC_FULL_BUILD=ON")
459+
endif()
460+
# The `libc` project may require '-DCUDAToolkit_ROOT' in GPU mode.
461+
if(CUDAToolkit_ROOT)
462+
list(APPEND libc_cmake_args "-DCUDAToolkit_ROOT=${CUDAToolkit_ROOT}")
463+
endif()
464+
foreach(dep clang-offload-packager nvptx-arch amdgpu-arch)
465+
if(TARGET ${dep})
466+
list(APPEND extra_deps ${dep})
467+
endif()
468+
endforeach()
469+
endif()
470+
if(LLVM_LIBC_FULL_BUILD)
471+
list(APPEND libc_cmake_args "-DLLVM_LIBC_FULL_BUILD=ON")
456472
endif()
457473
if(NOT LLVM_RUNTIME_TARGETS)
458474
runtime_default_target(

0 commit comments

Comments
 (0)