[Openmp-commits] [openmp] 720b8ea - [openmp] Add support for Arm64X to libomp (#176157)
via Openmp-commits
openmp-commits at lists.llvm.org
Tue Mar 31 08:39:09 PDT 2026
Author: David Truby
Date: 2026-03-31T16:39:02+01:00
New Revision: 720b8ea893da2168121622bbfb536a78b35ffa32
URL: https://github.com/llvm/llvm-project/commit/720b8ea893da2168121622bbfb536a78b35ffa32
DIFF: https://github.com/llvm/llvm-project/commit/720b8ea893da2168121622bbfb536a78b35ffa32.diff
LOG: [openmp] Add support for Arm64X to libomp (#176157)
This patch allows building libomp.dll and libomp.lib as Arm64X binaries
containing both arm64 and arm64ec code and useable from applications
compiled for both architectures.
Added:
openmp/runtime/cmake/arm64x.cmake
Modified:
llvm/CMakeLists.txt
llvm/runtimes/CMakeLists.txt
openmp/runtime/CMakeLists.txt
Removed:
################################################################################
diff --git a/llvm/CMakeLists.txt b/llvm/CMakeLists.txt
index 6dbe47600cb2f..359d1591925b1 100644
--- a/llvm/CMakeLists.txt
+++ b/llvm/CMakeLists.txt
@@ -223,6 +223,22 @@ if(LIBC_GPU_BUILD)
list(APPEND RUNTIMES_amdgcn-amd-amdhsa_LLVM_ENABLE_RUNTIMES "libc")
endif()
+# Set up Arm64X build of the OpenMP runtime
+option(LIBOMP_ENABLE_ARM64X "Build the OpenMP library as Arm64X for compatibility with both Arm64 and Arm64EC" OFF)
+if(LIBOMP_ENABLE_ARM64X)
+ if(NOT CMAKE_HOST_WIN32 AND NOT CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL "ARM64")
+ message(FATAL_ERROR "Arm64X builds are only supported on Windows hosts.")
+ endif()
+ if(NOT LLVM_RUNTIME_TARGETS)
+ set(LLVM_RUNTIME_TARGETS "default")
+ endif()
+
+ if(NOT "arm64ec-pc-windows-msvc" IN_LIST LLVM_RUNTIME_TARGETS)
+ list(APPEND LLVM_RUNTIME_TARGETS "arm64ec-pc-windows-msvc")
+ endif()
+ set(RUNTIMES_arm64ec-pc-windows-msvc_LIBOMP_ENABLE_ARM64X ON)
+endif()
+
foreach(_name ${LLVM_RUNTIME_TARGETS})
if("libc" IN_LIST RUNTIMES_${_name}_LLVM_ENABLE_RUNTIMES)
if("${_name}" STREQUAL "amdgcn-amd-amdhsa" OR "${_name}" STREQUAL "nvptx64-nvidia-cuda" OR "${_name}" STREQUAL "spirv64-intel-unknown")
diff --git a/llvm/runtimes/CMakeLists.txt b/llvm/runtimes/CMakeLists.txt
index f22b551b89aca..c3e8df91d1be5 100644
--- a/llvm/runtimes/CMakeLists.txt
+++ b/llvm/runtimes/CMakeLists.txt
@@ -716,3 +716,9 @@ if(build_runtimes)
set_property(GLOBAL APPEND PROPERTY LLVM_ALL_ADDITIONAL_TEST_TARGETS runtimes ${extra_deps})
endif()
endif()
+
+if(LIBOMP_ENABLE_ARM64X)
+ # TODO: This only needs to depend on openmp-arm64ec-pc-windows-msvc, but the
+ # openmp targets set up for cross build runtimes don't currently work correctly.
+ add_dependencies(runtimes-configure runtimes-arm64ec-pc-windows-msvc-build)
+endif()
diff --git a/openmp/runtime/CMakeLists.txt b/openmp/runtime/CMakeLists.txt
index 680e845ffdc95..3ccfa8463810f 100644
--- a/openmp/runtime/CMakeLists.txt
+++ b/openmp/runtime/CMakeLists.txt
@@ -81,6 +81,11 @@ if(LIBOMP_ARCH STREQUAL "aarch64")
endif()
endif()
+# Include support file for arm64x builds
+if(LIBOMP_ENABLE_ARM64X)
+ include(arm64x)
+endif()
+
libomp_check_variable(LIBOMP_ARCH 32e x86_64 32 i386 arm ppc ppc64 ppc64le aarch64 aarch64_32 aarch64_a64fx arm64ec mic mips mips64 riscv64 loongarch64 ve s390x sparc sparcv9 wasm32)
set(LIBOMP_LIB_TYPE normal CACHE STRING
@@ -432,3 +437,8 @@ set(LIBOMP_OMP_TOOLS_INCLUDE_DIR ${LIBOMP_OMP_TOOLS_INCLUDE_DIR} PARENT_SCOPE)
# make these variables available for tools/libompd:
set(LIBOMP_SRC_DIR ${LIBOMP_SRC_DIR} PARENT_SCOPE)
set(LIBOMP_OMPD_SUPPORT ${LIBOMP_OMPD_SUPPORT} PARENT_SCOPE)
+
+# Set up the targets we want to build arm64x libs for
+if(LIBOMP_ENABLE_ARM64X)
+ handle_arm64x(omp ompimp)
+endif()
diff --git a/openmp/runtime/cmake/arm64x.cmake b/openmp/runtime/cmake/arm64x.cmake
new file mode 100644
index 0000000000000..b52ebb7f70bd4
--- /dev/null
+++ b/openmp/runtime/cmake/arm64x.cmake
@@ -0,0 +1,98 @@
+# check if we have the right linker flags to enable Arm64X
+include(CheckLinkerFlag)
+check_linker_flag(CXX "LINKER:/linkreprofullpathrsp:test_rsp" LIBOMP_HAVE_LINKREPROFULLPATHRSP_FLAG)
+if(NOT LIBOMP_HAVE_LINKREPROFULLPATHRSP_FLAG)
+ message(FATAL_ERROR "Arm64X builds are enabled but the linker does not support the required flag. "
+ "Either update Visual Studio if using link.exe or add lld to LLVM_ENABLE_PROJECTS to use a newer lld.")
+endif()
+
+# directory where the link.rsp file generated during arm64 build will be stored
+set(arm64ReproDir "${LLVM_BINARY_DIR}/runtimes/repros-arm64ec")
+
+# Don't install the runtime if we are doing an arm64ec build for arm64x.
+# The hybrid arm64x runtime will get installed by the host (default) runtime build
+if (LIBOMP_ARCH STREQUAL "arm64ec")
+ set(CMAKE_SKIP_INSTALL_RULES On)
+endif()
+
+# This function reads in the content of the rsp file outputted from the arm64ec build for a target,
+# then passes the arm64ec libs and objs to the linker using /machine:arm64x to combine them with the
+# arm64 counterparts and create an arm64x binary.
+function(set_arm64ec_dll_dependencies target)
+ set(REPRO_FILE "${arm64ReproDir}/${target}.rsp")
+ file(STRINGS "${REPRO_FILE}" ARM64_OBJS REGEX obj\"$)
+ file(STRINGS "${REPRO_FILE}" ARM64_LIBS REGEX lib\"$)
+ string(REPLACE "\"" ";" ARM64_OBJS "${ARM64_OBJS}")
+ string(REPLACE "\"" ";" ARM64_LIBS "${ARM64_LIBS}")
+
+ get_target_property(libs "${target}" LINK_FLAGS)
+ set(non_def "")
+
+ # Separate out the /def flag from the other link flags, so we can replace it with /defArm64Native.
+ foreach(lib IN LISTS libs)
+ if(lib MATCHES ".*\.def")
+ string(REPLACE "/DEF:" "" "def" "${lib}")
+ else()
+ list(APPEND non_def "${lib}")
+ endif()
+ endforeach()
+ # Remove the /def link flag
+ set_target_properties("${target}" PROPERTIES LINK_FLAGS "${non_def}")
+
+ target_sources("${target}" PRIVATE ${ARM64_OBJS})
+ target_link_options("${target}" PRIVATE /machine:arm64x "/def:${arm64ReproDir}/${target}.def" "/defArm64Native:${def}")
+endfunction()
+
+# Replace the /def flag with /defArm64Native and add the arm64ec /def file.
+function(set_arm64ec_lib_dependencies target)
+ get_target_property(opts ${target} STATIC_LIBRARY_OPTIONS)
+ string(REPLACE "/DEF:" "/defArm64Native:" opts "${opts}")
+ set_target_properties(${target} PROPERTIES STATIC_LIBRARY_OPTIONS "/machine:arm64x;${opts};/def:${arm64ReproDir}/${target}.def")
+endfunction()
+
+# Copy the def file for arm64ec to the repros directory so we can use it in the arm64x builds and add the linkreprofullpathrsp flag.
+function(handle_arm64ec_target target)
+ get_target_property(type "${target}" TYPE)
+ if(type STREQUAL "SHARED_LIBRARY")
+ get_target_property(libs "${target}" LINK_FLAGS)
+ elseif(type STREQUAL "STATIC_LIBRARY")
+ get_target_property(libs "${target}" STATIC_LIBRARY_OPTIONS)
+ endif()
+ list(FILTER libs INCLUDE REGEX ".*\.def")
+ string(REPLACE "/DEF:" "" def "${libs}")
+
+ add_custom_target("${target}.def"
+ BYPRODUCTS "${arm64ReproDir}/${target}.def"
+ COMMAND ${CMAKE_COMMAND} -E copy
+ "${def}"
+ "${arm64ReproDir}/${target}.def"
+ DEPENDS "${def}")
+ add_dependencies(${target} "${target}.def")
+ # tell the linker to produce this special rsp file that has absolute paths to its inputs
+ if(type STREQUAL "SHARED_LIBRARY")
+ target_link_options(${target} PRIVATE "/LINKREPROFULLPATHRSP:${arm64ReproDir}/${target}.rsp")
+ endif()
+endfunction()
+
+# Handle the targets we have requested arm64x builds for.
+function(handle_arm64x)
+ set(targets "${ARGV}")
+ # During the arm64ec build, create rsp files that containes the absolute path to the inputs passed to the linker (objs, libs).
+ if(LIBOMP_ARCH STREQUAL "arm64ec")
+ file(MAKE_DIRECTORY ${arm64ReproDir})
+ foreach (target IN LISTS targets)
+ handle_arm64ec_target("${target}")
+ endforeach()
+
+ # During the ARM64 build, modify the link step appropriately to produce an arm64x binary
+ elseif(LIBOMP_ARCH STREQUAL "aarch64")
+ foreach (target IN LISTS targets)
+ get_target_property(type ${target} TYPE)
+ if(type STREQUAL "SHARED_LIBRARY")
+ set_arm64ec_dll_dependencies("${target}")
+ elseif(type STREQUAL "STATIC_LIBRARY")
+ set_arm64ec_lib_dependencies("${target}")
+ endif()
+ endforeach()
+ endif()
+endfunction()
More information about the Openmp-commits
mailing list