15 #ifndef LLVM_SUPPORT_COMPILER_H
16 #define LLVM_SUPPORT_COMPILER_H
18 #include "llvm/Config/llvm-config.h"
25 # define __has_feature(x) 0
28 #ifndef __has_extension
29 # define __has_extension(x) 0
32 #ifndef __has_attribute
33 # define __has_attribute(x) 0
36 #ifndef __has_cpp_attribute
37 # define __has_cpp_attribute(x) 0
41 # define __has_builtin(x) 0
47 #ifndef LLVM_GNUC_PREREQ
48 # if defined(__GNUC__) && defined(__GNUC_MINOR__) && defined(__GNUC_PATCHLEVEL__)
49 # define LLVM_GNUC_PREREQ(maj, min, patch) \
50 ((__GNUC__ << 20) + (__GNUC_MINOR__ << 10) + __GNUC_PATCHLEVEL__ >= \
51 ((maj) << 20) + ((min) << 10) + (patch))
52 # elif defined(__GNUC__) && defined(__GNUC_MINOR__)
53 # define LLVM_GNUC_PREREQ(maj, min, patch) \
54 ((__GNUC__ << 20) + (__GNUC_MINOR__ << 10) >= ((maj) << 20) + ((min) << 10))
56 # define LLVM_GNUC_PREREQ(maj, min, patch) 0
65 #define LLVM_MSC_PREREQ(version) (_MSC_VER >= (version))
68 #if !LLVM_MSC_PREREQ(1900)
69 #error LLVM requires at least MSVC 2015.
73 #define LLVM_MSC_PREREQ(version) 0
80 #if __has_feature(cxx_rvalue_references) || LLVM_GNUC_PREREQ(4, 8, 1)
81 #define LLVM_HAS_RVALUE_REFERENCE_THIS 1
83 #define LLVM_HAS_RVALUE_REFERENCE_THIS 0
90 #if LLVM_HAS_RVALUE_REFERENCE_THIS
91 #define LLVM_LVALUE_FUNCTION &
93 #define LLVM_LVALUE_FUNCTION
101 #if (__has_attribute(visibility) || LLVM_GNUC_PREREQ(4, 0, 0)) && \
102 !defined(__MINGW32__) && !defined(__CYGWIN__) && !defined(LLVM_ON_WIN32)
103 #define LLVM_LIBRARY_VISIBILITY __attribute__ ((visibility("hidden")))
105 #define LLVM_LIBRARY_VISIBILITY
108 #if defined(__GNUC__)
109 #define LLVM_PREFETCH(addr, rw, locality) __builtin_prefetch(addr, rw, locality)
111 #define LLVM_PREFETCH(addr, rw, locality)
114 #if __has_attribute(sentinel) || LLVM_GNUC_PREREQ(3, 0, 0)
115 #define LLVM_END_WITH_NULL __attribute__((sentinel))
117 #define LLVM_END_WITH_NULL
120 #if __has_attribute(used) || LLVM_GNUC_PREREQ(3, 1, 0)
121 #define LLVM_ATTRIBUTE_USED __attribute__((__used__))
123 #define LLVM_ATTRIBUTE_USED
127 #if __cplusplus > 201402L && __has_cpp_attribute(nodiscard)
128 #define LLVM_NODISCARD [[nodiscard]]
132 #define LLVM_NODISCARD
133 #elif __has_cpp_attribute(clang::warn_unused_result)
134 #define LLVM_NODISCARD [[clang::warn_unused_result]]
136 #define LLVM_NODISCARD
147 #if __has_attribute(unused) || LLVM_GNUC_PREREQ(3, 1, 0)
148 #define LLVM_ATTRIBUTE_UNUSED __attribute__((__unused__))
150 #define LLVM_ATTRIBUTE_UNUSED
154 #if (__has_attribute(weak) || LLVM_GNUC_PREREQ(4, 0, 0)) && \
155 (!defined(__MINGW32__) && !defined(__CYGWIN__) && !defined(LLVM_ON_WIN32))
156 #define LLVM_ATTRIBUTE_WEAK __attribute__((__weak__))
158 #define LLVM_ATTRIBUTE_WEAK
163 #if defined(__clang__) || defined(__GNUC__)
165 #define LLVM_READNONE __attribute__((__const__))
167 #define LLVM_READNONE
170 #if __has_attribute(pure) || defined(__GNUC__)
172 #define LLVM_READONLY __attribute__((__pure__))
174 #define LLVM_READONLY
177 #if __has_builtin(__builtin_expect) || LLVM_GNUC_PREREQ(4, 0, 0)
178 #define LLVM_LIKELY(EXPR) __builtin_expect((bool)(EXPR), true)
179 #define LLVM_UNLIKELY(EXPR) __builtin_expect((bool)(EXPR), false)
181 #define LLVM_LIKELY(EXPR) (EXPR)
182 #define LLVM_UNLIKELY(EXPR) (EXPR)
187 #if __has_attribute(noinline) || LLVM_GNUC_PREREQ(3, 4, 0)
188 #define LLVM_ATTRIBUTE_NOINLINE __attribute__((noinline))
189 #elif defined(_MSC_VER)
190 #define LLVM_ATTRIBUTE_NOINLINE __declspec(noinline)
192 #define LLVM_ATTRIBUTE_NOINLINE
199 #if __has_attribute(always_inline) || LLVM_GNUC_PREREQ(4, 0, 0)
200 #define LLVM_ATTRIBUTE_ALWAYS_INLINE __attribute__((always_inline))
201 #elif defined(_MSC_VER)
202 #define LLVM_ATTRIBUTE_ALWAYS_INLINE __forceinline
204 #define LLVM_ATTRIBUTE_ALWAYS_INLINE
208 #define LLVM_ATTRIBUTE_NORETURN __attribute__((noreturn))
209 #elif defined(_MSC_VER)
210 #define LLVM_ATTRIBUTE_NORETURN __declspec(noreturn)
212 #define LLVM_ATTRIBUTE_NORETURN
215 #if __has_attribute(returns_nonnull) || LLVM_GNUC_PREREQ(4, 9, 0)
216 #define LLVM_ATTRIBUTE_RETURNS_NONNULL __attribute__((returns_nonnull))
217 #elif defined(_MSC_VER)
218 #define LLVM_ATTRIBUTE_RETURNS_NONNULL _Ret_notnull_
220 #define LLVM_ATTRIBUTE_RETURNS_NONNULL
226 #define LLVM_ATTRIBUTE_RETURNS_NOALIAS __attribute__((__malloc__))
227 #elif defined(_MSC_VER)
228 #define LLVM_ATTRIBUTE_RETURNS_NOALIAS __declspec(restrict)
230 #define LLVM_ATTRIBUTE_RETURNS_NOALIAS
234 #if __cplusplus > 201402L && __has_cpp_attribute(fallthrough)
235 #define LLVM_FALLTHROUGH [[fallthrough]]
239 #define LLVM_FALLTHROUGH
240 #elif __has_cpp_attribute(clang::fallthrough)
241 #define LLVM_FALLTHROUGH [[clang::fallthrough]]
243 #define LLVM_FALLTHROUGH
249 #define LLVM_EXTENSION __extension__
251 #define LLVM_EXTENSION
255 #if __has_feature(attribute_deprecated_with_message)
256 # define LLVM_ATTRIBUTE_DEPRECATED(decl, message) \
257 decl __attribute__((deprecated(message)))
258 #elif defined(__GNUC__)
259 # define LLVM_ATTRIBUTE_DEPRECATED(decl, message) \
260 decl __attribute__((deprecated))
261 #elif defined(_MSC_VER)
262 # define LLVM_ATTRIBUTE_DEPRECATED(decl, message) \
263 __declspec(deprecated(message)) decl
265 # define LLVM_ATTRIBUTE_DEPRECATED(decl, message) \
272 #if __has_builtin(__builtin_unreachable) || LLVM_GNUC_PREREQ(4, 5, 0)
273 # define LLVM_BUILTIN_UNREACHABLE __builtin_unreachable()
274 #elif defined(_MSC_VER)
275 # define LLVM_BUILTIN_UNREACHABLE __assume(false)
280 #if __has_builtin(__builtin_trap) || LLVM_GNUC_PREREQ(4, 3, 0)
281 # define LLVM_BUILTIN_TRAP __builtin_trap()
282 #elif defined(_MSC_VER)
287 # define LLVM_BUILTIN_TRAP __debugbreak()
289 # define LLVM_BUILTIN_TRAP *(volatile int*)0x11 = 0
295 #if __has_builtin(__builtin_debugtrap)
296 # define LLVM_BUILTIN_DEBUGTRAP __builtin_debugtrap()
297 #elif defined(_MSC_VER)
301 # define LLVM_BUILTIN_DEBUGTRAP __debugbreak()
306 # define LLVM_BUILTIN_DEBUGTRAP
311 #if __has_builtin(__builtin_assume_aligned) || LLVM_GNUC_PREREQ(4, 7, 0)
312 # define LLVM_ASSUME_ALIGNED(p, a) __builtin_assume_aligned(p, a)
313 #elif defined(LLVM_BUILTIN_UNREACHABLE)
315 # define LLVM_ASSUME_ALIGNED(p, a) \
316 (((uintptr_t(p) % (a)) == 0) ? (p) : (LLVM_BUILTIN_UNREACHABLE, (p)))
318 # define LLVM_ASSUME_ALIGNED(p, a) (p)
323 #if __GNUC__ && !__has_feature(cxx_alignas) && !LLVM_GNUC_PREREQ(4, 8, 1)
324 # define LLVM_ALIGNAS(x) __attribute__((aligned(x)))
326 # define LLVM_ALIGNAS(x) alignas(x)
348 # define LLVM_PACKED(d) __pragma(pack(push, 1)) d __pragma(pack(pop))
349 # define LLVM_PACKED_START __pragma(pack(push, 1))
350 # define LLVM_PACKED_END __pragma(pack(pop))
352 # define LLVM_PACKED(d) d __attribute__((packed))
353 # define LLVM_PACKED_START _Pragma("pack(push, 1)")
354 # define LLVM_PACKED_END _Pragma("pack(pop)")
361 #ifdef __SIZEOF_POINTER__
362 # define LLVM_PTR_SIZE __SIZEOF_POINTER__
363 #elif defined(_WIN64)
364 # define LLVM_PTR_SIZE 8
365 #elif defined(_WIN32)
366 # define LLVM_PTR_SIZE 4
367 #elif defined(_MSC_VER)
368 # error "could not determine LLVM_PTR_SIZE as a constant int for MSVC"
370 # define LLVM_PTR_SIZE sizeof(void *)
375 #if __has_feature(memory_sanitizer)
376 # define LLVM_MEMORY_SANITIZER_BUILD 1
377 # include <sanitizer/msan_interface.h>
379 # define LLVM_MEMORY_SANITIZER_BUILD 0
380 # define __msan_allocated_memory(p, size)
381 # define __msan_unpoison(p, size)
386 #if __has_feature(address_sanitizer) || defined(__SANITIZE_ADDRESS__)
387 # define LLVM_ADDRESS_SANITIZER_BUILD 1
388 # include <sanitizer/asan_interface.h>
390 # define LLVM_ADDRESS_SANITIZER_BUILD 0
391 # define __asan_poison_memory_region(p, size)
392 # define __asan_unpoison_memory_region(p, size)
397 #if __has_feature(thread_sanitizer) || defined(__SANITIZE_THREAD__)
398 # define LLVM_THREAD_SANITIZER_BUILD 1
400 # define LLVM_THREAD_SANITIZER_BUILD 0
403 #if LLVM_THREAD_SANITIZER_BUILD
410 void AnnotateHappensAfter(
const char *
file,
int line,
const volatile void *cv);
411 void AnnotateHappensBefore(
const char *file,
int line,
const volatile void *cv);
412 void AnnotateIgnoreWritesBegin(
const char *file,
int line);
413 void AnnotateIgnoreWritesEnd(
const char *file,
int line);
421 # define TsanHappensBefore(cv) AnnotateHappensBefore(__FILE__, __LINE__, cv)
424 # define TsanHappensAfter(cv) AnnotateHappensAfter(__FILE__, __LINE__, cv)
427 # define TsanIgnoreWritesBegin() AnnotateIgnoreWritesBegin(__FILE__, __LINE__)
430 # define TsanIgnoreWritesEnd() AnnotateIgnoreWritesEnd(__FILE__, __LINE__)
432 # define TsanHappensBefore(cv)
433 # define TsanHappensAfter(cv)
434 # define TsanIgnoreWritesBegin()
435 # define TsanIgnoreWritesEnd()
440 #if __has_attribute(no_sanitize)
441 #define LLVM_NO_SANITIZE(KIND) __attribute__((no_sanitize(KIND)))
443 #define LLVM_NO_SANITIZE(KIND)
449 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
450 #define LLVM_DUMP_METHOD LLVM_ATTRIBUTE_NOINLINE LLVM_ATTRIBUTE_USED
452 #define LLVM_DUMP_METHOD LLVM_ATTRIBUTE_NOINLINE
460 #if defined(_MSC_VER)
461 #define LLVM_PRETTY_FUNCTION __FUNCSIG__
462 #elif defined(__GNUC__) || defined(__clang__)
463 #define LLVM_PRETTY_FUNCTION __PRETTY_FUNCTION__
465 #define LLVM_PRETTY_FUNCTION __func__
480 #if LLVM_ENABLE_THREADS
481 #if __has_feature(cxx_thread_local)
482 #define LLVM_THREAD_LOCAL thread_local
483 #elif defined(_MSC_VER)
485 #define LLVM_THREAD_LOCAL __declspec(thread)
489 #define LLVM_THREAD_LOCAL __thread
491 #else // !LLVM_ENABLE_THREADS
494 #define LLVM_THREAD_LOCAL
dot regions Print regions of function to dot file(with no function bodies)"