diff --git a/0001-add-loongarch64-support.patch b/0001-add-loongarch64-support.patch new file mode 100644 index 0000000000000000000000000000000000000000..ec1ccae5826a8a2b0b16d5854ee24135ff4d803a --- /dev/null +++ b/0001-add-loongarch64-support.patch @@ -0,0 +1,243 @@ +From 4bf3c70add7aeba3f6eca861dd8bf21194c1901e Mon Sep 17 00:00:00 2001 +From: zhangxianting +Date: Wed, 3 Jul 2024 16:45:01 +0800 +Subject: [PATCH] add loongarch64 support + +--- + runtime/CMakeLists.txt | 11 ++++++++--- + runtime/cmake/LibompGetArchitecture.cmake | 2 ++ + runtime/cmake/LibompMicroTests.cmake | 3 +++ + runtime/cmake/LibompUtils.cmake | 2 ++ + runtime/cmake/config-ix.cmake | 1 + + runtime/src/kmp_csupport.cpp | 2 +- + runtime/src/kmp_os.h | 2 +- + runtime/src/kmp_platform.h | 7 ++++++- + runtime/src/kmp_runtime.cpp | 2 +- + runtime/src/thirdparty/ittnotify/ittnotify_config.h | 9 ++++++++- + runtime/src/z_Linux_util.cpp | 2 +- + 11 files changed, 34 insertions(+), 9 deletions(-) + +diff --git a/runtime/CMakeLists.txt b/runtime/CMakeLists.txt +index 8828ff8..2be9215 100644 +--- a/runtime/CMakeLists.txt ++++ b/runtime/CMakeLists.txt +@@ -30,7 +30,7 @@ if(${OPENMP_STANDALONE_BUILD}) + # If adding a new architecture, take a look at cmake/LibompGetArchitecture.cmake + libomp_get_architecture(LIBOMP_DETECTED_ARCH) + set(LIBOMP_ARCH ${LIBOMP_DETECTED_ARCH} CACHE STRING +- "The architecture to build for (x86_64/i386/arm/ppc64/ppc64le/aarch64/mic/mips/mips64/riscv64).") ++ "The architecture to build for (x86_64/i386/arm/ppc64/ppc64le/aarch64/mic/mips/mips64/riscv64/loongarch64).") + # Should assertions be enabled? They are on by default. + set(LIBOMP_ENABLE_ASSERTIONS TRUE CACHE BOOL + "enable assertions?") +@@ -60,6 +60,8 @@ else() # Part of LLVM build + set(LIBOMP_ARCH arm) + elseif(LIBOMP_NATIVE_ARCH MATCHES "riscv64") + set(LIBOMP_ARCH riscv64) ++ elseif(LIBOMP_NATIVE_ARCH MATCHES "loongarch64") ++ set(LIBOMP_ARCH loongarch64) + else() + # last ditch effort + libomp_get_architecture(LIBOMP_ARCH) +@@ -80,7 +82,7 @@ if(LIBOMP_ARCH STREQUAL "aarch64") + endif() + endif() + +-libomp_check_variable(LIBOMP_ARCH 32e x86_64 32 i386 arm ppc64 ppc64le aarch64 aarch64_a64fx mic mips mips64 riscv64) ++libomp_check_variable(LIBOMP_ARCH 32e x86_64 32 i386 arm ppc64 ppc64le aarch64 aarch64_a64fx mic mips mips64 riscv64 loongarch64) + + set(LIBOMP_LIB_TYPE normal CACHE STRING + "Performance,Profiling,Stubs library (normal/profile/stubs)") +@@ -158,6 +160,7 @@ set(MIC FALSE) + set(MIPS64 FALSE) + set(MIPS FALSE) + set(RISCV64 FALSE) ++set(LOONGARCH64 FALSE) + if("${LIBOMP_ARCH}" STREQUAL "i386" OR "${LIBOMP_ARCH}" STREQUAL "32") # IA-32 architecture + set(IA32 TRUE) + elseif("${LIBOMP_ARCH}" STREQUAL "x86_64" OR "${LIBOMP_ARCH}" STREQUAL "32e") # Intel(R) 64 architecture +@@ -180,8 +183,10 @@ elseif("${LIBOMP_ARCH}" STREQUAL "mips") # MIPS architecture + set(MIPS TRUE) + elseif("${LIBOMP_ARCH}" STREQUAL "mips64") # MIPS64 architecture + set(MIPS64 TRUE) +- elseif("${LIBOMP_ARCH}" STREQUAL "riscv64") # RISCV64 architecture ++elseif("${LIBOMP_ARCH}" STREQUAL "riscv64") # RISCV64 architecture + set(RISCV64 TRUE) ++elseif("${LIBOMP_ARCH}" STREQUAL "loongarch64") # LOONGARCH64 architecture ++ set(LOONGARCH64 TRUE) + endif() + + # Set some flags based on build_type +diff --git a/runtime/cmake/LibompGetArchitecture.cmake b/runtime/cmake/LibompGetArchitecture.cmake +index dd60a2d..00f0b3d 100644 +--- a/runtime/cmake/LibompGetArchitecture.cmake ++++ b/runtime/cmake/LibompGetArchitecture.cmake +@@ -47,6 +47,8 @@ function(libomp_get_architecture return_arch) + #error ARCHITECTURE=mips + #elif defined(__riscv) && __riscv_xlen == 64 + #error ARCHITECTURE=riscv64 ++ #elif defined(__loongarch64__) || defined(__loongarch64) ++ #error ARCHITECTURE=loongarch64 + #else + #error ARCHITECTURE=UnknownArchitecture + #endif +diff --git a/runtime/cmake/LibompMicroTests.cmake b/runtime/cmake/LibompMicroTests.cmake +index 1ca3412..88deb46 100644 +--- a/runtime/cmake/LibompMicroTests.cmake ++++ b/runtime/cmake/LibompMicroTests.cmake +@@ -214,6 +214,9 @@ else() + elseif(${RISCV64}) + libomp_append(libomp_expected_library_deps libc.so.6) + libomp_append(libomp_expected_library_deps ld.so.1) ++ elseif(${LOONGARCH64}) ++ libomp_append(libomp_expected_library_deps libc.so.6) ++ libomp_append(libomp_expected_library_deps ld.so.1) + endif() + libomp_append(libomp_expected_library_deps libpthread.so.0 IF_FALSE STUBS_LIBRARY) + libomp_append(libomp_expected_library_deps libhwloc.so.5 LIBOMP_USE_HWLOC) +diff --git a/runtime/cmake/LibompUtils.cmake b/runtime/cmake/LibompUtils.cmake +index b1de242..b5ffc97 100644 +--- a/runtime/cmake/LibompUtils.cmake ++++ b/runtime/cmake/LibompUtils.cmake +@@ -109,6 +109,8 @@ function(libomp_get_legal_arch return_arch_string) + set(${return_arch_string} "MIPS64" PARENT_SCOPE) + elseif(${RISCV64}) + set(${return_arch_string} "RISCV64" PARENT_SCOPE) ++ elseif(${LOONGARCH64}) ++ set(${return_arch_string} "LOONGARCH64" PARENT_SCOPE) + else() + set(${return_arch_string} "${LIBOMP_ARCH}" PARENT_SCOPE) + libomp_warning_say("libomp_get_legal_arch(): Warning: Unknown architecture: Using ${LIBOMP_ARCH}") +diff --git a/runtime/cmake/config-ix.cmake b/runtime/cmake/config-ix.cmake +index ed62aef..51af23b 100644 +--- a/runtime/cmake/config-ix.cmake ++++ b/runtime/cmake/config-ix.cmake +@@ -299,6 +299,7 @@ else() + (LIBOMP_ARCH STREQUAL aarch64_a64fx) OR + (LIBOMP_ARCH STREQUAL ppc64le) OR + (LIBOMP_ARCH STREQUAL ppc64) OR ++ (LIBOMP_ARCH STREQUAL loongarch64) OR + (LIBOMP_ARCH STREQUAL riscv64)) + AND # OS supported? + ((WIN32 AND LIBOMP_HAVE_PSAPI) OR APPLE OR (NOT WIN32 AND LIBOMP_HAVE_WEAK_ATTRIBUTE))) +diff --git a/runtime/src/kmp_csupport.cpp b/runtime/src/kmp_csupport.cpp +index 4b18876..0b6bd08 100644 +--- a/runtime/src/kmp_csupport.cpp ++++ b/runtime/src/kmp_csupport.cpp +@@ -666,7 +666,7 @@ void __kmpc_flush(ident_t *loc) { + } + #endif // KMP_MIC + #elif (KMP_ARCH_ARM || KMP_ARCH_AARCH64 || KMP_ARCH_MIPS || KMP_ARCH_MIPS64 || \ +- KMP_ARCH_RISCV64) ++ KMP_ARCH_RISCV64 || KMP_ARCH_LOONGARCH64) + // Nothing to see here move along + #elif KMP_ARCH_PPC64 + // Nothing needed here (we have a real MB above). +diff --git a/runtime/src/kmp_os.h b/runtime/src/kmp_os.h +index 5ceae98..073db3e 100644 +--- a/runtime/src/kmp_os.h ++++ b/runtime/src/kmp_os.h +@@ -167,7 +167,7 @@ typedef unsigned long long kmp_uint64; + #if KMP_ARCH_X86 || KMP_ARCH_ARM || KMP_ARCH_MIPS + #define KMP_SIZE_T_SPEC KMP_UINT32_SPEC + #elif KMP_ARCH_X86_64 || KMP_ARCH_PPC64 || KMP_ARCH_AARCH64 || \ +- KMP_ARCH_MIPS64 || KMP_ARCH_RISCV64 ++ KMP_ARCH_MIPS64 || KMP_ARCH_RISCV64 || KMP_ARCH_LOONGARCH64 + #define KMP_SIZE_T_SPEC KMP_UINT64_SPEC + #else + #error "Can't determine size_t printf format specifier." +diff --git a/runtime/src/kmp_platform.h b/runtime/src/kmp_platform.h +index 4296ca3..20e986b 100644 +--- a/runtime/src/kmp_platform.h ++++ b/runtime/src/kmp_platform.h +@@ -93,6 +93,7 @@ + #define KMP_ARCH_MIPS 0 + #define KMP_ARCH_MIPS64 0 + #define KMP_ARCH_RISCV64 0 ++#define KMP_ARCH_LOONGARCH64 0 + + #if KMP_OS_WINDOWS + #if defined(_M_AMD64) || defined(__x86_64) +@@ -133,6 +134,9 @@ + #elif defined __riscv && __riscv_xlen == 64 + #undef KMP_ARCH_RISCV64 + #define KMP_ARCH_RISCV64 1 ++#elif defined __loongarch64 ++#undef KMP_ARCH_LOONGARCH64 ++#define KMP_ARCH_LOONGARCH64 1 + #endif + #endif + +@@ -197,7 +201,8 @@ + // TODO: Fixme - This is clever, but really fugly + #if (1 != \ + KMP_ARCH_X86 + KMP_ARCH_X86_64 + KMP_ARCH_ARM + KMP_ARCH_PPC64 + \ +- KMP_ARCH_AARCH64 + KMP_ARCH_MIPS + KMP_ARCH_MIPS64 + KMP_ARCH_RISCV64) ++ KMP_ARCH_AARCH64 + KMP_ARCH_MIPS + KMP_ARCH_MIPS64 + \ ++ KMP_ARCH_RISCV64 + KMP_ARCH_LOONGARCH64) + #error Unknown or unsupported architecture + #endif + +diff --git a/runtime/src/kmp_runtime.cpp b/runtime/src/kmp_runtime.cpp +index b981f87..cf23406 100644 +--- a/runtime/src/kmp_runtime.cpp ++++ b/runtime/src/kmp_runtime.cpp +@@ -8368,7 +8368,7 @@ __kmp_determine_reduction_method( + int atomic_available = FAST_REDUCTION_ATOMIC_METHOD_GENERATED; + + #if KMP_ARCH_X86_64 || KMP_ARCH_PPC64 || KMP_ARCH_AARCH64 || \ +- KMP_ARCH_MIPS64 || KMP_ARCH_RISCV64 ++ KMP_ARCH_MIPS64 || KMP_ARCH_RISCV64 || KMP_ARCH_LOONGARCH64 + + #if KMP_OS_LINUX || KMP_OS_DRAGONFLY || KMP_OS_FREEBSD || KMP_OS_NETBSD || \ + KMP_OS_OPENBSD || KMP_OS_WINDOWS || KMP_OS_DARWIN || KMP_OS_HURD +diff --git a/runtime/src/thirdparty/ittnotify/ittnotify_config.h b/runtime/src/thirdparty/ittnotify/ittnotify_config.h +index f231e70..2131611 100644 +--- a/runtime/src/thirdparty/ittnotify/ittnotify_config.h ++++ b/runtime/src/thirdparty/ittnotify/ittnotify_config.h +@@ -165,6 +165,10 @@ + # define ITT_ARCH_RISCV64 7 + #endif /* ITT_ARCH_RISCV64 */ + ++#ifndef ITT_ARCH_LOONGARCH64 ++# define ITT_ARCH_LOONGARCH64 8 ++#endif /* ITT_ARCH_LOONGARCH64 */ ++ + #ifndef ITT_ARCH + # if defined _M_IX86 || defined __i386__ + # define ITT_ARCH ITT_ARCH_IA32 +@@ -184,6 +188,8 @@ + # define ITT_ARCH ITT_ARCH_MIPS64 + # elif defined __riscv && __riscv_xlen == 64 + # define ITT_ARCH ITT_ARCH_RISCV64 ++# elif defined __loongarch64__ || defined __loongarch64 ++# define ITT_ARCH ITT_ARCH_LOONGARCH64 + # endif + #endif + +@@ -338,7 +344,8 @@ ITT_INLINE long __TBB_machine_fetchadd4(volatile void* ptr, long addend) + } + #elif ITT_ARCH == ITT_ARCH_ARM || ITT_ARCH == ITT_ARCH_PPC64 || \ + ITT_ARCH == ITT_ARCH_AARCH64 || ITT_ARCH == ITT_ARCH_MIPS || \ +- ITT_ARCH == ITT_ARCH_MIPS64 || ITT_ARCH == ITT_ARCH_RISCV64 ++ ITT_ARCH == ITT_ARCH_MIPS64 || ITT_ARCH == ITT_ARCH_RISCV64 || \ ++ ITT_ARCH == ITT_ARCH_LOONGARCH64 + #define __TBB_machine_fetchadd4(addr, val) __sync_fetch_and_add(addr, val) + #endif /* ITT_ARCH==ITT_ARCH_IA64 */ + #ifndef ITT_SIMPLE_INIT +diff --git a/runtime/src/z_Linux_util.cpp b/runtime/src/z_Linux_util.cpp +index 95feafb..c0822d1 100644 +--- a/runtime/src/z_Linux_util.cpp ++++ b/runtime/src/z_Linux_util.cpp +@@ -2438,7 +2438,7 @@ finish: // Clean up and exit. + + #if !(KMP_ARCH_X86 || KMP_ARCH_X86_64 || KMP_MIC || \ + ((KMP_OS_LINUX || KMP_OS_DARWIN) && KMP_ARCH_AARCH64) || \ +- KMP_ARCH_PPC64 || KMP_ARCH_RISCV64) ++ KMP_ARCH_PPC64 || KMP_ARCH_RISCV64 || KMP_ARCH_LOONGARCH64) + + // we really only need the case with 1 argument, because CLANG always build + // a struct of pointers to shared variables referenced in the outlined function +-- +2.39.3 + diff --git a/libomp.spec b/libomp.spec index 2f4bd8de722891166290a682c9dd25f4c1d9930b..9042a11cf93d3a6408aa542e44a9ab3e8eecba6d 100644 --- a/libomp.spec +++ b/libomp.spec @@ -12,12 +12,13 @@ Name: libomp Version: %{libomp_version} -Release: 1 +Release: 2 Summary: OpenMP runtime for clang License: Apache-2.0 WITH LLVM-exception OR NCSA URL: http://openmp.llvm.org Source0: https://github.com/llvm/llvm-project/releases/download/llvmorg-12.0.1/%{libomp_srcdir}.tar.xz +Patch0: 0001-add-loongarch64-support.patch BuildRequires: clang # For clang-offload-packager @@ -47,7 +48,7 @@ Requires: clang-resource-filesystem%{?isa} = %{version} OpenMP header files. %prep -%autosetup -n %{libomp_srcdir} -p2 +%autosetup -n %{libomp_srcdir} -p1 %build mkdir build && cd build @@ -92,6 +93,9 @@ cp LICENSE.txt %{buildroot}%{_datadir}/licenses/libomp/ %{_libdir}/*.a %changelog +* Wed Jul 3 2024 zhangxianting - 16.0.2-2 +- Add loongarch64 support + * Tue May 9 2023 will_niutao - 16.0.2-1 - Init for openEuler