LLVM OpenMP* Runtime Library
 All Classes Functions Variables Typedefs Enumerations Enumerator Groups Pages
kmp_platform.h
1 /*
2  * kmp_platform.h -- header for determining operating system and architecture
3  */
4 
5 //===----------------------------------------------------------------------===//
6 //
7 // The LLVM Compiler Infrastructure
8 //
9 // This file is dual licensed under the MIT and the University of Illinois Open
10 // Source Licenses. See LICENSE.txt for details.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #ifndef KMP_PLATFORM_H
15 #define KMP_PLATFORM_H
16 
17 /* ---------------------- Operating system recognition ------------------- */
18 
19 #define KMP_OS_LINUX 0
20 #define KMP_OS_FREEBSD 0
21 #define KMP_OS_KFREEBSD 0
22 #define KMP_OS_NETBSD 0
23 #define KMP_OS_DARWIN 0
24 #define KMP_OS_WINDOWS 0
25 #define KMP_OS_CNK 0
26 #define KMP_OS_HURD 0
27 #define KMP_OS_UNIX 0 /* disjunction of KMP_OS_LINUX, KMP_OS_DARWIN etc. */
28 
29 #ifdef _WIN32
30 #undef KMP_OS_WINDOWS
31 #define KMP_OS_WINDOWS 1
32 #endif
33 
34 #if (defined __APPLE__ && defined __MACH__)
35 #undef KMP_OS_DARWIN
36 #define KMP_OS_DARWIN 1
37 #endif
38 
39 // in some ppc64 linux installations, only the second condition is met
40 #if (defined __linux)
41 #undef KMP_OS_LINUX
42 #define KMP_OS_LINUX 1
43 #elif (defined __linux__)
44 #undef KMP_OS_LINUX
45 #define KMP_OS_LINUX 1
46 #else
47 #endif
48 
49 #if (defined __FreeBSD__)
50 #undef KMP_OS_FREEBSD
51 #define KMP_OS_FREEBSD 1
52 #endif
53 
54 #if (defined __FreeBSD_kernel__)
55 #undef KMP_OS_KFREEBSD
56 #define KMP_OS_KFREEBSD 1
57 #endif
58 
59 #if (defined __NetBSD__)
60 #undef KMP_OS_NETBSD
61 #define KMP_OS_NETBSD 1
62 #endif
63 
64 #if (defined __bgq__)
65 #undef KMP_OS_CNK
66 #define KMP_OS_CNK 1
67 #endif
68 
69 #if (defined __GNU__)
70 #undef KMP_OS_HURD
71 #define KMP_OS_HURD 1
72 #endif
73 
74 #if (1 != \
75  KMP_OS_LINUX + KMP_OS_FREEBSD + KMP_OS_NETBSD + KMP_OS_DARWIN + \
76  KMP_OS_WINDOWS + KMP_OS_HURD + KMP_OS_KFREEBSD)
77 #error Unknown OS
78 #endif
79 
80 #if KMP_OS_LINUX || KMP_OS_FREEBSD || KMP_OS_KFREEBSD || KMP_OS_NETBSD || KMP_OS_DARWIN || KMP_OS_HURD
81 #undef KMP_OS_UNIX
82 #define KMP_OS_UNIX 1
83 #endif
84 
85 /* ---------------------- Architecture recognition ------------------- */
86 
87 #define KMP_ARCH_X86 0
88 #define KMP_ARCH_X86_64 0
89 #define KMP_ARCH_AARCH64 0
90 #define KMP_ARCH_PPC64_BE 0
91 #define KMP_ARCH_PPC64_LE 0
92 #define KMP_ARCH_PPC64 (KMP_ARCH_PPC64_LE || KMP_ARCH_PPC64_BE)
93 #define KMP_ARCH_MIPS 0
94 #define KMP_ARCH_MIPS64 0
95 
96 #if KMP_OS_WINDOWS
97 #if defined _M_AMD64
98 #undef KMP_ARCH_X86_64
99 #define KMP_ARCH_X86_64 1
100 #else
101 #undef KMP_ARCH_X86
102 #define KMP_ARCH_X86 1
103 #endif
104 #endif
105 
106 #if KMP_OS_UNIX
107 #if defined __x86_64
108 #undef KMP_ARCH_X86_64
109 #define KMP_ARCH_X86_64 1
110 #elif defined __i386
111 #undef KMP_ARCH_X86
112 #define KMP_ARCH_X86 1
113 #elif defined __powerpc64__
114 #if defined __LITTLE_ENDIAN__
115 #undef KMP_ARCH_PPC64_LE
116 #define KMP_ARCH_PPC64_LE 1
117 #else
118 #undef KMP_ARCH_PPC64_BE
119 #define KMP_ARCH_PPC64_BE 1
120 #endif
121 #elif defined __aarch64__
122 #undef KMP_ARCH_AARCH64
123 #define KMP_ARCH_AARCH64 1
124 #elif defined __mips__
125 #if defined __mips64
126 #undef KMP_ARCH_MIPS64
127 #define KMP_ARCH_MIPS64 1
128 #else
129 #undef KMP_ARCH_MIPS
130 #define KMP_ARCH_MIPS 1
131 #endif
132 #endif
133 #endif
134 
135 #if defined(__ARM_ARCH_7__) || defined(__ARM_ARCH_7R__) || \
136  defined(__ARM_ARCH_7A__)
137 #define KMP_ARCH_ARMV7 1
138 #endif
139 
140 #if defined(KMP_ARCH_ARMV7) || defined(__ARM_ARCH_6__) || \
141  defined(__ARM_ARCH_6J__) || defined(__ARM_ARCH_6K__) || \
142  defined(__ARM_ARCH_6Z__) || defined(__ARM_ARCH_6T2__) || \
143  defined(__ARM_ARCH_6ZK__)
144 #define KMP_ARCH_ARMV6 1
145 #endif
146 
147 #if defined(KMP_ARCH_ARMV6) || defined(__ARM_ARCH_5T__) || \
148  defined(__ARM_ARCH_5E__) || defined(__ARM_ARCH_5TE__) || \
149  defined(__ARM_ARCH_5TEJ__)
150 #define KMP_ARCH_ARMV5 1
151 #endif
152 
153 #if defined(KMP_ARCH_ARMV5) || defined(__ARM_ARCH_4__) || \
154  defined(__ARM_ARCH_4T__)
155 #define KMP_ARCH_ARMV4 1
156 #endif
157 
158 #if defined(KMP_ARCH_ARMV4) || defined(__ARM_ARCH_3__) || \
159  defined(__ARM_ARCH_3M__)
160 #define KMP_ARCH_ARMV3 1
161 #endif
162 
163 #if defined(KMP_ARCH_ARMV3) || defined(__ARM_ARCH_2__)
164 #define KMP_ARCH_ARMV2 1
165 #endif
166 
167 #if defined(KMP_ARCH_ARMV2)
168 #define KMP_ARCH_ARM 1
169 #endif
170 
171 #if defined(__MIC__) || defined(__MIC2__)
172 #define KMP_MIC 1
173 #if __MIC2__ || __KNC__
174 #define KMP_MIC1 0
175 #define KMP_MIC2 1
176 #else
177 #define KMP_MIC1 1
178 #define KMP_MIC2 0
179 #endif
180 #else
181 #define KMP_MIC 0
182 #define KMP_MIC1 0
183 #define KMP_MIC2 0
184 #endif
185 
186 /* Specify 32 bit architectures here */
187 #define KMP_32_BIT_ARCH (KMP_ARCH_X86 || KMP_ARCH_ARM || KMP_ARCH_MIPS)
188 
189 // Platforms which support Intel(R) Many Integrated Core Architecture
190 #define KMP_MIC_SUPPORTED \
191  ((KMP_ARCH_X86 || KMP_ARCH_X86_64) && (KMP_OS_LINUX || KMP_OS_WINDOWS))
192 
193 // TODO: Fixme - This is clever, but really fugly
194 #if (1 != \
195  KMP_ARCH_X86 + KMP_ARCH_X86_64 + KMP_ARCH_ARM + KMP_ARCH_PPC64 + \
196  KMP_ARCH_AARCH64 + KMP_ARCH_MIPS + KMP_ARCH_MIPS64)
197 #error Unknown or unsupported architecture
198 #endif
199 
200 #endif // KMP_PLATFORM_H