Skip to content

Commit 562c3aa

Browse files
committed
[LLVM] Add LLVM_<proj>_RUNTIME_TARGETS to set targets per-project
Summary: Currently, the runtimes build allow users to optionally build for multiple target architectures via the `LLVM_RUNTIME_TARGETS` option. Once problem is that this applies to every single runtime the user has enabled, when it's possible that we may wish to enable a different set for just one target. The motivating example here is for handling GPU targets as cross-compiling. We want to be able to perform something like `LLVM_RUNTIME_TARGETS=amdgcn-amd-amdhsa;nvptx64-nvidia-cuda` to build runtimes targeting the GPU. However, the current support would force the other runtimes to be built for the GPU, when this definitely will not work. This patch attempts to work around this in a generic way by letting individual targets overload the set of enabled runtimes triples. The expected use would be to enable something like the following for targeting the GPU `libc` and in the future the GPU `libcxx`. ``` -DLLVM_ENABLE_PROJECTS='openmp;libcxx;libcxx-abi;libc' -DLLVM_LIBC_RUNTIME_TARGETS='nvptx64-nvidia-cuda;amdgcn-amd-amdhsa' ```
1 parent 2dbfa84 commit 562c3aa

File tree

1 file changed

+66
-37
lines changed

1 file changed

+66
-37
lines changed

llvm/runtimes/CMakeLists.txt

Lines changed: 66 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -209,12 +209,13 @@ foreach(entry ${runtimes})
209209
endforeach()
210210

211211
function(runtime_default_target)
212-
cmake_parse_arguments(ARG "" "" "DEPENDS;CMAKE_ARGS;PREFIXES" ${ARGN})
212+
cmake_parse_arguments(ARG "" "" "DEPENDS;CMAKE_ARGS;PREFIXES;RUNTIMES" ${ARGN})
213213

214214
include(${LLVM_BINARY_DIR}/runtimes/Components.cmake OPTIONAL)
215215
set(SUB_CHECK_TARGETS ${SUB_CHECK_TARGETS} PARENT_SCOPE)
216216
set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS ${LLVM_BINARY_DIR}/runtimes/Components.cmake)
217217

218+
set(LLVM_ENABLE_RUNTIMES ${ARG_RUNTIMES})
218219
foreach(runtime_name ${RUNTIME_NAMES})
219220
list(APPEND extra_targets
220221
${runtime_name}
@@ -269,11 +270,12 @@ endfunction()
269270
# runtime_register_target(name)
270271
# Utility function to register external runtime target.
271272
function(runtime_register_target name)
272-
cmake_parse_arguments(ARG "" "BASE_NAME" "DEPENDS;CMAKE_ARGS;EXTRA_ARGS" ${ARGN})
273+
cmake_parse_arguments(ARG "" "BASE_NAME" "DEPENDS;CMAKE_ARGS;EXTRA_ARGS;RUNTIMES" ${ARGN})
273274
include(${LLVM_BINARY_DIR}/runtimes/${name}/Components.cmake OPTIONAL)
274275
set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS ${LLVM_BINARY_DIR}/runtimes/${name}/Components.cmake)
275276

