15 #ifndef LLVM_SUPPORT_COMPILER_H 16 #define LLVM_SUPPORT_COMPILER_H 18 #include "llvm/Config/llvm-config.h" 30 # define __has_feature(x) 0 33 #ifndef __has_extension 34 # define __has_extension(x) 0 37 #ifndef __has_attribute 38 # define __has_attribute(x) 0 42 # define __has_builtin(x) 0 47 #ifndef LLVM_HAS_CPP_ATTRIBUTE 48 #if defined(__cplusplus) && defined(__has_cpp_attribute) 49 # define LLVM_HAS_CPP_ATTRIBUTE(x) __has_cpp_attribute(x) 51 # define LLVM_HAS_CPP_ATTRIBUTE(x) 0 58 #ifndef LLVM_GNUC_PREREQ 59 # if defined(__GNUC__) && defined(__GNUC_MINOR__) && defined(__GNUC_PATCHLEVEL__) 60 # define LLVM_GNUC_PREREQ(maj, min, patch) \ 61 ((__GNUC__ << 20) + (__GNUC_MINOR__ << 10) + __GNUC_PATCHLEVEL__ >= \ 62 ((maj) << 20) + ((min) << 10) + (patch)) 63 # elif defined(__GNUC__) && defined(__GNUC_MINOR__) 64 # define LLVM_GNUC_PREREQ(maj, min, patch) \ 65 ((__GNUC__ << 20) + (__GNUC_MINOR__ << 10) >= ((maj) << 20) + ((min) << 10)) 67 # define LLVM_GNUC_PREREQ(maj, min, patch) 0 84 #define LLVM_MSC_PREREQ(version) (_MSC_VER >= (version)) 87 #if !LLVM_MSC_PREREQ(1910) 88 #error LLVM requires at least MSVC 2017. 92 #define LLVM_MSC_PREREQ(version) 0 99 #if __has_feature(cxx_rvalue_references) || LLVM_GNUC_PREREQ(4, 8, 1) 100 #define LLVM_HAS_RVALUE_REFERENCE_THIS 1 102 #define LLVM_HAS_RVALUE_REFERENCE_THIS 0 109 #if LLVM_HAS_RVALUE_REFERENCE_THIS 110 #define LLVM_LVALUE_FUNCTION & 112 #define LLVM_LVALUE_FUNCTION 124 #if (__has_attribute(visibility) || LLVM_GNUC_PREREQ(4, 0, 0)) && \ 125 !defined(__MINGW32__) && !defined(__CYGWIN__) && !defined(_WIN32) 126 #define LLVM_LIBRARY_VISIBILITY __attribute__ ((visibility("hidden"))) 127 #define LLVM_EXTERNAL_VISIBILITY __attribute__ ((visibility("default"))) 129 #define LLVM_LIBRARY_VISIBILITY 130 #define LLVM_EXTERNAL_VISIBILITY 133 #if defined(__GNUC__) 134 #define LLVM_PREFETCH(addr, rw, locality) __builtin_prefetch(addr, rw, locality) 136 #define LLVM_PREFETCH(addr, rw, locality) 139 #if __has_attribute(used) || LLVM_GNUC_PREREQ(3, 1, 0) 140 #define LLVM_ATTRIBUTE_USED __attribute__((__used__)) 142 #define LLVM_ATTRIBUTE_USED 148 #if __cplusplus > 201402L && LLVM_HAS_CPP_ATTRIBUTE(nodiscard) 149 #define LLVM_NODISCARD [[nodiscard]] 150 #elif LLVM_HAS_CPP_ATTRIBUTE(clang::warn_unused_result) 151 #define LLVM_NODISCARD [[clang::warn_unused_result]] 156 #elif defined(__GNUC__) && LLVM_HAS_CPP_ATTRIBUTE(nodiscard) 157 #define LLVM_NODISCARD [[nodiscard]] 159 #define LLVM_NODISCARD 169 #if LLVM_HAS_CPP_ATTRIBUTE(clang::reinitializes) 170 #define LLVM_ATTRIBUTE_REINITIALIZES [[clang::reinitializes]] 172 #define LLVM_ATTRIBUTE_REINITIALIZES 183 #if __has_attribute(unused) || LLVM_GNUC_PREREQ(3, 1, 0) 184 #define LLVM_ATTRIBUTE_UNUSED __attribute__((__unused__)) 186 #define LLVM_ATTRIBUTE_UNUSED 190 #if (__has_attribute(weak) || LLVM_GNUC_PREREQ(4, 0, 0)) && \ 191 (!defined(__MINGW32__) && !defined(__CYGWIN__) && !defined(_WIN32)) 192 #define LLVM_ATTRIBUTE_WEAK __attribute__((__weak__)) 194 #define LLVM_ATTRIBUTE_WEAK 199 #if defined(__clang__) || defined(__GNUC__) 201 #define LLVM_READNONE __attribute__((__const__)) 203 #define LLVM_READNONE 206 #if __has_attribute(pure) || defined(__GNUC__) 208 #define LLVM_READONLY __attribute__((__pure__)) 210 #define LLVM_READONLY 213 #if __has_builtin(__builtin_expect) || LLVM_GNUC_PREREQ(4, 0, 0) 214 #define LLVM_LIKELY(EXPR) __builtin_expect((bool)(EXPR), true) 215 #define LLVM_UNLIKELY(EXPR) __builtin_expect((bool)(EXPR), false) 217 #define LLVM_LIKELY(EXPR) (EXPR) 218 #define LLVM_UNLIKELY(EXPR) (EXPR) 223 #if __has_attribute(noinline) || LLVM_GNUC_PREREQ(3, 4, 0) 224 #define LLVM_ATTRIBUTE_NOINLINE __attribute__((noinline)) 225 #elif defined(_MSC_VER) 226 #define LLVM_ATTRIBUTE_NOINLINE __declspec(noinline) 228 #define LLVM_ATTRIBUTE_NOINLINE 235 #if __has_attribute(always_inline) || LLVM_GNUC_PREREQ(4, 0, 0) 236 #define LLVM_ATTRIBUTE_ALWAYS_INLINE __attribute__((always_inline)) 237 #elif defined(_MSC_VER) 238 #define LLVM_ATTRIBUTE_ALWAYS_INLINE __forceinline 240 #define LLVM_ATTRIBUTE_ALWAYS_INLINE 244 #define LLVM_ATTRIBUTE_NORETURN __attribute__((noreturn)) 245 #elif defined(_MSC_VER) 246 #define LLVM_ATTRIBUTE_NORETURN __declspec(noreturn) 248 #define LLVM_ATTRIBUTE_NORETURN 251 #if __has_attribute(returns_nonnull) || LLVM_GNUC_PREREQ(4, 9, 0) 252 #define LLVM_ATTRIBUTE_RETURNS_NONNULL __attribute__((returns_nonnull)) 253 #elif defined(_MSC_VER) 254 #define LLVM_ATTRIBUTE_RETURNS_NONNULL _Ret_notnull_ 256 #define LLVM_ATTRIBUTE_RETURNS_NONNULL 262 #define LLVM_ATTRIBUTE_RETURNS_NOALIAS __attribute__((__malloc__)) 263 #elif defined(_MSC_VER) 264 #define LLVM_ATTRIBUTE_RETURNS_NOALIAS __declspec(restrict) 266 #define LLVM_ATTRIBUTE_RETURNS_NOALIAS 270 #if __cplusplus > 201402L && LLVM_HAS_CPP_ATTRIBUTE(fallthrough) 271 #define LLVM_FALLTHROUGH [[fallthrough]] 272 #elif LLVM_HAS_CPP_ATTRIBUTE(gnu::fallthrough) 273 #define LLVM_FALLTHROUGH [[gnu::fallthrough]] 274 #elif __has_attribute(fallthrough) 275 #define LLVM_FALLTHROUGH __attribute__((fallthrough)) 276 #elif LLVM_HAS_CPP_ATTRIBUTE(clang::fallthrough) 277 #define LLVM_FALLTHROUGH [[clang::fallthrough]] 279 #define LLVM_FALLTHROUGH 284 #if LLVM_HAS_CPP_ATTRIBUTE(clang::require_constant_initialization) 285 #define LLVM_REQUIRE_CONSTANT_INITIALIZATION \ 286 [[clang::require_constant_initialization]] 288 #define LLVM_REQUIRE_CONSTANT_INITIALIZATION 294 #define LLVM_EXTENSION __extension__ 296 #define LLVM_EXTENSION 300 #if __has_feature(attribute_deprecated_with_message) 301 # define LLVM_ATTRIBUTE_DEPRECATED(decl, message) \ 302 decl __attribute__((deprecated(message))) 303 #elif defined(__GNUC__) 304 # define LLVM_ATTRIBUTE_DEPRECATED(decl, message) \ 305 decl __attribute__((deprecated)) 306 #elif defined(_MSC_VER) 307 # define LLVM_ATTRIBUTE_DEPRECATED(decl, message) \ 308 __declspec(deprecated(message)) decl 310 # define LLVM_ATTRIBUTE_DEPRECATED(decl, message) \ 317 #if __has_builtin(__builtin_unreachable) || LLVM_GNUC_PREREQ(4, 5, 0) 318 # define LLVM_BUILTIN_UNREACHABLE __builtin_unreachable() 319 #elif defined(_MSC_VER) 320 # define LLVM_BUILTIN_UNREACHABLE __assume(false) 325 #if __has_builtin(__builtin_trap) || LLVM_GNUC_PREREQ(4, 3, 0) 326 # define LLVM_BUILTIN_TRAP __builtin_trap() 327 #elif defined(_MSC_VER) 332 # define LLVM_BUILTIN_TRAP __debugbreak() 334 # define LLVM_BUILTIN_TRAP *(volatile int*)0x11 = 0 340 #if __has_builtin(__builtin_debugtrap) 341 # define LLVM_BUILTIN_DEBUGTRAP __builtin_debugtrap() 342 #elif defined(_MSC_VER) 346 # define LLVM_BUILTIN_DEBUGTRAP __debugbreak() 351 # define LLVM_BUILTIN_DEBUGTRAP 356 #if __has_builtin(__builtin_assume_aligned) || LLVM_GNUC_PREREQ(4, 7, 0) 357 # define LLVM_ASSUME_ALIGNED(p, a) __builtin_assume_aligned(p, a) 358 #elif defined(LLVM_BUILTIN_UNREACHABLE) 360 # define LLVM_ASSUME_ALIGNED(p, a) \ 361 (((uintptr_t(p) % (a)) == 0) ? (p) : (LLVM_BUILTIN_UNREACHABLE, (p))) 363 # define LLVM_ASSUME_ALIGNED(p, a) (p) 385 # define LLVM_PACKED(d) __pragma(pack(push, 1)) d __pragma(pack(pop)) 386 # define LLVM_PACKED_START __pragma(pack(push, 1)) 387 # define LLVM_PACKED_END __pragma(pack(pop)) 389 # define LLVM_PACKED(d) d __attribute__((packed)) 390 # define LLVM_PACKED_START _Pragma("pack(push, 1)") 391 # define LLVM_PACKED_END _Pragma("pack(pop)") 398 #ifdef __SIZEOF_POINTER__ 399 # define LLVM_PTR_SIZE __SIZEOF_POINTER__ 400 #elif defined(_WIN64) 401 # define LLVM_PTR_SIZE 8 402 #elif defined(_WIN32) 403 # define LLVM_PTR_SIZE 4 404 #elif defined(_MSC_VER) 405 # error "could not determine LLVM_PTR_SIZE as a constant int for MSVC" 407 # define LLVM_PTR_SIZE sizeof(void *) 412 #if __has_feature(memory_sanitizer) 413 # define LLVM_MEMORY_SANITIZER_BUILD 1 414 # include <sanitizer/msan_interface.h> 415 # define LLVM_NO_SANITIZE_MEMORY_ATTRIBUTE __attribute__((no_sanitize_memory)) 417 # define LLVM_MEMORY_SANITIZER_BUILD 0 418 # define __msan_allocated_memory(p, size) 419 # define __msan_unpoison(p, size) 420 # define LLVM_NO_SANITIZE_MEMORY_ATTRIBUTE 425 #if __has_feature(address_sanitizer) || defined(__SANITIZE_ADDRESS__) 426 # define LLVM_ADDRESS_SANITIZER_BUILD 1 427 # include <sanitizer/asan_interface.h> 429 # define LLVM_ADDRESS_SANITIZER_BUILD 0 430 # define __asan_poison_memory_region(p, size) 431 # define __asan_unpoison_memory_region(p, size) 436 #if __has_feature(thread_sanitizer) || defined(__SANITIZE_THREAD__) 437 # define LLVM_THREAD_SANITIZER_BUILD 1 439 # define LLVM_THREAD_SANITIZER_BUILD 0 442 #if LLVM_THREAD_SANITIZER_BUILD 449 void AnnotateHappensAfter(
const char *
file,
int line,
const volatile void *cv);
450 void AnnotateHappensBefore(
const char *file,
int line,
const volatile void *cv);
451 void AnnotateIgnoreWritesBegin(
const char *file,
int line);
452 void AnnotateIgnoreWritesEnd(
const char *file,
int line);
460 # define TsanHappensBefore(cv) AnnotateHappensBefore(__FILE__, __LINE__, cv) 463 # define TsanHappensAfter(cv) AnnotateHappensAfter(__FILE__, __LINE__, cv) 466 # define TsanIgnoreWritesBegin() AnnotateIgnoreWritesBegin(__FILE__, __LINE__) 469 # define TsanIgnoreWritesEnd() AnnotateIgnoreWritesEnd(__FILE__, __LINE__) 471 # define TsanHappensBefore(cv) 472 # define TsanHappensAfter(cv) 473 # define TsanIgnoreWritesBegin() 474 # define TsanIgnoreWritesEnd() 479 #if __has_attribute(no_sanitize) 480 #define LLVM_NO_SANITIZE(KIND) __attribute__((no_sanitize(KIND))) 482 #define LLVM_NO_SANITIZE(KIND) 491 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP) 492 #define LLVM_DUMP_METHOD LLVM_ATTRIBUTE_NOINLINE LLVM_ATTRIBUTE_USED 494 #define LLVM_DUMP_METHOD LLVM_ATTRIBUTE_NOINLINE 502 #if defined(_MSC_VER) 503 #define LLVM_PRETTY_FUNCTION __FUNCSIG__ 504 #elif defined(__GNUC__) || defined(__clang__) 505 #define LLVM_PRETTY_FUNCTION __PRETTY_FUNCTION__ 507 #define LLVM_PRETTY_FUNCTION __func__ 521 #if LLVM_ENABLE_THREADS 522 #if __has_feature(cxx_thread_local) || defined(_MSC_VER) 523 #define LLVM_THREAD_LOCAL thread_local 527 #define LLVM_THREAD_LOCAL __thread 529 #else // !LLVM_ENABLE_THREADS 532 #define LLVM_THREAD_LOCAL 537 #if __has_feature(cxx_exceptions) 538 #define LLVM_ENABLE_EXCEPTIONS 1 539 #elif defined(__GNUC__) && defined(__EXCEPTIONS) 540 #define LLVM_ENABLE_EXCEPTIONS 1 541 #elif defined(_MSC_VER) && defined(_CPPUNWIND) 542 #define LLVM_ENABLE_EXCEPTIONS 1 557 inline void *allocate_buffer(
size_t Size,
size_t Alignment) {
558 return ::operator
new(Size
559 #ifdef __cpp_aligned_new 561 std::align_val_t(Alignment)
573 inline void deallocate_buffer(
void *Ptr,
size_t Size,
size_t Alignment) {
574 ::operator
delete(Ptr
575 #ifdef __cpp_sized_deallocation 579 #ifdef __cpp_aligned_new 581 std::align_val_t(Alignment)
588 #endif // __cplusplus *ViewGraph Emit a dot run run gv on the postscript file
This class represents lattice values for constants.