Skip to content

Commit 9ff130a

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 9ff130a

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,63 @@ 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+
foreach(proj ${LLVM_ENABLE_RUNTIMES})
456+
string(TOUPPER "${proj}" canon_name)
457+
string(REGEX REPLACE "-" "_" canon_name ${canon_name})
458+
if(LLVM_${canon_name}_RUNTIME_TARGETS)
459+
list(APPEND extra_targets ${LLVM_${canon_name}_RUNTIME_TARGETS})
460+
endif()
461+
endforeach()
462+
list(REMOVE_DUPLICATES extra_targets)
463+
464+
# If we have any non-default triples we need to create custom targets.
465+
if(NOT "default" IN_LIST runtime_targets AND NOT "default" IN_LIST extra_targets)
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+
# Register each requested target triple using the projects that requested that
485+
# target.
486+
foreach(name ${runtime_targets} ${extra_targets})
487+
set(_enabled_runtimes "")
488+
foreach(proj ${LLVM_ENABLE_RUNTIMES})
489+
string(TOUPPER "${proj}" canon_name)
490+
string(REGEX REPLACE "-" "_" canon_name ${canon_name})
491+
if((NOT LLVM_${canon_name}_RUNTIME_TARGETS AND ${name} IN_LIST runtime_targets)
492+
OR ${name} IN_LIST LLVM_${canon_name}_RUNTIME_TARGETS)
493+
list(APPEND _enabled_runtimes ${proj})
494+
endif()
495+
endforeach()
496+
string(REPLACE ";" "|" enabled_runtimes "${_enabled_runtimes}")
497+
498+
if("${name}" STREQUAL "default")
460499
runtime_default_target(
461500
DEPENDS ${builtins_dep} ${extra_deps}
462-
CMAKE_ARGS ${libc_cmake_args}
501+
CMAKE_ARGS -DLLVM_ENABLE_RUNTIMES=${enabled_runtimes}
502+
${libc_cmake_args}
463503
PREFIXES ${prefixes})
464-
list(REMOVE_ITEM LLVM_RUNTIME_TARGETS "default")
504+
set(test_targets check-runtimes)
465505
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})
485506
if(builtins_dep)
486507
if (LLVM_BUILTIN_TARGETS)
487508
set(builtins_dep_name "${builtins_dep}-${name}")
@@ -494,22 +515,25 @@ if(runtimes)
494515

495516
runtime_register_target(${name}
496517
DEPENDS ${builtins_dep_name} ${hdrgen_deps}
497-
CMAKE_ARGS -DLLVM_DEFAULT_TARGET_TRIPLE=${name} ${libc_cmake_args}
518+
CMAKE_ARGS -DLLVM_ENABLE_RUNTIMES=${enabled_runtimes}
519+
-DLLVM_DEFAULT_TARGET_TRIPLE=${name}
520+
${libc_cmake_args}
521+
RUNTIMES ${enabled_runtimes}
498522
EXTRA_ARGS TARGET_TRIPLE ${name})
499-
endforeach()
500523

501-
foreach(multilib ${LLVM_RUNTIME_MULTILIBS})
502-
foreach(name ${LLVM_RUNTIME_MULTILIB_${multilib}_TARGETS})
524+
foreach(multilib ${LLVM_RUNTIME_MULTILIBS})
503525
runtime_register_target(${name}+${multilib}
504526
DEPENDS runtimes-${name}
505527
CMAKE_ARGS -DLLVM_DEFAULT_TARGET_TRIPLE=${name}
528+
-DLLVM_ENABLE_RUNTIMES=${enabled_runtimes}
506529
-DLLVM_RUNTIMES_PREFIX=${name}/
507530
-DLLVM_RUNTIMES_LIBDIR_SUBDIR=${multilib}
508531
BASE_NAME ${name}
532+
RUNTIMES ${enabled_runtimes}
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)