LLVM API Documentation
Go to the documentation of this file.
15 #ifndef LLVM_SUPPORT_COMPILER_H
16 #define LLVM_SUPPORT_COMPILER_H
18 #include "llvm/Config/llvm-config.h"
21 # define __has_feature(x) 0
24 #ifndef __has_attribute
25 # define __has_attribute(x) 0
29 # define __has_builtin(x) 0
35 # if defined(__GNUC__) && defined(__GNUC_MINOR__)
36 # define __GNUC_PREREQ(maj, min) \
37 ((__GNUC__ << 16) + __GNUC_MINOR__ >= ((maj) << 16) + (min))
39 # define __GNUC_PREREQ(maj, min) 0
46 #if (__has_feature(cxx_rvalue_references) \
47 || defined(__GXX_EXPERIMENTAL_CXX0X__) \
48 || (defined(_MSC_VER) && _MSC_VER >= 1600))
49 #define LLVM_HAS_RVALUE_REFERENCES 1
51 #define LLVM_HAS_RVALUE_REFERENCES 0
60 #if __has_feature(cxx_rvalue_references)
61 #define LLVM_HAS_RVALUE_REFERENCE_THIS 1
63 #define LLVM_HAS_RVALUE_REFERENCE_THIS 0
75 #if defined(__GXX_EXPERIMENTAL_CXX0X__) \
76 || (defined(_MSC_VER) && _MSC_VER >= 1700)
77 #define LLVM_HAS_CXX11_TYPETRAITS 1
79 #define LLVM_HAS_CXX11_TYPETRAITS 0
86 #if defined(__GXX_EXPERIMENTAL_CXX0X__) \
87 || (defined(_MSC_VER) && _MSC_VER >= 1700)
88 #define LLVM_HAS_CXX11_STDLIB 1
90 #define LLVM_HAS_CXX11_STDLIB 0
97 #if __has_feature(cxx_variadic_templates)
98 # define LLVM_HAS_VARIADIC_TEMPLATES 1
100 # define LLVM_HAS_VARIADIC_TEMPLATES 0
105 #if LLVM_HAS_RVALUE_REFERENCES
106 #define llvm_move(value) (::std::move(value))
108 #define llvm_move(value) (value)
115 #if LLVM_HAS_RVALUE_REFERENCE_THIS
116 #define LLVM_LVALUE_FUNCTION &
118 #define LLVM_LVALUE_FUNCTION
132 #if (__has_feature(cxx_deleted_functions) \
133 || defined(__GXX_EXPERIMENTAL_CXX0X__))
135 #define LLVM_DELETED_FUNCTION = delete
137 #define LLVM_DELETED_FUNCTION
142 #if __has_feature(cxx_override_control) \
143 || (defined(_MSC_VER) && _MSC_VER >= 1700)
144 #define LLVM_FINAL final
151 #if __has_feature(cxx_override_control) \
152 || (defined(_MSC_VER) && _MSC_VER >= 1700)
153 #define LLVM_OVERRIDE override
155 #define LLVM_OVERRIDE
158 #if __has_feature(cxx_constexpr) || defined(__GXX_EXPERIMENTAL_CXX0X__)
159 # define LLVM_CONSTEXPR constexpr
161 # define LLVM_CONSTEXPR
169 #if (__has_attribute(visibility) || __GNUC_PREREQ(4, 0)) && \
170 !defined(__MINGW32__) && !defined(__CYGWIN__) && !defined(LLVM_ON_WIN32)
171 #define LLVM_LIBRARY_VISIBILITY __attribute__ ((visibility("hidden")))
173 #define LLVM_LIBRARY_VISIBILITY
176 #if __has_attribute(used) || __GNUC_PREREQ(3, 1)
177 #define LLVM_ATTRIBUTE_USED __attribute__((__used__))
179 #define LLVM_ATTRIBUTE_USED
182 #if __has_attribute(warn_unused_result) || __GNUC_PREREQ(3, 4)
183 #define LLVM_ATTRIBUTE_UNUSED_RESULT __attribute__((__warn_unused_result__))
185 #define LLVM_ATTRIBUTE_UNUSED_RESULT
196 #if __has_attribute(unused) || __GNUC_PREREQ(3, 1)
197 #define LLVM_ATTRIBUTE_UNUSED __attribute__((__unused__))
199 #define LLVM_ATTRIBUTE_UNUSED
203 #if (__has_attribute(weak) || __GNUC_PREREQ(4, 0)) && \
204 (!defined(__MINGW32__) && !defined(__CYGWIN__) && !defined(LLVM_ON_WIN32))
205 #define LLVM_ATTRIBUTE_WEAK __attribute__((__weak__))
207 #define LLVM_ATTRIBUTE_WEAK
212 #if defined(__clang__) || defined(__GNUC__)
214 #define LLVM_READNONE __attribute__((__const__))
216 #define LLVM_READNONE
219 #if __has_attribute(pure) || defined(__GNUC__)
221 #define LLVM_READONLY __attribute__((__pure__))
223 #define LLVM_READONLY
226 #if __has_builtin(__builtin_expect) || __GNUC_PREREQ(4, 0)
227 #define LLVM_LIKELY(EXPR) __builtin_expect((bool)(EXPR), true)
228 #define LLVM_UNLIKELY(EXPR) __builtin_expect((bool)(EXPR), false)
230 #define LLVM_LIKELY(EXPR) (EXPR)
231 #define LLVM_UNLIKELY(EXPR) (EXPR)
240 #define EXTERN_TEMPLATE_INSTANTIATION(X) __extension__ extern template X
241 #define TEMPLATE_INSTANTIATION(X) template X
243 #define EXTERN_TEMPLATE_INSTANTIATION(X)
244 #define TEMPLATE_INSTANTIATION(X)
249 #if __has_attribute(noinline) || __GNUC_PREREQ(3, 4)
250 #define LLVM_ATTRIBUTE_NOINLINE __attribute__((noinline))
251 #elif defined(_MSC_VER)
252 #define LLVM_ATTRIBUTE_NOINLINE __declspec(noinline)
254 #define LLVM_ATTRIBUTE_NOINLINE
261 #if __has_attribute(always_inline) || __GNUC_PREREQ(4, 0)
262 #define LLVM_ATTRIBUTE_ALWAYS_INLINE inline __attribute__((always_inline))
263 #elif defined(_MSC_VER)
264 #define LLVM_ATTRIBUTE_ALWAYS_INLINE __forceinline
266 #define LLVM_ATTRIBUTE_ALWAYS_INLINE
270 #define LLVM_ATTRIBUTE_NORETURN __attribute__((noreturn))
271 #elif defined(_MSC_VER)
272 #define LLVM_ATTRIBUTE_NORETURN __declspec(noreturn)
274 #define LLVM_ATTRIBUTE_NORETURN
280 #define LLVM_EXTENSION __extension__
282 #define LLVM_EXTENSION
286 #if __has_feature(attribute_deprecated_with_message)
287 # define LLVM_ATTRIBUTE_DEPRECATED(decl, message) \
288 decl __attribute__((deprecated(message)))
289 #elif defined(__GNUC__)
290 # define LLVM_ATTRIBUTE_DEPRECATED(decl, message) \
291 decl __attribute__((deprecated))
292 #elif defined(_MSC_VER)
293 # define LLVM_ATTRIBUTE_DEPRECATED(decl, message) \
294 __declspec(deprecated(message)) decl
296 # define LLVM_ATTRIBUTE_DEPRECATED(decl, message) \
303 #if __has_builtin(__builtin_unreachable) || __GNUC_PREREQ(4, 5)
304 # define LLVM_BUILTIN_UNREACHABLE __builtin_unreachable()
305 #elif defined(_MSC_VER)
306 # define LLVM_BUILTIN_UNREACHABLE __assume(false)
311 #if __has_builtin(__builtin_trap) || __GNUC_PREREQ(4, 3)
312 # define LLVM_BUILTIN_TRAP __builtin_trap()
314 # define LLVM_BUILTIN_TRAP *(volatile int*)0x11 = 0
319 #if __has_builtin(__builtin_assume_aligned) && __GNUC_PREREQ(4, 7)
320 # define LLVM_ASSUME_ALIGNED(p, a) __builtin_assume_aligned(p, a)
321 #elif defined(LLVM_BUILTIN_UNREACHABLE)
323 # define LLVM_ASSUME_ALIGNED(p, a) \
324 (((uintptr_t(p) % (a)) == 0) ? (p) : (LLVM_BUILTIN_UNREACHABLE, (p)))
326 # define LLVM_ASSUME_ALIGNED(p, a) (p)
332 #if defined(_MSC_VER)
333 # define LLVM_FUNCTION_NAME __FUNCTION__
335 # define LLVM_FUNCTION_NAME __func__
338 #if defined(HAVE_SANITIZER_MSAN_INTERFACE_H)
339 # include <sanitizer/msan_interface.h>
341 # define __msan_allocated_memory(p, size)
342 # define __msan_unpoison(p, size)
347 #if __has_feature(memory_sanitizer)
348 # define LLVM_MEMORY_SANITIZER_BUILD 1
350 # define LLVM_MEMORY_SANITIZER_BUILD 0
355 #if __has_feature(address_sanitizer) || defined(__SANITIZE_ADDRESS__)
356 # define LLVM_ADDRESS_SANITIZER_BUILD 1
358 # define LLVM_ADDRESS_SANITIZER_BUILD 0
366 #if defined(_M_AMD64) || defined(_M_IX86) || defined(__amd64) || \
367 defined(__amd64__) || defined(__x86_64) || defined(__x86_64__) || \
368 defined(_X86_) || defined(__i386) || defined(__i386__)
369 # define LLVM_IS_UNALIGNED_ACCESS_FAST 1
371 # define LLVM_IS_UNALIGNED_ACCESS_FAST 0
377 #if (__has_feature(cxx_explicit_conversions) \
378 || defined(__GXX_EXPERIMENTAL_CXX0X__))
379 #define LLVM_EXPLICIT explicit
381 #define LLVM_EXPLICIT
386 #if __has_feature(cxx_static_assert)
387 # define LLVM_STATIC_ASSERT(expr, msg) static_assert(expr, msg)
388 #elif __has_feature(c_static_assert)
389 # define LLVM_STATIC_ASSERT(expr, msg) _Static_assert(expr, msg)
391 # define LLVM_STATIC_ASSERT(expr, msg)
398 #if __has_feature(cxx_strong_enums)
399 # define LLVM_ENUM_INT_TYPE(intty) : intty
400 #elif defined(_MSC_VER) && _MSC_VER >= 1600 // Added in MSVC 2010.
401 # define LLVM_ENUM_INT_TYPE(intty) : intty
403 # define LLVM_ENUM_INT_TYPE(intty)
408 #if __has_feature(cxx_generalized_initializers)
409 #define LLVM_HAS_INITIALIZER_LISTS 1
411 #define LLVM_HAS_INITIALIZER_LISTS 0