Skip to content

Commit a70563f

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 a057506 commit a70563f

File tree

1 file changed

+64
-38
lines changed

1 file changed

+64
-38
lines changed

llvm/runtimes/CMakeLists.txt

Lines changed: 64 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ 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)
@@ -236,6 +236,7 @@ function(runtime_default_target)
236236
endif()
237237

238238
set_enable_per_target_runtime_dir()
239+
set(LLVM_ENABLE_RUNTIMES ${ARG_RUNTIMES})
239240

240241
llvm_ExternalProject_Add(runtimes
241242
${CMAKE_CURRENT_SOURCE_DIR}/../../runtimes
@@ -269,7 +270,7 @@ 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

@@ -338,6 +339,7 @@ function(runtime_register_target name)
338339
endif()
339340

340341
set(${name}_extra_args ${ARG_CMAKE_ARGS})
342+
set(LLVM_ENABLE_RUNTIMES ${ARG_RUNTIMES})
341343
string(REPLACE ";" "|" LLVM_ENABLE_RUNTIMES_PASSTHROUGH "${LLVM_ENABLE_RUNTIMES}")
342344
list(APPEND ${name}_extra_args -DLLVM_ENABLE_RUNTIMES=${LLVM_ENABLE_RUNTIMES_PASSTHROUGH})
343345
list(APPEND ${name}_extra_args -DLLVM_USE_LINKER=${LLVM_USE_LINKER})
@@ -449,39 +451,62 @@ 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)
458-
else()
459-
if("default" IN_LIST LLVM_RUNTIME_TARGETS)
454+
455+
# Get the list of all target triples requested for this build.
456+
set(runtime_targets "default")
457+
if (LLVM_RUNTIME_TARGETS)
458+
set(runtime_targets ${LLVM_RUNTIME_TARGETS})
459+
endif()
460+
foreach(proj ${LLVM_ENABLE_RUNTIMES})
461+
string(TOUPPER "${proj}" canon_name)
462+
string(REGEX REPLACE "-" "_" canon_name ${canon_name})
463+
if(LLVM_${canon_name}_RUNTIME_TARGETS)
464+
list(APPEND extra_targets ${LLVM_${canon_name}_RUNTIME_TARGETS})
465+
endif()
466+
endforeach()
467+
list(REMOVE_DUPLICATES extra_targets)
468+
469+
# If we have any non-default triples we need to create custom targets.
470+
if(NOT "default" IN_LIST runtime_targets AND NOT "default" IN_LIST extra_targets)
471+
add_custom_target(runtimes)
472+
add_custom_target(runtimes-configure)
473+
add_custom_target(install-runtimes)
474+
add_custom_target(install-runtimes-stripped)
475+
if(LLVM_INCLUDE_TESTS)
476+
add_custom_target(check-runtimes)
477+
add_custom_target(runtimes-test-depends)
478+
set(test_targets "")
479+
endif()
480+
if(LLVM_RUNTIME_DISTRIBUTION_COMPONENTS)
481+
foreach(component ${LLVM_RUNTIME_DISTRIBUTION_COMPONENTS})
482+
add_custom_target(${component})
483+
add_custom_target(install-${component})
484+
add_custom_target(install-${component}-stripped)
485+
endforeach()
486+
endif()
487+
endif()
488+
489+
# Register each requested target triple using the projects that requested that
490+
# target.
491+
foreach(name ${runtime_targets} ${extra_targets})
492+
set(enabled_runtimes "")
493+
foreach(proj ${LLVM_ENABLE_RUNTIMES})
494+
string(TOUPPER "${proj}" canon_name)
495+
string(REGEX REPLACE "-" "_" canon_name ${canon_name})
496+
if((NOT LLVM_${canon_name}_RUNTIME_TARGETS AND ${name} IN_LIST runtime_targets)
497+
OR ${name} IN_LIST LLVM_${canon_name}_RUNTIME_TARGETS)
498+
list(APPEND enabled_runtimes ${proj})
499+
endif()
500+
endforeach()
501+
502+
if("${name}" STREQUAL "default")
460503
runtime_default_target(
461504
DEPENDS ${builtins_dep} ${extra_deps}
462505
CMAKE_ARGS ${libc_cmake_args}
463-
PREFIXES ${prefixes})
464-
list(REMOVE_ITEM LLVM_RUNTIME_TARGETS "default")
506+
PREFIXES ${prefixes}
507+
RUNTIMES ${enabled_runtimes})
508+
set(test_targets check-runtimes)
465509
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})
485510
if(builtins_dep)
486511
if (LLVM_BUILTIN_TARGETS)
487512
set(builtins_dep_name "${builtins_dep}-${name}")
@@ -495,21 +520,22 @@ if(runtimes)
495520
runtime_register_target(${name}
496521
DEPENDS ${builtins_dep_name} ${hdrgen_deps}
497522
CMAKE_ARGS -DLLVM_DEFAULT_TARGET_TRIPLE=${name} ${libc_cmake_args}
523+
RUNTIMES ${enabled_runtimes}
498524
EXTRA_ARGS TARGET_TRIPLE ${name})
499-
endforeach()
500525

501-
foreach(multilib ${LLVM_RUNTIME_MULTILIBS})
502-
foreach(name ${LLVM_RUNTIME_MULTILIB_${multilib}_TARGETS})
526+
foreach(multilib ${LLVM_RUNTIME_MULTILIBS})
503527
runtime_register_target(${name}+${multilib}
504528
DEPENDS runtimes-${name}
505529
CMAKE_ARGS -DLLVM_DEFAULT_TARGET_TRIPLE=${name}
506-
-DLLVM_RUNTIMES_PREFIX=${name}/
507-
-DLLVM_RUNTIMES_LIBDIR_SUBDIR=${multilib}
530+
-DLLVM_ENABLE_RUNTIMES="${enabled_runtimes}"
531+
-DLLVM_RUNTIMES_PREFIX=${name}/
532+
-DLLVM_RUNTIMES_LIBDIR_SUBDIR=${multilib}
508533
BASE_NAME ${name}
534+
RUNTIMES ${enabled_runtimes}
509535
EXTRA_ARGS TARGET_TRIPLE ${name})
510536
endforeach()
511-
endforeach()
512-
endif()
537+
endif()
538+
endforeach()
513539

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

0 commit comments

Comments
 (0)