Skip to content

Commit 2cac95b

Browse files
authored
[AIX][PowerPC] Teach the Threading Library About the Number of Physical Cores on AIX (#67683)
The threading library does not recognize AIX and always returns `-1` for number of physical cores on AIX. This PR teaches the library to recognize AIX and obtain the correct value for the number of physical cores.
1 parent ab9cd27 commit 2cac95b

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-2
lines changed

llvm/lib/Support/CMakeLists.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,15 @@ if(LLVM_INTEGRATED_CRT_ALLOC)
118118
endif()
119119
endif()
120120

121+
# FIXME: We are currently guarding AIX headers with _XOPEN_SOURCE=700.
122+
# See llvm/CMakeLists.txt. However, we need _SC_NPROCESSORS_ONLN in
123+
# unistd.h and it is guarded by _ALL_SOURCE, so we remove the _XOPEN_SOURCE
124+
# guard here. We should remove the guards all together once AIX cleans up
125+
# the system headers.
126+
if (UNIX AND ${CMAKE_SYSTEM_NAME} MATCHES "AIX")
127+
remove_definitions("-D_XOPEN_SOURCE=700")
128+
endif()
129+
121130
add_subdirectory(BLAKE3)
122131

123132
add_llvm_component_library(LLVMSupport

llvm/lib/Support/Unix/Threading.inc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,7 @@ static int computeHostNumPhysicalCores() {
371371
}
372372
return CPU_COUNT(&Enabled);
373373
}
374-
#elif defined(__linux__) && defined(__s390x__)
374+
#elif (defined(__linux__) && defined(__s390x__)) || defined(_AIX)
375375
static int computeHostNumPhysicalCores() {
376376
return sysconf(_SC_NPROCESSORS_ONLN);
377377
}

llvm/unittests/Support/Threading.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ static bool isThreadingSupportedArchAndOS() {
2929
return (Host.isOSWindows() && llvm_is_multithreaded()) || Host.isOSDarwin() ||
3030
(Host.isX86() && Host.isOSLinux()) ||
3131
(Host.isOSLinux() && !Host.isAndroid()) ||
32-
(Host.isSystemZ() && Host.isOSzOS());
32+
(Host.isSystemZ() && Host.isOSzOS()) || Host.isOSAIX();
3333
#else
3434
return false;
3535
#endif

0 commit comments

Comments
 (0)