[LLVM] Replace use of LLVM_RUNTIMES_TARGET with LLVM_DEFAULT_TARGET_TRIPLE (#188303)

Summary:
This PR primarily changes using `LLVM_RUNTIMES_TARGET` to
`LLVM_DEFAULT_TARGET_TRIPLE`. The reason is that the default target
triple is the true cross-compiling architecture we are using, while the
runtimes_target can contain multilib strings like `+debug` or similar.

Additionally add the proper path handling to the OpenMP / Offload
libraries.
This commit is contained in:
Joseph Huber
2026-03-26 08:52:32 -05:00
committed by GitHub
parent e41e7b90f9
commit cc4727ae3b
7 changed files with 17 additions and 18 deletions

View File

@@ -139,7 +139,6 @@ cmake_path(NORMAL_PATH FLANG_RT_INSTALL_RESOURCE_LIB_PATH)
# Important: flang-rt user options must be prefixed with "FLANG_RT_". Variables
# with this prefix will be forwarded in bootstrap builds.
# Provide an interface to link against the LLVM libc/libc++ projects directly.
set(FLANG_RT_SUPPORTED_PROVIDERS system llvm)
set(FLANG_RT_LIBC_PROVIDER "system" CACHE STRING "Specify C library to use. Supported values are ${FLANG_RT_SUPPORTED_PROVIDERS}.")
@@ -169,7 +168,7 @@ endif ()
# TODO: Support tests for the GPU target.
set(FLANG_RT_INCLUDE_TESTS_default ${LLVM_INCLUDE_TESTS})
if ("${LLVM_RUNTIMES_TARGET}" MATCHES "^amdgcn|^nvptx")
if ("${LLVM_DEFAULT_TARGET_TRIPLE}" MATCHES "^amdgcn|^nvptx")
set(FLANG_RT_INCLUDE_TESTS_default OFF)
elseif (NOT FLANG_RT_ENABLE_STATIC AND NOT FLANG_RT_ENABLE_SHARED)
set(FLANG_RT_INCLUDE_TESTS_default OFF)
@@ -268,7 +267,7 @@ find_package(Threads)
# FIXME: The NVPTX target will erroneously report it has backtrace support. This
# is caused by using "-c -flto" in the required flags to suppress CUDA
# tools from being required for the CMake flag checks to succeed.
if (NOT "${LLVM_RUNTIMES_TARGET}" MATCHES "^nvptx")
if (NOT "${LLVM_DEFAULT_TARGET_TRIPLE}" MATCHES "^nvptx")
find_package(Backtrace)
endif()
set(HAVE_BACKTRACE ${Backtrace_FOUND})

View File

@@ -112,11 +112,10 @@ The `CMAKE_Fortran_COMPILER_WORKS` parameter must be set because otherwise CMake
will test whether the Fortran compiler can compile and link programs which will
obviously fail without a runtime library available yet.
Building Flang-RT for cross-compilation triple, the target triple can
be selected using `LLVM_DEFAULT_TARGET_TRIPLE` AND `LLVM_RUNTIMES_TARGET`.
Of course, Flang-RT can be built multiple times with different build
configurations, but have to be located manually when using with the Flang
driver using the `-L` option.
Building Flang-RT for cross-compilation triple, the target triple can be
selected using `LLVM_DEFAULT_TARGET_TRIPLE`. Of course, Flang-RT can be built
multiple times with different build configurations, but have to be located
manually when using with the Flang driver using the `-L` option.
After configuration, build, test, and install the runtime via

View File

@@ -266,11 +266,11 @@ function (add_flangrt_library name)
endif ()
# Add target specific options if necessary.
if ("${LLVM_RUNTIMES_TARGET}" MATCHES "^amdgcn")
if ("${LLVM_DEFAULT_TARGET_TRIPLE}" MATCHES "^amdgcn")
target_compile_options(${tgtname} PRIVATE
$<$<COMPILE_LANGUAGE:CXX>:-nogpulib -flto -fvisibility=hidden>
)
elseif ("${LLVM_RUNTIMES_TARGET}" MATCHES "^nvptx")
elseif ("${LLVM_DEFAULT_TARGET_TRIPLE}" MATCHES "^nvptx")
target_compile_options(${tgtname} PRIVATE
$<$<COMPILE_LANGUAGE:CXX>:-nogpulib -flto -fvisibility=hidden -Wno-unknown-cuda-version --cuda-feature=+ptx63>
)

View File

@@ -188,7 +188,7 @@ if (TARGET FortranFloat128MathILib)
endif ()
endif ()
if ("${LLVM_RUNTIMES_TARGET}" MATCHES "^amdgcn|^nvptx")
if ("${LLVM_DEFAULT_TARGET_TRIPLE}" MATCHES "^amdgcn|^nvptx")
set(sources ${gpu_sources})
elseif(FLANG_RT_EXPERIMENTAL_OFFLOAD_SUPPORT STREQUAL "CUDA")
set(sources ${supported_sources})

View File

@@ -98,21 +98,22 @@ string(SUBSTRING ${libc_compiler_target_info} 8 -1 libc_compiler_triple)
# One should not set LLVM_RUNTIMES_TARGET and LIBC_TARGET_TRIPLE
if(LLVM_RUNTIMES_TARGET AND LIBC_TARGET_TRIPLE)
message(FATAL_ERROR
"libc build: Specify only LLVM_RUNTIMES_TARGET if you are doing a "
"libc build: Specify only LLVM_DEFAULT_TARGET_TRIPLE if you are doing a "
"runtimes/bootstrap build. If you are doing a standalone build, "
"specify only LIBC_TARGET_TRIPLE.")
endif()
set(explicit_target_triple)
if(LLVM_RUNTIMES_TARGET)
set(explicit_target_triple ${LLVM_RUNTIMES_TARGET})
# LLVM_RUNTIMES_TARGET may contain multilib flags, use the clean triple.
set(explicit_target_triple ${LLVM_DEFAULT_TARGET_TRIPLE})
elseif(LIBC_TARGET_TRIPLE)
set(explicit_target_triple ${LIBC_TARGET_TRIPLE})
endif()
# The libc's target architecture and OS are set to match the compiler's default
# target triple above. However, one can explicitly set LIBC_TARGET_TRIPLE or
# LLVM_RUNTIMES_TARGET (for runtimes/bootstrap build). If one of them is set,
# LLVM_DEFAULT_TARGET_TRIPLE (for runtimes/bootstrap build). If one of them is set,
# then we will use that target triple to deduce libc's target OS and
# architecture.
if(explicit_target_triple)
@@ -124,7 +125,7 @@ if(explicit_target_triple)
set(LIBC_TARGET_ARCHITECTURE ${libc_arch})
set(LIBC_TARGET_OS ${libc_sys})
# If the compiler target triple is not the same as the triple specified by
# LIBC_TARGET_TRIPLE or LLVM_RUNTIMES_TARGET, we will add a --target option
# LIBC_TARGET_TRIPLE or LLVM_DEFAULT_TARGET_TRIPLE, we will add a --target option
# if the compiler is clang. If the compiler is GCC we just error out as there
# is no equivalent of an option like --target.
if(NOT libc_compiler_triple STREQUAL explicit_target_triple)
@@ -216,7 +217,7 @@ else()
endif()
# If the compiler target triple is not the same as the triple specified by
# LIBC_TARGET_TRIPLE or LLVM_RUNTIMES_TARGET, we will add a --target option
# LIBC_TARGET_TRIPLE or LLVM_DEFAULT_TARGET_TRIPLE, we will add a --target option
# if the compiler is clang. If the compiler is GCC we just error out as there
# is no equivalent of an option like --target.
if(explicit_target_triple AND

View File

@@ -1159,7 +1159,7 @@ if (UNIX AND
endif()
# lld doesn't print colored diagnostics when invoked from Ninja
if (UNIX AND CMAKE_GENERATOR MATCHES "Ninja" AND NOT "${LLVM_RUNTIMES_TARGET}" MATCHES "^nvptx64")
if (UNIX AND CMAKE_GENERATOR MATCHES "Ninja" AND NOT "${LLVM_DEFAULT_TARGET_TRIPLE}" MATCHES "^nvptx64")
include(CheckLinkerFlag)
check_linker_flag(CXX "-Wl,--color-diagnostics" LINKER_SUPPORTS_COLOR_DIAGNOSTICS)
append_if(LINKER_SUPPORTS_COLOR_DIAGNOSTICS "-Wl,--color-diagnostics"

View File

@@ -191,7 +191,7 @@ if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
endif()
# The NVPTX target needs to override linking to pass compiler flag checks.
if("${LLVM_RUNTIMES_TARGET}" MATCHES "^nvptx")
if("${LLVM_DEFAULT_TARGET_TRIPLE}" MATCHES "^nvptx")
set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -flto -c")
endif()