comparison include/llvm/Support/Compiler.h @ 95:afa8332a0e37 LLVM3.8

LLVM 3.8
author Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
date Tue, 13 Oct 2015 17:48:58 +0900
parents 60c9769439b8
children 7d135dc70f03
comparison
equal deleted inserted replaced
84:f3e34b893a5f 95:afa8332a0e37
67 #endif 67 #endif
68 68
69 #if !defined(_MSC_VER) || defined(__clang__) || LLVM_MSC_PREREQ(1900) 69 #if !defined(_MSC_VER) || defined(__clang__) || LLVM_MSC_PREREQ(1900)
70 #define LLVM_NOEXCEPT noexcept 70 #define LLVM_NOEXCEPT noexcept
71 #else 71 #else
72 #define LLVM_NOEXCEPT 72 #define LLVM_NOEXCEPT throw()
73 #endif 73 #endif
74 74
75 /// \brief Does the compiler support r-value reference *this? 75 /// \brief Does the compiler support ref-qualifiers for *this?
76 /// 76 ///
77 /// Sadly, this is separate from just r-value reference support because GCC 77 /// Sadly, this is separate from just rvalue reference support because GCC
78 /// implemented this later than everything else. 78 /// and MSVC implemented this later than everything else.
79 #if __has_feature(cxx_rvalue_references) || LLVM_GNUC_PREREQ(4, 8, 1) 79 #if __has_feature(cxx_rvalue_references) || LLVM_GNUC_PREREQ(4, 8, 1)
80 #define LLVM_HAS_RVALUE_REFERENCE_THIS 1 80 #define LLVM_HAS_RVALUE_REFERENCE_THIS 1
81 #else 81 #else
82 #define LLVM_HAS_RVALUE_REFERENCE_THIS 0 82 #define LLVM_HAS_RVALUE_REFERENCE_THIS 0
83 #endif 83 #endif
84 84
85 /// Expands to '&' if r-value references are supported. 85 /// Expands to '&' if ref-qualifiers for *this are supported.
86 /// 86 ///
87 /// This can be used to provide l-value/r-value overrides of member functions. 87 /// This can be used to provide lvalue/rvalue overrides of member functions.
88 /// The r-value override should be guarded by LLVM_HAS_RVALUE_REFERENCE_THIS 88 /// The rvalue override should be guarded by LLVM_HAS_RVALUE_REFERENCE_THIS
89 #if LLVM_HAS_RVALUE_REFERENCE_THIS 89 #if LLVM_HAS_RVALUE_REFERENCE_THIS
90 #define LLVM_LVALUE_FUNCTION & 90 #define LLVM_LVALUE_FUNCTION &
91 #else 91 #else
92 #define LLVM_LVALUE_FUNCTION 92 #define LLVM_LVALUE_FUNCTION
93 #endif 93 #endif
172 #else 172 #else
173 #define LLVM_LIKELY(EXPR) (EXPR) 173 #define LLVM_LIKELY(EXPR) (EXPR)
174 #define LLVM_UNLIKELY(EXPR) (EXPR) 174 #define LLVM_UNLIKELY(EXPR) (EXPR)
175 #endif 175 #endif
176 176
177 // C++ doesn't support 'extern template' of template specializations. GCC does,
178 // but requires __extension__ before it. In the header, use this:
179 // EXTERN_TEMPLATE_INSTANTIATION(class foo<bar>);
180 // in the .cpp file, use this:
181 // TEMPLATE_INSTANTIATION(class foo<bar>);
182 #ifdef __GNUC__
183 #define EXTERN_TEMPLATE_INSTANTIATION(X) __extension__ extern template X
184 #define TEMPLATE_INSTANTIATION(X) template X
185 #else
186 #define EXTERN_TEMPLATE_INSTANTIATION(X)
187 #define TEMPLATE_INSTANTIATION(X)
188 #endif
189
190 /// LLVM_ATTRIBUTE_NOINLINE - On compilers where we have a directive to do so, 177 /// LLVM_ATTRIBUTE_NOINLINE - On compilers where we have a directive to do so,
191 /// mark a method "not for inlining". 178 /// mark a method "not for inlining".
192 #if __has_attribute(noinline) || LLVM_GNUC_PREREQ(3, 4, 0) 179 #if __has_attribute(noinline) || LLVM_GNUC_PREREQ(3, 4, 0)
193 #define LLVM_ATTRIBUTE_NOINLINE __attribute__((noinline)) 180 #define LLVM_ATTRIBUTE_NOINLINE __attribute__((noinline))
194 #elif defined(_MSC_VER) 181 #elif defined(_MSC_VER)
200 /// LLVM_ATTRIBUTE_ALWAYS_INLINE - On compilers where we have a directive to do 187 /// LLVM_ATTRIBUTE_ALWAYS_INLINE - On compilers where we have a directive to do
201 /// so, mark a method "always inline" because it is performance sensitive. GCC 188 /// so, mark a method "always inline" because it is performance sensitive. GCC
202 /// 3.4 supported this but is buggy in various cases and produces unimplemented 189 /// 3.4 supported this but is buggy in various cases and produces unimplemented
203 /// errors, just use it in GCC 4.0 and later. 190 /// errors, just use it in GCC 4.0 and later.
204 #if __has_attribute(always_inline) || LLVM_GNUC_PREREQ(4, 0, 0) 191 #if __has_attribute(always_inline) || LLVM_GNUC_PREREQ(4, 0, 0)
205 #define LLVM_ATTRIBUTE_ALWAYS_INLINE inline __attribute__((always_inline)) 192 #define LLVM_ATTRIBUTE_ALWAYS_INLINE __attribute__((always_inline))
206 #elif defined(_MSC_VER) 193 #elif defined(_MSC_VER)
207 #define LLVM_ATTRIBUTE_ALWAYS_INLINE __forceinline 194 #define LLVM_ATTRIBUTE_ALWAYS_INLINE __forceinline
208 #else 195 #else
209 #define LLVM_ATTRIBUTE_ALWAYS_INLINE 196 #define LLVM_ATTRIBUTE_ALWAYS_INLINE
210 #endif 197 #endif
219 206
220 #if __has_attribute(returns_nonnull) || LLVM_GNUC_PREREQ(4, 9, 0) 207 #if __has_attribute(returns_nonnull) || LLVM_GNUC_PREREQ(4, 9, 0)
221 #define LLVM_ATTRIBUTE_RETURNS_NONNULL __attribute__((returns_nonnull)) 208 #define LLVM_ATTRIBUTE_RETURNS_NONNULL __attribute__((returns_nonnull))
222 #else 209 #else
223 #define LLVM_ATTRIBUTE_RETURNS_NONNULL 210 #define LLVM_ATTRIBUTE_RETURNS_NONNULL
211 #endif
212
213 /// \macro LLVM_ATTRIBUTE_RETURNS_NOALIAS Used to mark a function as returning a
214 /// pointer that does not alias any other valid pointer.
215 #ifdef __GNUC__
216 #define LLVM_ATTRIBUTE_RETURNS_NOALIAS __attribute__((__malloc__))
217 #elif defined(_MSC_VER)
218 #define LLVM_ATTRIBUTE_RETURNS_NOALIAS __declspec(restrict)
219 #else
220 #define LLVM_ATTRIBUTE_RETURNS_NOALIAS
224 #endif 221 #endif
225 222
226 /// LLVM_EXTENSION - Support compilers where we have a keyword to suppress 223 /// LLVM_EXTENSION - Support compilers where we have a keyword to suppress
227 /// pedantic diagnostics. 224 /// pedantic diagnostics.
228 #ifdef __GNUC__ 225 #ifdef __GNUC__
279 (((uintptr_t(p) % (a)) == 0) ? (p) : (LLVM_BUILTIN_UNREACHABLE, (p))) 276 (((uintptr_t(p) % (a)) == 0) ? (p) : (LLVM_BUILTIN_UNREACHABLE, (p)))
280 #else 277 #else
281 # define LLVM_ASSUME_ALIGNED(p, a) (p) 278 # define LLVM_ASSUME_ALIGNED(p, a) (p)
282 #endif 279 #endif
283 280
281 /// \macro LLVM_ALIGNAS
282 /// \brief Used to specify a minimum alignment for a structure or variable. The
283 /// alignment must be a constant integer. Use LLVM_PTR_SIZE to compute
284 /// alignments in terms of the size of a pointer.
285 ///
286 /// Note that __declspec(align) has special quirks, it's not legal to pass a
287 /// structure with __declspec(align) as a formal parameter.
288 #ifdef _MSC_VER
289 # define LLVM_ALIGNAS(x) __declspec(align(x))
290 #elif __GNUC__ && !__has_feature(cxx_alignas) && !LLVM_GNUC_PREREQ(4, 8, 0)
291 # define LLVM_ALIGNAS(x) __attribute__((aligned(x)))
292 #else
293 # define LLVM_ALIGNAS(x) alignas(x)
294 #endif
295
296 /// \macro LLVM_PTR_SIZE
297 /// \brief A constant integer equivalent to the value of sizeof(void*).
298 /// Generally used in combination with LLVM_ALIGNAS or when doing computation in
299 /// the preprocessor.
300 #ifdef __SIZEOF_POINTER__
301 # define LLVM_PTR_SIZE __SIZEOF_POINTER__
302 #elif defined(_WIN64)
303 # define LLVM_PTR_SIZE 8
304 #elif defined(_WIN32)
305 # define LLVM_PTR_SIZE 4
306 #elif defined(_MSC_VER)
307 # error "could not determine LLVM_PTR_SIZE as a constant int for MSVC"
308 #else
309 # define LLVM_PTR_SIZE sizeof(void *)
310 #endif
311
284 /// \macro LLVM_FUNCTION_NAME 312 /// \macro LLVM_FUNCTION_NAME
285 /// \brief Expands to __func__ on compilers which support it. Otherwise, 313 /// \brief Expands to __func__ on compilers which support it. Otherwise,
286 /// expands to a compiler-dependent replacement. 314 /// expands to a compiler-dependent replacement.
287 #if defined(_MSC_VER) 315 #if defined(_MSC_VER)
288 # define LLVM_FUNCTION_NAME __FUNCTION__ 316 # define LLVM_FUNCTION_NAME __FUNCTION__
307 # define LLVM_ADDRESS_SANITIZER_BUILD 1 335 # define LLVM_ADDRESS_SANITIZER_BUILD 1
308 #else 336 #else
309 # define LLVM_ADDRESS_SANITIZER_BUILD 0 337 # define LLVM_ADDRESS_SANITIZER_BUILD 0
310 #endif 338 #endif
311 339
312 /// \macro LLVM_IS_UNALIGNED_ACCESS_FAST 340 /// \macro LLVM_THREAD_SANITIZER_BUILD
313 /// \brief Is unaligned memory access fast on the host machine. 341 /// \brief Whether LLVM itself is built with ThreadSanitizer instrumentation.
314 /// 342 #if __has_feature(thread_sanitizer) || defined(__SANITIZE_THREAD__)
315 /// Don't specialize on alignment for platforms where unaligned memory accesses 343 # define LLVM_THREAD_SANITIZER_BUILD 1
316 /// generates the same code as aligned memory accesses for common types. 344 #else
317 #if defined(_M_AMD64) || defined(_M_IX86) || defined(__amd64) || \ 345 # define LLVM_THREAD_SANITIZER_BUILD 0
318 defined(__amd64__) || defined(__x86_64) || defined(__x86_64__) || \ 346 #endif
319 defined(_X86_) || defined(__i386) || defined(__i386__) 347
320 # define LLVM_IS_UNALIGNED_ACCESS_FAST 1 348 #if LLVM_THREAD_SANITIZER_BUILD
321 #else 349 // Thread Sanitizer is a tool that finds races in code.
322 # define LLVM_IS_UNALIGNED_ACCESS_FAST 0 350 // See http://code.google.com/p/data-race-test/wiki/DynamicAnnotations .
351 // tsan detects these exact functions by name.
352 extern "C" {
353 void AnnotateHappensAfter(const char *file, int line, const volatile void *cv);
354 void AnnotateHappensBefore(const char *file, int line, const volatile void *cv);
355 void AnnotateIgnoreWritesBegin(const char *file, int line);
356 void AnnotateIgnoreWritesEnd(const char *file, int line);
357 }
358
359 // This marker is used to define a happens-before arc. The race detector will
360 // infer an arc from the begin to the end when they share the same pointer
361 // argument.
362 # define TsanHappensBefore(cv) AnnotateHappensBefore(__FILE__, __LINE__, cv)
363
364 // This marker defines the destination of a happens-before arc.
365 # define TsanHappensAfter(cv) AnnotateHappensAfter(__FILE__, __LINE__, cv)
366
367 // Ignore any races on writes between here and the next TsanIgnoreWritesEnd.
368 # define TsanIgnoreWritesBegin() AnnotateIgnoreWritesBegin(__FILE__, __LINE__)
369
370 // Resume checking for racy writes.
371 # define TsanIgnoreWritesEnd() AnnotateIgnoreWritesEnd(__FILE__, __LINE__)
372 #else
373 # define TsanHappensBefore(cv)
374 # define TsanHappensAfter(cv)
375 # define TsanIgnoreWritesBegin()
376 # define TsanIgnoreWritesEnd()
323 #endif 377 #endif
324 378
325 /// \brief Mark debug helper function definitions like dump() that should not be 379 /// \brief Mark debug helper function definitions like dump() that should not be
326 /// stripped from debug builds. 380 /// stripped from debug builds.
327 // FIXME: Move this to a private config.h as it's not usable in public headers. 381 // FIXME: Move this to a private config.h as it's not usable in public headers.