Skip to content

Commit ab08233

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 ab08233

File tree

1 file changed

+63
-39
lines changed

1 file changed

+63
-39
lines changed

llvm/runtimes/CMakeLists.txt

Lines changed: 63 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -253,8 +253,7 @@ function(runtime_default_target)
253253
${COMMON_CMAKE_ARGS}
254254
${RUNTIMES_CMAKE_ARGS}
255255
${ARG_CMAKE_ARGS}
256-
PASSTHROUGH_PREFIXES LLVM_ENABLE_RUNTIMES
257-
LLVM_USE_LINKER
256+
PASSTHROUGH_PREFIXES LLVM_USE_LINKER
258257
${ARG_PREFIXES}
259258
EXTRA_TARGETS ${extra_targets}
260259
${test_targets}
@@ -338,8 +337,6 @@ function(runtime_register_target name)
338337
endif()
339338

340339
set(${name}_extra_args ${ARG_CMAKE_ARGS})
341-
string(REPLACE ";" "|" LLVM_ENABLE_RUNTIMES_PASSTHROUGH "${LLVM_ENABLE_RUNTIMES}")
342-
list(APPEND ${name}_extra_args -DLLVM_ENABLE_RUNTIMES=${LLVM_ENABLE_RUNTIMES_PASSTHROUGH})
343340
list(APPEND ${name}_extra_args -DLLVM_USE_LINKER=${LLVM_USE_LINKER})
344341

345342
get_cmake_property(variable_names VARIABLES)
@@ -449,39 +446,65 @@ if(runtimes)
449446
endforeach()
450447
endif()
451448
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)
449+
450+
# Get the list of all target triples requested for this build.
451+
set(runtime_targets "default")
452+
if (LLVM_RUNTIME_TARGETS)
453+
set(runtime_targets ${LLVM_RUNTIME_TARGETS})
454+
endif()
455+
set(all_targets ${runtime_targets})
456+
foreach(proj ${LLVM_ENABLE_RUNTIMES})
457+
string(TOUPPER "${proj}" canon_name)
458+
string(REGEX REPLACE "-" "_" canon_name ${canon_name})
459+
if(LLVM_${canon_name}_RUNTIME_TARGETS)
460+
list(APPEND all_targets ${LLVM_${canon_name}_RUNTIME_TARGETS})
461+
endif()
462+
endforeach()
463+
list(REMOVE_DUPLICATES all_targets)
464+
465+
# If we have any non-default triples we need to create custom targets.
466+
if(NOT "default" IN_LIST all_targets)
467+
add_custom_target(runtimes)
468+
add_custom_target(runtimes-configure)
469+
add_custom_target(install-runtimes)
470+
add_custom_target(install-runtimes-stripped)
471+
if(LLVM_INCLUDE_TESTS)
472+
add_custom_target(check-runtimes)
473+
add_custom_target(runtimes-test-depends)
474+
set(test_targets "")
475+
endif()
476+
if(LLVM_RUNTIME_DISTRIBUTION_COMPONENTS)
477+
foreach(component ${LLVM_RUNTIME_DISTRIBUTION_COMPONENTS})
478+
add_custom_target(${component})
479+
add_custom_target(install-${component})
480+
add_custom_target(install-${component}-stripped)
481+
endforeach()
482+
endif()
483+
endif()
484+
485+
# Register each requested target triple using the projects that requested that
486+
# target. It should be used if it is in the base list of enabled runtimes and
487+
# not overridden on the project level.
488+
foreach(name ${all_targets})
489+
set(_enabled_runtimes "")
490+
foreach(proj ${LLVM_ENABLE_RUNTIMES})
491+
string(TOUPPER "${proj}" canon_name)
492+
string(REGEX REPLACE "-" "_" canon_name ${canon_name})
493+
if((NOT LLVM_${canon_name}_RUNTIME_TARGETS AND ${name} IN_LIST runtime_targets)
494+
OR ${name} IN_LIST LLVM_${canon_name}_RUNTIME_TARGETS)
495+
list(APPEND _enabled_runtimes ${proj})
496+
endif()
497+
endforeach()
498+
string(REPLACE ";" "|" enabled_runtimes "${_enabled_runtimes}")
499+
500+
if("${name}" STREQUAL "default")
460501
runtime_default_target(
461502
DEPENDS ${builtins_dep} ${extra_deps}
462-
CMAKE_ARGS ${libc_cmake_args}
503+
CMAKE_ARGS -DLLVM_ENABLE_RUNTIMES=${enabled_runtimes}
504+
${libc_cmake_args}
463505
PREFIXES ${prefixes})
464-
list(REMOVE_ITEM LLVM_RUNTIME_TARGETS "default")
506+
set(test_targets check-runtimes)
465507
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})
485508
if(builtins_dep)
486509
if (LLVM_BUILTIN_TARGETS)
487510
set(builtins_dep_name "${builtins_dep}-${name}")
@@ -494,22 +517,23 @@ if(runtimes)
494517

495518
runtime_register_target(${name}
496519
DEPENDS ${builtins_dep_name} ${hdrgen_deps}
497-
CMAKE_ARGS -DLLVM_DEFAULT_TARGET_TRIPLE=${name} ${libc_cmake_args}
520+
CMAKE_ARGS -DLLVM_ENABLE_RUNTIMES=${enabled_runtimes}
521+
-DLLVM_DEFAULT_TARGET_TRIPLE=${name}
522+
${libc_cmake_args}
498523
EXTRA_ARGS TARGET_TRIPLE ${name})
499-
endforeach()
500524

501-
foreach(multilib ${LLVM_RUNTIME_MULTILIBS})
502-
foreach(name ${LLVM_RUNTIME_MULTILIB_${multilib}_TARGETS})
525+
foreach(multilib ${LLVM_RUNTIME_MULTILIBS})
503526
runtime_register_target(${name}+${multilib}
504527
DEPENDS runtimes-${name}
505528
CMAKE_ARGS -DLLVM_DEFAULT_TARGET_TRIPLE=${name}
529+
-DLLVM_ENABLE_RUNTIMES=${enabled_runtimes}
506530
-DLLVM_RUNTIMES_PREFIX=${name}/
507531
-DLLVM_RUNTIMES_LIBDIR_SUBDIR=${multilib}
508532
BASE_NAME ${name}
509533
EXTRA_ARGS TARGET_TRIPLE ${name})
510534
endforeach()
511-
endforeach()
512-
endif()
535+
endif()
536+
endforeach()
513537

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

0 commit comments

Comments
 (0)