Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / openmp / runtime / src / kmp_platform.h
blob1a2197d338342aca5690bc03c7fd4ff5e8a01a5e
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_UNIX 0 /* disjunction of KMP_OS_LINUX, KMP_OS_DARWIN etc. */
28 #ifdef _WIN32
29 #undef KMP_OS_WINDOWS
30 #define KMP_OS_WINDOWS 1
31 #endif
33 #if (defined __APPLE__ && defined __MACH__)
34 #undef KMP_OS_DARWIN
35 #define KMP_OS_DARWIN 1
36 #endif
38 // in some ppc64 linux installations, only the second condition is met
39 #if (defined __linux)
40 #undef KMP_OS_LINUX
41 #define KMP_OS_LINUX 1
42 #elif (defined __linux__)
43 #undef KMP_OS_LINUX
44 #define KMP_OS_LINUX 1
45 #else
46 #endif
48 #if (defined __DragonFly__)
49 #undef KMP_OS_DRAGONFLY
50 #define KMP_OS_DRAGONFLY 1
51 #endif
53 #if (defined __FreeBSD__)
54 #undef KMP_OS_FREEBSD
55 #define KMP_OS_FREEBSD 1
56 #endif
58 #if (defined __NetBSD__)
59 #undef KMP_OS_NETBSD
60 #define KMP_OS_NETBSD 1
61 #endif
63 #if (defined __OpenBSD__)
64 #undef KMP_OS_OPENBSD
65 #define KMP_OS_OPENBSD 1
66 #endif
68 #if (defined __GNU__)
69 #undef KMP_OS_HURD
70 #define KMP_OS_HURD 1
71 #endif
73 #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)
75 #error Unknown OS
76 #endif
78 #if KMP_OS_LINUX || KMP_OS_DRAGONFLY || KMP_OS_FREEBSD || KMP_OS_NETBSD || \
79 KMP_OS_OPENBSD || KMP_OS_DARWIN || KMP_OS_HURD
80 #undef KMP_OS_UNIX
81 #define KMP_OS_UNIX 1
82 #endif
84 /* ---------------------- Architecture recognition ------------------- */
86 #define KMP_ARCH_X86 0
87 #define KMP_ARCH_X86_64 0
88 #define KMP_ARCH_AARCH64 0
89 #define KMP_ARCH_PPC64_ELFv1 0
90 #define KMP_ARCH_PPC64_ELFv2 0
91 #define KMP_ARCH_PPC64 (KMP_ARCH_PPC64_ELFv2 || KMP_ARCH_PPC64_ELFv1)
92 #define KMP_ARCH_MIPS 0
93 #define KMP_ARCH_MIPS64 0
94 #define KMP_ARCH_RISCV64 0
95 #define KMP_ARCH_LOONGARCH64 0
96 #define KMP_ARCH_VE 0
98 #if KMP_OS_WINDOWS
99 #if defined(_M_AMD64) || defined(__x86_64)
100 #undef KMP_ARCH_X86_64
101 #define KMP_ARCH_X86_64 1
102 #elif defined(__aarch64__) || defined(_M_ARM64)
103 #undef KMP_ARCH_AARCH64
104 #define KMP_ARCH_AARCH64 1
105 #elif defined(__arm__) || defined(_M_ARM)
106 #undef KMP_ARCH_ARMV7
107 #define KMP_ARCH_ARMV7 1
108 #else
109 #undef KMP_ARCH_X86
110 #define KMP_ARCH_X86 1
111 #endif
112 #endif
114 #if KMP_OS_UNIX
115 #if defined __x86_64
116 #undef KMP_ARCH_X86_64
117 #define KMP_ARCH_X86_64 1
118 #elif defined __i386
119 #undef KMP_ARCH_X86
120 #define KMP_ARCH_X86 1
121 #elif defined __powerpc64__
122 #if defined(_CALL_ELF) && _CALL_ELF == 2
123 #undef KMP_ARCH_PPC64_ELFv2
124 #define KMP_ARCH_PPC64_ELFv2 1
125 #else
126 #undef KMP_ARCH_PPC64_ELFv1
127 #define KMP_ARCH_PPC64_ELFv1 1
128 #endif
129 #elif defined __aarch64__
130 #undef KMP_ARCH_AARCH64
131 #define KMP_ARCH_AARCH64 1
132 #elif defined __mips__
133 #if defined __mips64
134 #undef KMP_ARCH_MIPS64
135 #define KMP_ARCH_MIPS64 1
136 #else
137 #undef KMP_ARCH_MIPS
138 #define KMP_ARCH_MIPS 1
139 #endif
140 #elif defined __riscv && __riscv_xlen == 64
141 #undef KMP_ARCH_RISCV64
142 #define KMP_ARCH_RISCV64 1
143 #elif defined __loongarch__ && __loongarch_grlen == 64
144 #undef KMP_ARCH_LOONGARCH64
145 #define KMP_ARCH_LOONGARCH64 1
146 #elif defined __ve__
147 #undef KMP_ARCH_VE
148 #define KMP_ARCH_VE 1
149 #endif
150 #endif
152 #if defined(__ARM_ARCH_7__) || defined(__ARM_ARCH_7R__) || \
153 defined(__ARM_ARCH_7A__) || defined(__ARM_ARCH_7VE__)
154 #define KMP_ARCH_ARMV7 1
155 #endif
157 #if defined(KMP_ARCH_ARMV7) || defined(__ARM_ARCH_6__) || \
158 defined(__ARM_ARCH_6J__) || defined(__ARM_ARCH_6K__) || \
159 defined(__ARM_ARCH_6Z__) || defined(__ARM_ARCH_6T2__) || \
160 defined(__ARM_ARCH_6ZK__)
161 #define KMP_ARCH_ARMV6 1
162 #endif
164 #if defined(KMP_ARCH_ARMV6) || defined(__ARM_ARCH_5T__) || \
165 defined(__ARM_ARCH_5E__) || defined(__ARM_ARCH_5TE__) || \
166 defined(__ARM_ARCH_5TEJ__)
167 #define KMP_ARCH_ARMV5 1
168 #endif
170 #if defined(KMP_ARCH_ARMV5) || defined(__ARM_ARCH_4__) || \
171 defined(__ARM_ARCH_4T__)
172 #define KMP_ARCH_ARMV4 1
173 #endif
175 #if defined(KMP_ARCH_ARMV4) || defined(__ARM_ARCH_3__) || \
176 defined(__ARM_ARCH_3M__)
177 #define KMP_ARCH_ARMV3 1
178 #endif
180 #if defined(KMP_ARCH_ARMV3) || defined(__ARM_ARCH_2__)
181 #define KMP_ARCH_ARMV2 1
182 #endif
184 #if defined(KMP_ARCH_ARMV2)
185 #define KMP_ARCH_ARM 1
186 #endif
188 #if defined(__MIC__) || defined(__MIC2__)
189 #define KMP_MIC 1
190 #if __MIC2__ || __KNC__
191 #define KMP_MIC1 0
192 #define KMP_MIC2 1
193 #else
194 #define KMP_MIC1 1
195 #define KMP_MIC2 0
196 #endif
197 #else
198 #define KMP_MIC 0
199 #define KMP_MIC1 0
200 #define KMP_MIC2 0
201 #endif
203 /* Specify 32 bit architectures here */
204 #define KMP_32_BIT_ARCH (KMP_ARCH_X86 || KMP_ARCH_ARM || KMP_ARCH_MIPS)
206 // Platforms which support Intel(R) Many Integrated Core Architecture
207 #define KMP_MIC_SUPPORTED \
208 ((KMP_ARCH_X86 || KMP_ARCH_X86_64) && (KMP_OS_LINUX || KMP_OS_WINDOWS))
210 // TODO: Fixme - This is clever, but really fugly
211 #if (1 != KMP_ARCH_X86 + KMP_ARCH_X86_64 + KMP_ARCH_ARM + KMP_ARCH_PPC64 + \
212 KMP_ARCH_AARCH64 + KMP_ARCH_MIPS + KMP_ARCH_MIPS64 + \
213 KMP_ARCH_RISCV64 + KMP_ARCH_LOONGARCH64 + KMP_ARCH_VE)
214 #error Unknown or unsupported architecture
215 #endif
217 #endif // KMP_PLATFORM_H