[Openmp-commits] [openmp] [OpenMP][OMPT] Enable OMPT on 32-bit PowerPC (PR #227540)
Matt Turner via Openmp-commits
openmp-commits at lists.llvm.org
Tue Sep 29 19:50:21 PDT 2026
https://github.com/mattst88 created https://github.com/llvm/llvm-project/pull/227540
Depends on https://github.com/llvm/llvm-project/pull/227539; only the last commit is new.
The tests' return-address offsets are the same as on LoongArch64: a nop, optionally followed by one or two branches.
Tested with check-openmp under qemu-ppc with OMPT enabled.
Assisted-by: Claude Code
>From 339f71565cec3d7f40f0fdd9354e73be85a109be Mon Sep 17 00:00:00 2001
From: Matt Turner <mattst88 at gmail.com>
Date: Tue, 29 Sep 2026 20:24:41 -0400
Subject: [PATCH 1/2] [OpenMP] Build libomp on 32-bit PowerPC Linux
kmp_affinity.h has no sched_{set,get}affinity syscall numbers for 32-bit
PowerPC and stops at its #error. They are the same as on ppc64 (222 and
223), so share that case.
32-bit PowerPC has no 64-bit atomic instructions, so linking libomp.so
also fails on undefined __atomic_*_8 references. Link libatomic, as for
MIPS, but only if it exists: other 32-bit PowerPC targets such as
OpenBSD (52a02b6d1e0c) may not have it. AIX already links
libcompiler_rt for these.
Assisted-by: Claude Code
---
openmp/runtime/CMakeLists.txt | 10 ++++++++++
openmp/runtime/src/kmp_affinity.h | 2 +-
2 files changed, 11 insertions(+), 1 deletion(-)
diff --git a/openmp/runtime/CMakeLists.txt b/openmp/runtime/CMakeLists.txt
index 0256bfaf4a892c..2a461388585f08 100644
--- a/openmp/runtime/CMakeLists.txt
+++ b/openmp/runtime/CMakeLists.txt
@@ -153,6 +153,16 @@ if("${LIBOMP_ARCH}" STREQUAL "mips" OR "${LIBOMP_ARCH}" STREQUAL "mips64")
set(LIBOMP_LIBFLAGS "${LIBOMP_LIBFLAGS} -latomic")
endif()
+if("${LIBOMP_ARCH}" STREQUAL "ppc" AND NOT "${CMAKE_SYSTEM_NAME}" MATCHES "AIX")
+ # PPC (32-bit) has no 64-bit atomic instructions, so __atomic_load_8, etc.
+ # come from libatomic where the toolchain provides one.
+ include(CheckLibraryExists)
+ check_library_exists(atomic __atomic_load_8 "" LIBOMP_HAVE_LIBATOMIC_8)
+ if(LIBOMP_HAVE_LIBATOMIC_8)
+ set(LIBOMP_LIBFLAGS "${LIBOMP_LIBFLAGS} -latomic")
+ endif()
+endif()
+
# Should the libomp library and generated headers be copied into the original source exports/ directory
# Turning this to FALSE aids parallel builds to not interfere with each other.
# Currently, the testsuite module expects the just built OpenMP library to be located inside the exports/
diff --git a/openmp/runtime/src/kmp_affinity.h b/openmp/runtime/src/kmp_affinity.h
index fa69585f7e2d58..6d814578ca4f23 100644
--- a/openmp/runtime/src/kmp_affinity.h
+++ b/openmp/runtime/src/kmp_affinity.h
@@ -234,7 +234,7 @@ class KMPHwlocAffinity : public KMPAffinity {
#elif __NR_sched_getaffinity != 204
#error Wrong code for getaffinity system call.
#endif /* __NR_sched_getaffinity */
-#elif KMP_ARCH_PPC64
+#elif KMP_ARCH_PPC64 || KMP_ARCH_PPC
#ifndef __NR_sched_setaffinity
#define __NR_sched_setaffinity 222
#elif __NR_sched_setaffinity != 222
>From 4409c5982f0c103a9b8e9427d1545db1cb389af5 Mon Sep 17 00:00:00 2001
From: Matt Turner <mattst88 at gmail.com>
Date: Tue, 29 Sep 2026 20:24:41 -0400
Subject: [PATCH 2/2] [OpenMP][OMPT] Enable OMPT on 32-bit PowerPC
The tests' return-address offsets are the same as on LoongArch64: a nop,
optionally followed by one or two branches.
Assisted-by: Claude Code
---
openmp/runtime/cmake/config-ix.cmake | 1 +
openmp/runtime/test/ompt/callback.h | 10 +++++-----
2 files changed, 6 insertions(+), 5 deletions(-)
diff --git a/openmp/runtime/cmake/config-ix.cmake b/openmp/runtime/cmake/config-ix.cmake
index a21764a2e488ab..41584a888b29b7 100644
--- a/openmp/runtime/cmake/config-ix.cmake
+++ b/openmp/runtime/cmake/config-ix.cmake
@@ -304,6 +304,7 @@ else()
(LIBOMP_ARCH STREQUAL aarch64) OR
(LIBOMP_ARCH STREQUAL aarch64_32) OR
(LIBOMP_ARCH STREQUAL aarch64_a64fx) OR
+ (LIBOMP_ARCH STREQUAL ppc) OR
(LIBOMP_ARCH STREQUAL ppc64le) OR
(LIBOMP_ARCH STREQUAL ppc64) OR
(LIBOMP_ARCH STREQUAL riscv64) OR
diff --git a/openmp/runtime/test/ompt/callback.h b/openmp/runtime/test/ompt/callback.h
index ab6c56291da238..42db52aa4d5b8c 100644
--- a/openmp/runtime/test/ompt/callback.h
+++ b/openmp/runtime/test/ompt/callback.h
@@ -309,11 +309,11 @@ static void print_ids(int level) {
ompt_get_thread_data()->value, ((char *)addr) - 8, \
((char *)addr) - 12)
#endif
-#elif KMP_ARCH_LOONGARCH64
-// On LoongArch64 the NOP instruction is 4 bytes long, can be followed by
-// inserted jump instruction (another 4 bytes long). And an additional jump
-// instruction may appear (adding 4 more bytes) when the NOP is referenced
-// elsewhere (ie. another branch).
+#elif KMP_ARCH_LOONGARCH64 || KMP_ARCH_PPC
+// On LoongArch64 and 32-bit PowerPC the NOP instruction is 4 bytes long, can
+// be followed by inserted jump instruction (another 4 bytes long). And an
+// additional jump instruction may appear (adding 4 more bytes) when the NOP is
+// referenced elsewhere (ie. another branch).
#define print_possible_return_addresses(addr) \
printf("%" PRIu64 ": current_address=%p or %p or %p\n", \
ompt_get_thread_data()->value, ((char *)addr) - 4, \
More information about the Openmp-commits
mailing list