Skip to content

Commit b5b251a

Browse files
authored
[OpenMP] Add support for Solaris/x86_64 (#70593)
Tested on `amd64-pc-solaris2.11`.
1 parent 74f38df commit b5b251a

File tree

8 files changed

+62
-16
lines changed

8 files changed

+62
-16
lines changed

clang/lib/Driver/ToolChains/Solaris.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,11 @@ void solaris::Linker::ConstructJob(Compilation &C, const JobAction &JA,
215215

216216
if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs,
217217
options::OPT_r)) {
218+
// Use the static OpenMP runtime with -static-openmp
219+
bool StaticOpenMP = Args.hasArg(options::OPT_static_openmp) &&
220+
!Args.hasArg(options::OPT_static);
221+
addOpenMPRuntime(CmdArgs, getToolChain(), Args, StaticOpenMP);
222+
218223
if (D.CCCIsCXX()) {
219224
if (getToolChain().ShouldLinkCXXStdlib(Args))
220225
getToolChain().AddCXXStdlibLibArgs(Args, CmdArgs);

clang/test/Driver/fopenmp.c

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616
// RUN: %clang -target x86_64-dragonfly -fopenmp=libomp -c %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-CC1-OPENMP
1717
// RUN: %clang -target x86_64-dragonfly -fopenmp=libgomp -c %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-CC1-NO-OPENMP
1818
// RUN: %clang -target x86_64-dragonfly -fopenmp=libiomp5 -c %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-CC1-OPENMP
19+
// RUN: %clang -target i386-pc-solaris2.11 -fopenmp=libomp -c %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-CC1-OPENMP
20+
// RUN: %clang -target i386-pc-solaris2.11 -fopenmp=libgomp -c %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-CC1-NO-OPENMP
21+
// RUN: %clang -target i386-pc-solaris2.11 -fopenmp=libiomp5 -c %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-CC1-OPENMP
1922
// RUN: %clang -target x86_64-windows-gnu -fopenmp=libomp -c %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-CC1-OPENMP
2023
// RUN: %clang -target x86_64-windows-gnu -fopenmp=libgomp -c %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-CC1-NO-OPENMP
2124
// RUN: %clang -target x86_64-windows-gnu -fopenmp=libiomp5 -c %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-CC1-OPENMP
@@ -106,6 +109,19 @@
106109
// RUN: %clang -nostdlib -target x86_64-dragonfly -fopenmp=libgomp %s -o %t -### 2>&1 | FileCheck %s --check-prefix=CHECK-NO-GOMP
107110
// RUN: %clang -nostdlib -target x86_64-dragonfly -fopenmp=libiomp5 %s -o %t -### 2>&1 | FileCheck %s --check-prefix=CHECK-NO-IOMP5
108111
//
112+
// RUN: %clang -target i386-pc-solaris2.11 -fopenmp=libomp %s -o %t -### 2>&1 | FileCheck %s --check-prefix=CHECK-LD-OMP
113+
// RUN: %clang -target i386-pc-solaris2.11 -fopenmp=libgomp %s -o %t -### 2>&1 | FileCheck %s --check-prefix=CHECK-LD-GOMP --check-prefix=CHECK-LD-GOMP-NO-RT
114+
// RUN: %clang -target i386-pc-solaris2.11 -fopenmp=libiomp5 %s -o %t -### 2>&1 | FileCheck %s --check-prefix=CHECK-LD-IOMP5
115+
//
116+
// RUN: %clang -target i386-pc-solaris2.11 -fopenmp=libomp -static-openmp %s -o %t -### 2>&1 | FileCheck %s --check-prefix=CHECK-LD-STATIC-OMP
117+
// RUN: %clang -target i386-pc-solaris2.11 -fopenmp=libgomp -static-openmp %s -o %t -### 2>&1 | FileCheck %s --check-prefix=CHECK-LD-STATIC-GOMP --check-prefix=CHECK-LD-STATIC-GOMP-NO-RT
118+
// RUN: %clang -target i386-pc-solaris2.11 -fopenmp=libiomp5 -static-openmp %s -o %t -### 2>&1 | FileCheck %s --check-prefix=CHECK-LD-STATIC-IOMP5
119+
// RUN: %clang -target i386-pc-solaris2.11 -fopenmp=libiomp5 -static -static-openmp %s -o %t -### 2>&1 | FileCheck %s --check-prefix=CHECK-LD-STATIC-IOMP5-NO-BDYNAMIC
120+
//
121+
// RUN: %clang -nostdlib -target i386-pc-solaris2.11 -fopenmp=libomp %s -o %t -### 2>&1 | FileCheck %s --check-prefix=CHECK-NO-OMP
122+
// RUN: %clang -nostdlib -target i386-pc-solaris2.11 -fopenmp=libgomp %s -o %t -### 2>&1 | FileCheck %s --check-prefix=CHECK-NO-GOMP
123+
// RUN: %clang -nostdlib -target i386-pc-solaris2.11 -fopenmp=libiomp5 %s -o %t -### 2>&1 | FileCheck %s --check-prefix=CHECK-NO-IOMP5
124+
//
109125
// RUN: %clang -target x86_64-windows-gnu -fopenmp=libomp %s -o %t -### 2>&1 | FileCheck %s --check-prefix=CHECK-LD-OMP
110126
// RUN: %clang -target x86_64-windows-gnu -fopenmp=libgomp %s -o %t -### 2>&1 | FileCheck %s --check-prefix=CHECK-LD-GOMP --check-prefix=CHECK-LD-GOMP-NO-RT
111127
// RUN: %clang -target x86_64-windows-gnu -fopenmp=libiomp5 %s -o %t -### 2>&1 | FileCheck %s --check-prefix=CHECK-LD-IOMP5MD
@@ -152,7 +168,7 @@
152168
// CHECK-LD-STATIC-IOMP5: "-Bstatic" "-liomp5" "-Bdynamic"
153169
//
154170
// CHECK-LD-STATIC-IOMP5-NO-BDYNAMIC: "{{.*}}ld{{(.exe)?}}"
155-
// For x86 Gnu, the driver passes -static, while FreeBSD, NetBSD, OpenBSD and DragonFly pass -Bstatic
171+
// For x86 Gnu, the driver passes -static, while FreeBSD, NetBSD, OpenBSD, DragonFly and Solaris pass -Bstatic
156172
// CHECK-LD-STATIC-IOMP5-NO-BDYNAMIC: "-{{B?}}static" {{.*}} "-liomp5"
157173
// CHECK-LD-STATIC-IOMP5-NO-BDYNAMIC-NOT: "-Bdynamic"
158174
//
@@ -174,6 +190,7 @@
174190
// RUN: %clang -target x86_64-netbsd -fopenmp %s -o %t -### 2>&1 | FileCheck %s --check-prefix=CHECK-LD-ANY
175191
// RUN: %clang -target x86_64-openbsd -fopenmp %s -o %t -### 2>&1 | FileCheck %s --check-prefix=CHECK-LD-ANY
176192
// RUN: %clang -target x86_64-dragonfly -fopenmp %s -o %t -### 2>&1 | FileCheck %s --check-prefix=CHECK-LD-ANY
193+
// RUN: %clang -target i386-pc-solaris2.11 -fopenmp %s -o %t -### 2>&1 | FileCheck %s --check-prefix=CHECK-LD-ANY
177194
// RUN: %clang -target x86_64-windows-gnu -fopenmp %s -o %t -### 2>&1 | FileCheck %s --check-prefix=CHECK-LD-ANYMD
178195
//
179196
// CHECK-LD-ANY: "{{.*}}ld{{(.exe)?}}"

openmp/runtime/cmake/LibompHandleFlags.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ function(libomp_get_libflags libflags)
144144
libomp_append(libflags_local "-Wl,--no-as-needed" LIBOMP_HAVE_AS_NEEDED_FLAG)
145145
libomp_append(libflags_local "-lm")
146146
libomp_append(libflags_local "-Wl,--as-needed" LIBOMP_HAVE_AS_NEEDED_FLAG)
147-
elseif(${CMAKE_SYSTEM_NAME} MATCHES "Linux|NetBSD")
147+
elseif(${CMAKE_SYSTEM_NAME} MATCHES "Linux|NetBSD|Solaris")
148148
libomp_append(libflags_local -lm)
149149
endif()
150150
set(libflags_local ${libflags_local} ${LIBOMP_LIBFLAGS})

openmp/runtime/src/kmp.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1327,12 +1327,16 @@ extern kmp_uint64 __kmp_now_nsec();
13271327
/* TODO: tune for KMP_OS_NETBSD */
13281328
#define KMP_INIT_WAIT 1024U /* initial number of spin-tests */
13291329
#define KMP_NEXT_WAIT 512U /* susequent number of spin-tests */
1330+
#elif KMP_OS_OPENBSD
1331+
/* TODO: tune for KMP_OS_OPENBSD */
1332+
#define KMP_INIT_WAIT 1024U /* initial number of spin-tests */
1333+
#define KMP_NEXT_WAIT 512U /* susequent number of spin-tests */
13301334
#elif KMP_OS_HURD
13311335
/* TODO: tune for KMP_OS_HURD */
13321336
#define KMP_INIT_WAIT 1024U /* initial number of spin-tests */
13331337
#define KMP_NEXT_WAIT 512U /* susequent number of spin-tests */
1334-
#elif KMP_OS_OPENBSD
1335-
/* TODO: tune for KMP_OS_OPENBSD */
1338+
#elif KMP_OS_SOLARIS
1339+
/* TODO: tune for KMP_OS_SOLARIS */
13361340
#define KMP_INIT_WAIT 1024U /* initial number of spin-tests */
13371341
#define KMP_NEXT_WAIT 512U /* susequent number of spin-tests */
13381342
#endif

openmp/runtime/src/kmp_ftn_entry.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -582,7 +582,7 @@ int FTN_STDCALL KMP_EXPAND_NAME(FTN_GET_THREAD_NUM)(void) {
582582
int gtid;
583583

584584
#if KMP_OS_DARWIN || KMP_OS_DRAGONFLY || KMP_OS_FREEBSD || KMP_OS_NETBSD || \
585-
KMP_OS_HURD || KMP_OS_OPENBSD
585+
KMP_OS_OPENBSD || KMP_OS_HURD || KMP_OS_SOLARIS
586586
gtid = __kmp_entry_gtid();
587587
#elif KMP_OS_WINDOWS
588588
if (!__kmp_init_parallel ||

openmp/runtime/src/kmp_platform.h

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#define KMP_OS_DARWIN 0
2424
#define KMP_OS_WINDOWS 0
2525
#define KMP_OS_HURD 0
26+
#define KMP_OS_SOLARIS 0
2627
#define KMP_OS_UNIX 0 /* disjunction of KMP_OS_LINUX, KMP_OS_DARWIN etc. */
2728

2829
#ifdef _WIN32
@@ -70,13 +71,19 @@
7071
#define KMP_OS_HURD 1
7172
#endif
7273

74+
#if (defined __sun__ && defined __svr4__)
75+
#undef KMP_OS_SOLARIS
76+
#define KMP_OS_SOLARIS 1
77+
#endif
78+
7379
#if (1 != KMP_OS_LINUX + KMP_OS_DRAGONFLY + KMP_OS_FREEBSD + KMP_OS_NETBSD + \
74-
KMP_OS_OPENBSD + KMP_OS_DARWIN + KMP_OS_WINDOWS + KMP_OS_HURD)
80+
KMP_OS_OPENBSD + KMP_OS_DARWIN + KMP_OS_WINDOWS + KMP_OS_HURD + \
81+
KMP_OS_SOLARIS)
7582
#error Unknown OS
7683
#endif
7784

7885
#if KMP_OS_LINUX || KMP_OS_DRAGONFLY || KMP_OS_FREEBSD || KMP_OS_NETBSD || \
79-
KMP_OS_OPENBSD || KMP_OS_DARWIN || KMP_OS_HURD
86+
KMP_OS_OPENBSD || KMP_OS_DARWIN || KMP_OS_HURD || KMP_OS_SOLARIS
8087
#undef KMP_OS_UNIX
8188
#define KMP_OS_UNIX 1
8289
#endif

openmp/runtime/src/kmp_runtime.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8897,7 +8897,8 @@ __kmp_determine_reduction_method(
88978897
KMP_ARCH_MIPS64 || KMP_ARCH_RISCV64 || KMP_ARCH_LOONGARCH64 || KMP_ARCH_VE
88988898

88998899
#if KMP_OS_LINUX || KMP_OS_DRAGONFLY || KMP_OS_FREEBSD || KMP_OS_NETBSD || \
8900-
KMP_OS_OPENBSD || KMP_OS_WINDOWS || KMP_OS_DARWIN || KMP_OS_HURD
8900+
KMP_OS_OPENBSD || KMP_OS_WINDOWS || KMP_OS_DARWIN || KMP_OS_HURD || \
8901+
KMP_OS_SOLARIS
89018902

89028903
int teamsize_cutoff = 4;
89038904

@@ -8921,12 +8922,13 @@ __kmp_determine_reduction_method(
89218922
#else
89228923
#error "Unknown or unsupported OS"
89238924
#endif // KMP_OS_LINUX || KMP_OS_DRAGONFLY || KMP_OS_FREEBSD || KMP_OS_NETBSD ||
8924-
// KMP_OS_OPENBSD || KMP_OS_WINDOWS || KMP_OS_DARWIN || KMP_OS_HURD
8925+
// KMP_OS_OPENBSD || KMP_OS_WINDOWS || KMP_OS_DARWIN || KMP_OS_HURD ||
8926+
// KMP_OS_SOLARIS
89258927

89268928
#elif KMP_ARCH_X86 || KMP_ARCH_ARM || KMP_ARCH_AARCH || KMP_ARCH_MIPS
89278929

89288930
#if KMP_OS_LINUX || KMP_OS_DRAGONFLY || KMP_OS_FREEBSD || KMP_OS_NETBSD || \
8929-
KMP_OS_OPENBSD || KMP_OS_WINDOWS || KMP_OS_HURD
8931+
KMP_OS_OPENBSD || KMP_OS_WINDOWS || KMP_OS_HURD || KMP_OS_SOLARIS
89308932

89318933
// basic tuning
89328934

openmp/runtime/src/z_Linux_util.cpp

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@
6060
#elif KMP_OS_NETBSD || KMP_OS_OPENBSD
6161
#include <sys/types.h>
6262
#include <sys/sysctl.h>
63+
#elif KMP_OS_SOLARIS
64+
#include <sys/loadavg.h>
6365
#endif
6466

6567
#include <ctype.h>
@@ -70,6 +72,15 @@ struct kmp_sys_timer {
7072
struct timespec start;
7173
};
7274

75+
#ifdef KMP_OS_SOLARIS
76+
// Convert timeval to timespec.
77+
#define TIMEVAL_TO_TIMESPEC(tv, ts) \
78+
do { \
79+
(ts)->tv_sec = (tv)->tv_sec; \
80+
(ts)->tv_nsec = (tv)->tv_usec * 1000; \
81+
} while (0)
82+
#endif
83+
7384
// Convert timespec to nanoseconds.
7485
#define TS2NS(timespec) \
7586
(((timespec).tv_sec * (long int)1e9) + (timespec).tv_nsec)
@@ -409,7 +420,7 @@ void __kmp_terminate_thread(int gtid) {
409420
static kmp_int32 __kmp_set_stack_info(int gtid, kmp_info_t *th) {
410421
int stack_data;
411422
#if KMP_OS_LINUX || KMP_OS_DRAGONFLY || KMP_OS_FREEBSD || KMP_OS_NETBSD || \
412-
KMP_OS_HURD
423+
KMP_OS_HURD || KMP_OS_SOLARIS
413424
pthread_attr_t attr;
414425
int status;
415426
size_t size = 0;
@@ -448,7 +459,7 @@ static kmp_int32 __kmp_set_stack_info(int gtid, kmp_info_t *th) {
448459
return TRUE;
449460
}
450461
#endif /* KMP_OS_LINUX || KMP_OS_DRAGONFLY || KMP_OS_FREEBSD || KMP_OS_NETBSD \
451-
|| KMP_OS_HURD */
462+
|| KMP_OS_HURD || KMP_OS_SOLARIS */
452463
/* Use incremental refinement starting from initial conservative estimate */
453464
TCW_PTR(th->th.th_info.ds.ds_stacksize, 0);
454465
TCW_PTR(th->th.th_info.ds.ds_stackbase, &stack_data);
@@ -1813,7 +1824,7 @@ static int __kmp_get_xproc(void) {
18131824
__kmp_type_convert(sysconf(_SC_NPROCESSORS_CONF), &(r));
18141825

18151826
#elif KMP_OS_DRAGONFLY || KMP_OS_FREEBSD || KMP_OS_NETBSD || KMP_OS_OPENBSD || \
1816-
KMP_OS_HURD
1827+
KMP_OS_HURD || KMP_OS_SOLARIS
18171828

18181829
__kmp_type_convert(sysconf(_SC_NPROCESSORS_ONLN), &(r));
18191830

@@ -2189,9 +2200,9 @@ int __kmp_is_address_mapped(void *addr) {
21892200
}
21902201
kiv.kve_start += 1;
21912202
}
2192-
#elif KMP_OS_DRAGONFLY
2203+
#elif KMP_OS_DRAGONFLY || KMP_OS_SOLARIS
21932204

2194-
// FIXME(DragonFly): Implement this
2205+
// FIXME(DragonFly, Solaris): Implement this
21952206
found = 1;
21962207

21972208
#else
@@ -2207,7 +2218,7 @@ int __kmp_is_address_mapped(void *addr) {
22072218
#ifdef USE_LOAD_BALANCE
22082219

22092220
#if KMP_OS_DARWIN || KMP_OS_DRAGONFLY || KMP_OS_FREEBSD || KMP_OS_NETBSD || \
2210-
KMP_OS_OPENBSD
2221+
KMP_OS_OPENBSD || KMP_OS_SOLARIS
22112222

22122223
// The function returns the rounded value of the system load average
22132224
// during given time interval which depends on the value of

0 commit comments

Comments
 (0)