1 //===-- llvm/Support/Compiler.h - Compiler abstraction support --*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file defines several macros, based on the current compiler. This allows
11 // use of compiler-specific features in a way that remains portable.
13 //===----------------------------------------------------------------------===//
15 #ifndef LLVM_SUPPORT_COMPILER_H
16 #define LLVM_SUPPORT_COMPILER_H
19 # define __has_feature(x) 0
22 /// LLVM_LIBRARY_VISIBILITY - If a class marked with this attribute is linked
23 /// into a shared library, then the class should be private to the library and
24 /// not accessible from outside it. Can also be used to mark variables and
25 /// functions, making them private to any shared library they are linked into.
26 #if (__GNUC__ >= 4) && !defined(__MINGW32__) && !defined(__CYGWIN__)
27 #define LLVM_LIBRARY_VISIBILITY __attribute__ ((visibility("hidden")))
29 #define LLVM_LIBRARY_VISIBILITY
32 #if (__GNUC__ >= 4 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1))
33 #define LLVM_ATTRIBUTE_USED __attribute__((__used__))
35 #define LLVM_ATTRIBUTE_USED
38 // Some compilers warn about unused functions. When a function is sometimes
39 // used or not depending on build settings (e.g. a function only called from
40 // within "assert"), this attribute can be used to suppress such warnings.
42 // However, it shouldn't be used for unused *variables*, as those have a much
43 // more portable solution:
44 // (void)unused_var_name;
45 // Prefer cast-to-void wherever it is sufficient.
46 #if (__GNUC__ >= 4 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1))
47 #define LLVM_ATTRIBUTE_UNUSED __attribute__((__unused__))
49 #define LLVM_ATTRIBUTE_UNUSED
52 #ifdef __GNUC__ // aka 'ATTRIBUTE_CONST' but following LLVM Conventions.
53 #define LLVM_ATTRIBUTE_READNONE __attribute__((__const__))
55 #define LLVM_ATTRIBUTE_READNONE
58 #ifdef __GNUC__ // aka 'ATTRIBUTE_PURE' but following LLVM Conventions.
59 #define LLVM_ATTRIBUTE_READONLY __attribute__((__pure__))
61 #define LLVM_ATTRIBUTE_READONLY
65 #define BUILTIN_EXPECT(EXPR, VALUE) __builtin_expect((EXPR), (VALUE))
67 #define BUILTIN_EXPECT(EXPR, VALUE) (EXPR)
70 // C++ doesn't support 'extern template' of template specializations. GCC does,
71 // but requires __extension__ before it. In the header, use this:
72 // EXTERN_TEMPLATE_INSTANTIATION(class foo<bar>);
73 // in the .cpp file, use this:
74 // TEMPLATE_INSTANTIATION(class foo<bar>);
76 #define EXTERN_TEMPLATE_INSTANTIATION(X) __extension__ extern template X
77 #define TEMPLATE_INSTANTIATION(X) template X
79 #define EXTERN_TEMPLATE_INSTANTIATION(X)
80 #define TEMPLATE_INSTANTIATION(X)
83 // LLVM_ATTRIBUTE_NOINLINE - On compilers where we have a directive to do so,
84 // mark a method "not for inlining".
85 #if (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4))
86 #define LLVM_ATTRIBUTE_NOINLINE __attribute__((noinline))
87 #elif defined(_MSC_VER)
88 #define LLVM_ATTRIBUTE_NOINLINE __declspec(noinline)
90 #define LLVM_ATTRIBUTE_NOINLINE
93 // LLVM_ATTRIBUTE_ALWAYS_INLINE - On compilers where we have a directive to do
94 // so, mark a method "always inline" because it is performance sensitive. GCC
95 // 3.4 supported this but is buggy in various cases and produces unimplemented
96 // errors, just use it in GCC 4.0 and later.
98 #define LLVM_ATTRIBUTE_ALWAYS_INLINE __attribute__((always_inline))
99 #elif defined(_MSC_VER)
100 #define LLVM_ATTRIBUTE_ALWAYS_INLINE __forceinline
102 #define LLVM_ATTRIBUTE_ALWAYS_INLINE
107 #define LLVM_ATTRIBUTE_NORETURN __attribute__((noreturn))
108 #elif defined(_MSC_VER)
109 #define LLVM_ATTRIBUTE_NORETURN __declspec(noreturn)
111 #define LLVM_ATTRIBUTE_NORETURN
114 // LLVM_ATTRIBUTE_DEPRECATED(decl, "message")
115 #if __has_feature(attribute_deprecated_with_message)
116 # define LLVM_ATTRIBUTE_DEPRECATED(decl, message) \
117 decl __attribute__((deprecated(message)))
118 #elif defined(__GNUC__)
119 # define LLVM_ATTRIBUTE_DEPRECATED(decl, message) \
120 decl __attribute__((deprecated))
121 #elif defined(_MSC_VER)
122 # define LLVM_ATTRIBUTE_DEPRECATED(decl, message) \
123 __declspec(deprecated(message)) decl
125 # define LLVM_ATTRIBUTE_DEPRECATED(decl, message) \