[memprof] Upgrade a unit test to MemProf Version 3 (#117063)
[llvm-project.git] / openmp / runtime / src / kmp_platform.h
blob9c2215140467df582fa08668779c271bf8c64971
1 /*
2 * kmp_platform.h -- header for determining operating system and architecture
3 */
5 //===----------------------------------------------------------------------===//
6 //
7 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
8 // See https://llvm.org/LICENSE.txt for license information.
9 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
11 //===----------------------------------------------------------------------===//
13 #ifndef KMP_PLATFORM_H
14 #define KMP_PLATFORM_H
16 /* ---------------------- Operating system recognition ------------------- */
18 #define KMP_OS_LINUX 0
19 #define KMP_OS_DRAGONFLY 0
20 #define KMP_OS_FREEBSD 0
21 #define KMP_OS_NETBSD 0
22 #define KMP_OS_OPENBSD 0
23 #define KMP_OS_DARWIN 0
24 #define KMP_OS_WINDOWS 0
25 #define KMP_OS_HURD 0
26 #define KMP_OS_SOLARIS 0
27 #define KMP_OS_WASI 0
28 #define KMP_OS_EMSCRIPTEN 0
29 #define KMP_OS_UNIX 0 /* disjunction of KMP_OS_LINUX, KMP_OS_DARWIN etc. */
31 #ifdef _WIN32
32 #undef KMP_OS_WINDOWS
33 #define KMP_OS_WINDOWS 1
34 #endif
36 #if (defined __APPLE__ && defined __MACH__)
37 #undef KMP_OS_DARWIN
38 #define KMP_OS_DARWIN 1
39 #endif
41 // in some ppc64 linux installations, only the second condition is met
42 #if (defined __linux)
43 #undef KMP_OS_LINUX
44 #define KMP_OS_LINUX 1
45 #elif (defined __linux__)
46 #undef KMP_OS_LINUX
47 #define KMP_OS_LINUX 1
48 #elif defined(__EMSCRIPTEN__)
49 #undef KMP_OS_LINUX
50 #undef KMP_OS_EMSCRIPTEN
51 #define KMP_OS_LINUX 1
52 #define KMP_OS_EMSCRIPTEN 1
53 #else
54 #endif
56 #if (defined __DragonFly__)
57 #undef KMP_OS_DRAGONFLY
58 #define KMP_OS_DRAGONFLY 1
59 #endif
61 #if (defined __FreeBSD__)
62 #undef KMP_OS_FREEBSD
63 #define KMP_OS_FREEBSD 1
64 #endif
66 #if (defined __NetBSD__)
67 #undef KMP_OS_NETBSD
68 #define KMP_OS_NETBSD 1
69 #endif
71 #if (defined __OpenBSD__)
72 #undef KMP_OS_OPENBSD
73 #define KMP_OS_OPENBSD 1
74 #endif
76 #if (defined __GNU__)
77 #undef KMP_OS_HURD
78 #define KMP_OS_HURD 1
79 #endif
81 #if (defined __sun__ && defined __svr4__)
82 #undef KMP_OS_SOLARIS
83 #define KMP_OS_SOLARIS 1
84 #endif
86 #if (defined __wasi__)
87 #undef KMP_OS_WASI
88 #define KMP_OS_WASI 1
89 #endif
91 #if (defined _AIX)
92 #undef KMP_OS_AIX
93 #define KMP_OS_AIX 1
94 #endif
96 #if (1 != KMP_OS_LINUX + KMP_OS_DRAGONFLY + KMP_OS_FREEBSD + KMP_OS_NETBSD + \
97 KMP_OS_OPENBSD + KMP_OS_DARWIN + KMP_OS_WINDOWS + KMP_OS_HURD + \
98 KMP_OS_SOLARIS + KMP_OS_WASI + KMP_OS_AIX)
99 #error Unknown OS
100 #endif
102 #if KMP_OS_LINUX || KMP_OS_DRAGONFLY || KMP_OS_FREEBSD || KMP_OS_NETBSD || \
103 KMP_OS_OPENBSD || KMP_OS_DARWIN || KMP_OS_HURD || KMP_OS_SOLARIS || \
104 KMP_OS_WASI || KMP_OS_AIX
105 #undef KMP_OS_UNIX
106 #define KMP_OS_UNIX 1
107 #endif
109 /* ---------------------- Architecture recognition ------------------- */
111 #define KMP_ARCH_X86 0
112 #define KMP_ARCH_X86_64 0
113 #define KMP_ARCH_AARCH64 0
114 #define KMP_ARCH_AARCH64_32 0
115 #define KMP_ARCH_PPC64_ELFv1 0
116 #define KMP_ARCH_PPC64_ELFv2 0
117 #define KMP_ARCH_PPC64_XCOFF 0
118 #define KMP_ARCH_PPC_XCOFF 0
119 #define KMP_ARCH_MIPS 0
120 #define KMP_ARCH_MIPS64 0
121 #define KMP_ARCH_RISCV64 0
122 #define KMP_ARCH_LOONGARCH64 0
123 #define KMP_ARCH_VE 0
124 #define KMP_ARCH_S390X 0
126 #if KMP_OS_WINDOWS
127 #if defined(_M_AMD64) || defined(__x86_64)
128 #undef KMP_ARCH_X86_64
129 #define KMP_ARCH_X86_64 1
130 #elif defined(__aarch64__) || defined(_M_ARM64)
131 #undef KMP_ARCH_AARCH64
132 #define KMP_ARCH_AARCH64 1
133 #elif defined(__arm__) || defined(_M_ARM)
134 #undef KMP_ARCH_ARMV7
135 #define KMP_ARCH_ARMV7 1
136 #else
137 #undef KMP_ARCH_X86
138 #define KMP_ARCH_X86 1
139 #endif
140 #endif
142 #if KMP_OS_UNIX
143 #if defined __x86_64
144 #undef KMP_ARCH_X86_64
145 #define KMP_ARCH_X86_64 1
146 #elif defined __i386
147 #undef KMP_ARCH_X86
148 #define KMP_ARCH_X86 1
149 #elif defined __powerpc64__
150 #if defined(_CALL_ELF)
151 #if _CALL_ELF == 2
152 #undef KMP_ARCH_PPC64_ELFv2
153 #define KMP_ARCH_PPC64_ELFv2 1
154 #else
155 #undef KMP_ARCH_PPC64_ELFv1
156 #define KMP_ARCH_PPC64_ELFv1 1
157 #endif
158 #elif defined KMP_OS_AIX
159 #undef KMP_ARCH_PPC64_XCOFF
160 #define KMP_ARCH_PPC64_XCOFF 1
161 #endif
162 #elif defined(__powerpc__) && defined(KMP_OS_AIX)
163 #undef KMP_ARCH_PPC_XCOFF
164 #define KMP_ARCH_PPC_XCOFF 1
165 #undef KMP_ARCH_PPC
166 #define KMP_ARCH_PPC 1
167 #elif defined __ARM64_ARCH_8_32__
168 #undef KMP_ARCH_AARCH64_32
169 #define KMP_ARCH_AARCH64_32 1
170 #elif defined __aarch64__
171 #undef KMP_ARCH_AARCH64
172 #define KMP_ARCH_AARCH64 1
173 #elif defined __mips__
174 #if defined __mips64
175 #undef KMP_ARCH_MIPS64
176 #define KMP_ARCH_MIPS64 1
177 #else
178 #undef KMP_ARCH_MIPS
179 #define KMP_ARCH_MIPS 1
180 #endif
181 #elif defined __riscv && __riscv_xlen == 64
182 #undef KMP_ARCH_RISCV64
183 #define KMP_ARCH_RISCV64 1
184 #elif defined __loongarch__ && __loongarch_grlen == 64
185 #undef KMP_ARCH_LOONGARCH64
186 #define KMP_ARCH_LOONGARCH64 1
187 #elif defined __ve__
188 #undef KMP_ARCH_VE
189 #define KMP_ARCH_VE 1
190 #elif defined __s390x__
191 #undef KMP_ARCH_S390X
192 #define KMP_ARCH_S390X 1
193 #endif
194 #endif
196 #if defined(__ARM_ARCH_7__) || defined(__ARM_ARCH_7R__) || \
197 defined(__ARM_ARCH_7A__) || defined(__ARM_ARCH_7VE__)
198 #define KMP_ARCH_ARMV7 1
199 #endif
201 #if defined(KMP_ARCH_ARMV7) || defined(__ARM_ARCH_6__) || \
202 defined(__ARM_ARCH_6J__) || defined(__ARM_ARCH_6K__) || \
203 defined(__ARM_ARCH_6Z__) || defined(__ARM_ARCH_6T2__) || \
204 defined(__ARM_ARCH_6ZK__)
205 #define KMP_ARCH_ARMV6 1
206 #endif
208 #if defined(KMP_ARCH_ARMV6) || defined(__ARM_ARCH_5T__) || \
209 defined(__ARM_ARCH_5E__) || defined(__ARM_ARCH_5TE__) || \
210 defined(__ARM_ARCH_5TEJ__)
211 #define KMP_ARCH_ARMV5 1
212 #endif
214 #if defined(KMP_ARCH_ARMV5) || defined(__ARM_ARCH_4__) || \
215 defined(__ARM_ARCH_4T__)
216 #define KMP_ARCH_ARMV4 1
217 #endif
219 #if defined(KMP_ARCH_ARMV4) || defined(__ARM_ARCH_3__) || \
220 defined(__ARM_ARCH_3M__)
221 #define KMP_ARCH_ARMV3 1
222 #endif
224 #if defined(KMP_ARCH_ARMV3) || defined(__ARM_ARCH_2__)
225 #define KMP_ARCH_ARMV2 1
226 #endif
228 #if defined(KMP_ARCH_ARMV2)
229 #define KMP_ARCH_ARM 1
230 #endif
232 #if defined(__wasm32__)
233 #define KMP_ARCH_WASM 1
234 #endif
236 #define KMP_ARCH_PPC64 \
237 (KMP_ARCH_PPC64_ELFv2 || KMP_ARCH_PPC64_ELFv1 || KMP_ARCH_PPC64_XCOFF)
239 #if defined(__MIC__) || defined(__MIC2__)
240 #define KMP_MIC 1
241 #if __MIC2__ || __KNC__
242 #define KMP_MIC1 0
243 #define KMP_MIC2 1
244 #else
245 #define KMP_MIC1 1
246 #define KMP_MIC2 0
247 #endif
248 #else
249 #define KMP_MIC 0
250 #define KMP_MIC1 0
251 #define KMP_MIC2 0
252 #endif
254 /* Specify 32 bit architectures here */
255 #define KMP_32_BIT_ARCH \
256 (KMP_ARCH_X86 || KMP_ARCH_ARM || KMP_ARCH_MIPS || KMP_ARCH_WASM || \
257 KMP_ARCH_PPC || KMP_ARCH_AARCH64_32)
259 // Platforms which support Intel(R) Many Integrated Core Architecture
260 #define KMP_MIC_SUPPORTED \
261 ((KMP_ARCH_X86 || KMP_ARCH_X86_64) && (KMP_OS_LINUX || KMP_OS_WINDOWS))
263 // TODO: Fixme - This is clever, but really fugly
264 #if (1 != KMP_ARCH_X86 + KMP_ARCH_X86_64 + KMP_ARCH_ARM + KMP_ARCH_PPC64 + \
265 KMP_ARCH_AARCH64 + KMP_ARCH_MIPS + KMP_ARCH_MIPS64 + \
266 KMP_ARCH_RISCV64 + KMP_ARCH_LOONGARCH64 + KMP_ARCH_VE + \
267 KMP_ARCH_S390X + KMP_ARCH_WASM + KMP_ARCH_PPC + \
268 KMP_ARCH_AARCH64_32)
269 #error Unknown or unsupported architecture
270 #endif
272 #endif // KMP_PLATFORM_H