276277
set(runtime_names ${RUNTIME_NAMES})
278+
set(LLVM_ENABLE_RUNTIMES ${ARG_RUNTIMES})
277279
foreach(_name IN ITEMS ${ARG_BASE_NAME} ${name})
278280
if(RUNTIMES_${_name}_LLVM_ENABLE_RUNTIMES)
279281
set(runtime_names)
@@ -449,39 +451,65 @@ if(runtimes)
449451
endforeach()
450452
endif()
451453
endif()
452-
if(NOT LLVM_RUNTIME_TARGETS)
453-
runtime_default_target(
454-
DEPENDS ${builtins_dep} ${extra_deps}
455-
CMAKE_ARGS ${libc_cmake_args}
456-
PREFIXES ${prefixes})
457-
set(test_targets check-runtimes)
454+
455+
# Get the list of all target triples requested for this build.
456+
if (LLVM_RUNTIME_TARGETS)
457+
set(runtime_targets ${LLVM_RUNTIME_TARGETS})
458458
else()
459-
if("default" IN_LIST LLVM_RUNTIME_TARGETS)
459+
set(runtime_targets "default")
460+
endif()
461+
set(extra_targets "")
462+
foreach(proj ${LLVM_ENABLE_RUNTIMES})
463+
string(TOUPPER "${proj}" canon_name)
464+
string(REGEX REPLACE "-" "_" canon_name ${canon_name})
465+
if(LLVM_${canon_name}_RUNTIME_TARGETS)
466+
list(APPEND extra_targets ${LLVM_${canon_name}_RUNTIME_TARGETS})
467+
endif()
468+
endforeach()
469+
list(REMOVE_DUPLICATES runtime_targets)
470+
471+
# If we have any non-default triples we need to create custom targets.
472+
if(NOT "default" IN_LIST runtime_targets AND NOT "default" IN_LIST extra_targets)
473+
add_custom_target(runtimes)
474+
add_custom_target(runtimes-configure)
475+
add_custom_target(install-runtimes)
476+
add_custom_target(install-runtimes-stripped)
477+
if(LLVM_INCLUDE_TESTS)
478+
add_custom_target(check-runtimes)
479+
add_custom_target(runtimes-test-depends)
480+
set(test_targets "")
481+
endif()
482+
if(LLVM_RUNTIME_DISTRIBUTION_COMPONENTS)
483+
foreach(component ${LLVM_RUNTIME_DISTRIBUTION_COMPONENTS})
484+
add_custom_target(${component})
485+
add_custom_target(install-${component})
486+
add_custom_target(install-${component}-stripped)
487+
endforeach()
488+
endif()
489+
endif()
490+
491+
# Register each requested target triple using the projects that requested that
492+
# target.
493+
foreach(name ${runtime_targets} ${extra_targets})
494+
set(enabled_runtimes "")
495+
foreach(proj ${LLVM_ENABLE_RUNTIMES})
496+
string(TOUPPER "${proj}" canon_name)
497+
string(REGEX REPLACE "-" "_" canon_name ${canon_name})
498+
if(NOT LLVM_${canon_name}_RUNTIME_TARGETS AND ${name} IN_LIST runtime_targets)
499+
list(APPEND enabled_runtimes ${proj})
500+
elseif(${name} IN_LIST LLVM_${canon_name}_RUNTIME_TARGETS)
501+
list(APPEND enabled_runtimes ${proj})
502+
endif()
503+
endforeach()
504+
505+
if("${name}" STREQUAL "default")
460506
runtime_default_target(
461507
DEPENDS ${builtins_dep} ${extra_deps}
462508
CMAKE_ARGS ${libc_cmake_args}
463-
PREFIXES ${prefixes})
464-
list(REMOVE_ITEM LLVM_RUNTIME_TARGETS "default")
509+
PREFIXES ${prefixes}
510+
RUNTIMES ${enabled_runtimes})
511+
set(test_targets check-runtimes)
465512
else()
466-
add_custom_target(runtimes)
467-
add_custom_target(runtimes-configure)
468-
add_custom_target(install-runtimes)
469-
add_custom_target(install-runtimes-stripped)
470-
if(LLVM_INCLUDE_TESTS)
471-
add_custom_target(check-runtimes)
472-
add_custom_target(runtimes-test-depends)
473-
set(test_targets "")
474-
endif()
475-
if(LLVM_RUNTIME_DISTRIBUTION_COMPONENTS)
476-
foreach(component ${LLVM_RUNTIME_DISTRIBUTION_COMPONENTS})
477-
add_custom_target(${component})
478-
add_custom_target(install-${component})
479-
add_custom_target(install-${component}-stripped)
480-
endforeach()
481-
endif()
482-
endif()
483-
484-
foreach(name ${LLVM_RUNTIME_TARGETS})
485513
if(builtins_dep)
486514
if (LLVM_BUILTIN_TARGETS)
487515
set(builtins_dep_name "${builtins_dep}-${name}")
@@ -495,21 +523,22 @@ if(runtimes)
495523
runtime_register_target(${name}
496524
DEPENDS ${builtins_dep_name} ${hdrgen_deps}
497525
CMAKE_ARGS -DLLVM_DEFAULT_TARGET_TRIPLE=${name} ${libc_cmake_args}
526+
RUNTIMES ${enabled_runtimes}
498527
EXTRA_ARGS TARGET_TRIPLE ${name})
499-
endforeach()
500528

501-
foreach(multilib ${LLVM_RUNTIME_MULTILIBS})
502-
foreach(name ${LLVM_RUNTIME_MULTILIB_${multilib}_TARGETS})
529+
foreach(multilib ${LLVM_RUNTIME_MULTILIBS})
503530
runtime_register_target(${name}+${multilib}
504531
DEPENDS runtimes-${name}
505532
CMAKE_ARGS -DLLVM_DEFAULT_TARGET_TRIPLE=${name}
506-
-DLLVM_RUNTIMES_PREFIX=${name}/
507-
-DLLVM_RUNTIMES_LIBDIR_SUBDIR=${multilib}
533+
-DLLVM_ENABLE_RUNTIMES="${enabled_runtimes}"
534+
-DLLVM_RUNTIMES_PREFIX=${name}/
535+
-DLLVM_RUNTIMES_LIBDIR_SUBDIR=${multilib}
508536
BASE_NAME ${name}
537+
RUNTIMES ${enabled_runtimes}
509538
EXTRA_ARGS TARGET_TRIPLE ${name})
510539
endforeach()
511-
endforeach()
512-
endif()
540+
endif()
541+
endforeach()
513542

514543
if(NOT LLVM_BUILD_INSTRUMENTED AND CLANG_ENABLE_BOOTSTRAP)
515544
# TODO: This is a hack needed because the libcxx headers are copied into the

0 commit comments

Comments
 (0)