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(used) || LLVM_GNUC_PREREQ(3, 1, 0)
115 #define LLVM_ATTRIBUTE_USED __attribute__((__used__))
117 #define LLVM_ATTRIBUTE_USED
121 #if __cplusplus > 201402L && __has_cpp_attribute(nodiscard)
122 #define LLVM_NODISCARD [[nodiscard]]
126 #define LLVM_NODISCARD
127 #elif __has_cpp_attribute(clang::warn_unused_result)
128 #define LLVM_NODISCARD [[clang::warn_unused_result]]
130 #define LLVM_NODISCARD
141 #if __has_attribute(unused) || LLVM_GNUC_PREREQ(3, 1, 0)
142 #define LLVM_ATTRIBUTE_UNUSED __attribute__((__unused__))
144 #define LLVM_ATTRIBUTE_UNUSED
148 #if (__has_attribute(weak) || LLVM_GNUC_PREREQ(4, 0, 0)) && \
149 (!defined(__MINGW32__) && !defined(__CYGWIN__) && !defined(LLVM_ON_WIN32))
150 #define LLVM_ATTRIBUTE_WEAK __attribute__((__weak__))
152 #define LLVM_ATTRIBUTE_WEAK
157 #if defined(__clang__) || defined(__GNUC__)
159 #define LLVM_READNONE __attribute__((__const__))
161 #define LLVM_READNONE
164 #if __has_attribute(pure) || defined(__GNUC__)
166 #define LLVM_READONLY __attribute__((__pure__))
168 #define LLVM_READONLY
171 #if __has_builtin(__builtin_expect) || LLVM_GNUC_PREREQ(4, 0, 0)
172 #define LLVM_LIKELY(EXPR) __builtin_expect((bool)(EXPR), true)
173 #define LLVM_UNLIKELY(EXPR) __builtin_expect((bool)(EXPR), false)
175 #define LLVM_LIKELY(EXPR) (EXPR)
176 #define LLVM_UNLIKELY(EXPR) (EXPR)
181 #if __has_attribute(noinline) || LLVM_GNUC_PREREQ(3, 4, 0)
182 #define LLVM_ATTRIBUTE_NOINLINE __attribute__((noinline))
183 #elif defined(_MSC_VER)
184 #define LLVM_ATTRIBUTE_NOINLINE __declspec(noinline)
186 #define LLVM_ATTRIBUTE_NOINLINE
193 #if __has_attribute(always_inline) || LLVM_GNUC_PREREQ(4, 0, 0)
194 #define LLVM_ATTRIBUTE_ALWAYS_INLINE __attribute__((always_inline))
195 #elif defined(_MSC_VER)
196 #define LLVM_ATTRIBUTE_ALWAYS_INLINE __forceinline
198 #define LLVM_ATTRIBUTE_ALWAYS_INLINE
202 #define LLVM_ATTRIBUTE_NORETURN __attribute__((noreturn))
203 #elif defined(_MSC_VER)
204 #define LLVM_ATTRIBUTE_NORETURN __declspec(noreturn)
206 #define LLVM_ATTRIBUTE_NORETURN
209 #if __has_attribute(returns_nonnull) || LLVM_GNUC_PREREQ(4, 9, 0)
210 #define LLVM_ATTRIBUTE_RETURNS_NONNULL __attribute__((returns_nonnull))
211 #elif defined(_MSC_VER)
212 #define LLVM_ATTRIBUTE_RETURNS_NONNULL _Ret_notnull_
214 #define LLVM_ATTRIBUTE_RETURNS_NONNULL
220 #define LLVM_ATTRIBUTE_RETURNS_NOALIAS __attribute__((__malloc__))
221 #elif defined(_MSC_VER)
222 #define LLVM_ATTRIBUTE_RETURNS_NOALIAS __declspec(restrict)
224 #define LLVM_ATTRIBUTE_RETURNS_NOALIAS
228 #if __cplusplus > 201402L && __has_cpp_attribute(fallthrough)
229 #define LLVM_FALLTHROUGH [[fallthrough]]
230 #elif __has_cpp_attribute(gnu::fallthrough)
231 #define LLVM_FALLTHROUGH [[gnu::fallthrough]]
235 #define LLVM_FALLTHROUGH
236 #elif __has_cpp_attribute(clang::fallthrough)
237 #define LLVM_FALLTHROUGH [[clang::fallthrough]]
239 #define LLVM_FALLTHROUGH
245 #define LLVM_EXTENSION __extension__
247 #define LLVM_EXTENSION
251 #if __has_feature(attribute_deprecated_with_message)
252 # define LLVM_ATTRIBUTE_DEPRECATED(decl, message) \
253 decl __attribute__((deprecated(message)))
254 #elif defined(__GNUC__)
255 # define LLVM_ATTRIBUTE_DEPRECATED(decl, message) \
256 decl __attribute__((deprecated))
257 #elif defined(_MSC_VER)
258 # define LLVM_ATTRIBUTE_DEPRECATED(decl, message) \
259 __declspec(deprecated(message)) decl
261 # define LLVM_ATTRIBUTE_DEPRECATED(decl, message) \
268 #if __has_builtin(__builtin_unreachable) || LLVM_GNUC_PREREQ(4, 5, 0)
269 # define LLVM_BUILTIN_UNREACHABLE __builtin_unreachable()
270 #elif defined(_MSC_VER)
271 # define LLVM_BUILTIN_UNREACHABLE __assume(false)
276 #if __has_builtin(__builtin_trap) || LLVM_GNUC_PREREQ(4, 3, 0)
277 # define LLVM_BUILTIN_TRAP __builtin_trap()
278 #elif defined(_MSC_VER)
283 # define LLVM_BUILTIN_TRAP __debugbreak()
285 # define LLVM_BUILTIN_TRAP *(volatile int*)0x11 = 0
291 #if __has_builtin(__builtin_debugtrap)
292 # define LLVM_BUILTIN_DEBUGTRAP __builtin_debugtrap()
293 #elif defined(_MSC_VER)
297 # define LLVM_BUILTIN_DEBUGTRAP __debugbreak()
302 # define LLVM_BUILTIN_DEBUGTRAP
307 #if __has_builtin(__builtin_assume_aligned) || LLVM_GNUC_PREREQ(4, 7, 0)
308 # define LLVM_ASSUME_ALIGNED(p, a) __builtin_assume_aligned(p, a)
309 #elif defined(LLVM_BUILTIN_UNREACHABLE)
311 # define LLVM_ASSUME_ALIGNED(p, a) \
312 (((uintptr_t(p) % (a)) == 0) ? (p) : (LLVM_BUILTIN_UNREACHABLE, (p)))
314 # define LLVM_ASSUME_ALIGNED(p, a) (p)
319 #if __GNUC__ && !__has_feature(cxx_alignas) && !LLVM_GNUC_PREREQ(4, 8, 1)
320 # define LLVM_ALIGNAS(x) __attribute__((aligned(x)))
322 # define LLVM_ALIGNAS(x) alignas(x)
344 # define LLVM_PACKED(d) __pragma(pack(push, 1)) d __pragma(pack(pop))
345 # define LLVM_PACKED_START __pragma(pack(push, 1))
346 # define LLVM_PACKED_END __pragma(pack(pop))
348 # define LLVM_PACKED(d) d __attribute__((packed))
349 # define LLVM_PACKED_START _Pragma("pack(push, 1)")
350 # define LLVM_PACKED_END _Pragma("pack(pop)")
357 #ifdef __SIZEOF_POINTER__
358 # define LLVM_PTR_SIZE __SIZEOF_POINTER__
359 #elif defined(_WIN64)
360 # define LLVM_PTR_SIZE 8
361 #elif defined(_WIN32)
362 # define LLVM_PTR_SIZE 4
363 #elif defined(_MSC_VER)
364 # error "could not determine LLVM_PTR_SIZE as a constant int for MSVC"
366 # define LLVM_PTR_SIZE sizeof(void *)
371 #if __has_feature(memory_sanitizer)
372 # define LLVM_MEMORY_SANITIZER_BUILD 1
373 # include <sanitizer/msan_interface.h>
375 # define LLVM_MEMORY_SANITIZER_BUILD 0
376 # define __msan_allocated_memory(p, size)
377 # define __msan_unpoison(p, size)
382 #if __has_feature(address_sanitizer) || defined(__SANITIZE_ADDRESS__)
383 # define LLVM_ADDRESS_SANITIZER_BUILD 1
384 # include <sanitizer/asan_interface.h>
386 # define LLVM_ADDRESS_SANITIZER_BUILD 0
387 # define __asan_poison_memory_region(p, size)
388 # define __asan_unpoison_memory_region(p, size)
393 #if __has_feature(thread_sanitizer) || defined(__SANITIZE_THREAD__)
394 # define LLVM_THREAD_SANITIZER_BUILD 1
396 # define LLVM_THREAD_SANITIZER_BUILD 0
399 #if LLVM_THREAD_SANITIZER_BUILD
406 void AnnotateHappensAfter(
const char *
file,
int line,
const volatile void *cv);
407 void AnnotateHappensBefore(
const char *file,
int line,
const volatile void *cv);
408 void AnnotateIgnoreWritesBegin(
const char *file,
int line);
409 void AnnotateIgnoreWritesEnd(
const char *file,
int line);
417 # define TsanHappensBefore(cv) AnnotateHappensBefore(__FILE__, __LINE__, cv)
420 # define TsanHappensAfter(cv) AnnotateHappensAfter(__FILE__, __LINE__, cv)
423 # define TsanIgnoreWritesBegin() AnnotateIgnoreWritesBegin(__FILE__, __LINE__)
426 # define TsanIgnoreWritesEnd() AnnotateIgnoreWritesEnd(__FILE__, __LINE__)
428 # define TsanHappensBefore(cv)
429 # define TsanHappensAfter(cv)
430 # define TsanIgnoreWritesBegin()
431 # define TsanIgnoreWritesEnd()
436 #if __has_attribute(no_sanitize)
437 #define LLVM_NO_SANITIZE(KIND) __attribute__((no_sanitize(KIND)))
439 #define LLVM_NO_SANITIZE(KIND)
448 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
449 #define LLVM_DUMP_METHOD LLVM_ATTRIBUTE_NOINLINE LLVM_ATTRIBUTE_USED
451 #define LLVM_DUMP_METHOD LLVM_ATTRIBUTE_NOINLINE
459 #if defined(_MSC_VER)
460 #define LLVM_PRETTY_FUNCTION __FUNCSIG__
461 #elif defined(__GNUC__) || defined(__clang__)
462 #define LLVM_PRETTY_FUNCTION __PRETTY_FUNCTION__
464 #define LLVM_PRETTY_FUNCTION __func__
479 #if LLVM_ENABLE_THREADS
480 #if __has_feature(cxx_thread_local)
481 #define LLVM_THREAD_LOCAL thread_local
482 #elif defined(_MSC_VER)
484 #define LLVM_THREAD_LOCAL __declspec(thread)
488 #define LLVM_THREAD_LOCAL __thread
490 #else // !LLVM_ENABLE_THREADS
493 #define LLVM_THREAD_LOCAL
498 #if __has_feature(cxx_exceptions)
499 #define LLVM_ENABLE_EXCEPTIONS 1
500 #elif defined(__GNUC__) && defined(__EXCEPTIONS)
501 #define LLVM_ENABLE_EXCEPTIONS 1
502 #elif defined(_MSC_VER) && defined(_CPPUNWIND)
503 #define LLVM_ENABLE_EXCEPTIONS 1
dot regions Print regions of function to dot file(with no function bodies)"