Fix trivial typo in llvm_move.
[oota-llvm.git] / include / llvm / Support / Compiler.h
1 //===-- llvm/Support/Compiler.h - Compiler abstraction support --*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
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.
12 //
13 //===----------------------------------------------------------------------===//
14
15 #ifndef LLVM_SUPPORT_COMPILER_H
16 #define LLVM_SUPPORT_COMPILER_H
17
18 #ifndef __has_feature
19 # define __has_feature(x) 0
20 #endif
21
22 /// LLVM_HAS_RVALUE_REFERENCES - Does the compiler provide r-value references?
23 /// This implies that <utility> provides the one-argument std::move;  it
24 /// does not imply the existence of any other C++ library features.
25 #if (__has_feature(cxx_rvalue_references)   \
26      || defined(__GXX_EXPERIMENTAL_CXX0X__) \
27      || _MSC_VER >= 1600)
28 #define LLVM_USE_RVALUE_REFERENCES 1
29 #else
30 #define LLVM_USE_RVALUE_REFERENCES 0
31 #endif
32
33 /// llvm_move - Expands to ::std::move if the compiler supports
34 /// r-value references; otherwise, expands to the argument.
35 #if LLVM_USE_RVALUE_REFERENCES
36 #define llvm_move(value) (::std::move(value))
37 #else
38 #define llvm_move(value) (value)
39 #endif
40
41 /// LLVM_LIBRARY_VISIBILITY - If a class marked with this attribute is linked
42 /// into a shared library, then the class should be private to the library and
43 /// not accessible from outside it.  Can also be used to mark variables and
44 /// functions, making them private to any shared library they are linked into.
45 #if (__GNUC__ >= 4) && !defined(__MINGW32__) && !defined(__CYGWIN__)
46 #define LLVM_LIBRARY_VISIBILITY __attribute__ ((visibility("hidden")))
47 #else
48 #define LLVM_LIBRARY_VISIBILITY
49 #endif
50
51 #if (__GNUC__ >= 4 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1))
52 #define LLVM_ATTRIBUTE_USED __attribute__((__used__))
53 #else
54 #define LLVM_ATTRIBUTE_USED
55 #endif
56
57 // Some compilers warn about unused functions. When a function is sometimes
58 // used or not depending on build settings (e.g. a function only called from
59 // within "assert"), this attribute can be used to suppress such warnings.
60 //
61 // However, it shouldn't be used for unused *variables*, as those have a much
62 // more portable solution:
63 //   (void)unused_var_name;
64 // Prefer cast-to-void wherever it is sufficient.
65 #if (__GNUC__ >= 4 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1))
66 #define LLVM_ATTRIBUTE_UNUSED __attribute__((__unused__))
67 #else
68 #define LLVM_ATTRIBUTE_UNUSED
69 #endif
70
71 #if (__GNUC__ >= 4) && !defined(__MINGW32__) && !defined(__CYGWIN__)
72 #define LLVM_ATTRIBUTE_WEAK __attribute__((__weak__))
73 #else
74 #define LLVM_ATTRIBUTE_WEAK
75 #endif
76
77 #ifdef __GNUC__ // aka 'CONST' but following LLVM Conventions.
78 #define LLVM_READNONE __attribute__((__const__))
79 #else
80 #define LLVM_READNONE
81 #endif
82
83 #ifdef __GNUC__  // aka 'PURE' but following LLVM Conventions.
84 #define LLVM_READONLY __attribute__((__pure__))
85 #else
86 #define LLVM_READONLY
87 #endif
88
89 #if (__GNUC__ >= 4)
90 #define BUILTIN_EXPECT(EXPR, VALUE) __builtin_expect((EXPR), (VALUE))
91 #else
92 #define BUILTIN_EXPECT(EXPR, VALUE) (EXPR)
93 #endif
94
95
96 // C++ doesn't support 'extern template' of template specializations.  GCC does,
97 // but requires __extension__ before it.  In the header, use this:
98 //   EXTERN_TEMPLATE_INSTANTIATION(class foo<bar>);
99 // in the .cpp file, use this:
100 //   TEMPLATE_INSTANTIATION(class foo<bar>);
101 #ifdef __GNUC__
102 #define EXTERN_TEMPLATE_INSTANTIATION(X) __extension__ extern template X
103 #define TEMPLATE_INSTANTIATION(X) template X
104 #else
105 #define EXTERN_TEMPLATE_INSTANTIATION(X)
106 #define TEMPLATE_INSTANTIATION(X)
107 #endif
108
109 // LLVM_ATTRIBUTE_NOINLINE - On compilers where we have a directive to do so,
110 // mark a method "not for inlining".
111 #if (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4))
112 #define LLVM_ATTRIBUTE_NOINLINE __attribute__((noinline))
113 #elif defined(_MSC_VER)
114 #define LLVM_ATTRIBUTE_NOINLINE __declspec(noinline)
115 #else
116 #define LLVM_ATTRIBUTE_NOINLINE
117 #endif
118
119 // LLVM_ATTRIBUTE_ALWAYS_INLINE - On compilers where we have a directive to do
120 // so, mark a method "always inline" because it is performance sensitive. GCC
121 // 3.4 supported this but is buggy in various cases and produces unimplemented
122 // errors, just use it in GCC 4.0 and later.
123 #if __GNUC__ > 3
124 #define LLVM_ATTRIBUTE_ALWAYS_INLINE __attribute__((always_inline))
125 #elif defined(_MSC_VER)
126 #define LLVM_ATTRIBUTE_ALWAYS_INLINE __forceinline
127 #else
128 #define LLVM_ATTRIBUTE_ALWAYS_INLINE
129 #endif
130
131
132 #ifdef __GNUC__
133 #define LLVM_ATTRIBUTE_NORETURN __attribute__((noreturn))
134 #elif defined(_MSC_VER)
135 #define LLVM_ATTRIBUTE_NORETURN __declspec(noreturn)
136 #else
137 #define LLVM_ATTRIBUTE_NORETURN
138 #endif
139
140 // LLVM_EXTENSION - Support compilers where we have a keyword to suppress
141 // pedantic diagnostics.
142 #ifdef __GNUC__
143 #define LLVM_EXTENSION __extension__
144 #else
145 #define LLVM_EXTENSION
146 #endif
147
148 // LLVM_ATTRIBUTE_DEPRECATED(decl, "message")
149 #if __has_feature(attribute_deprecated_with_message)
150 # define LLVM_ATTRIBUTE_DEPRECATED(decl, message) \
151   decl __attribute__((deprecated(message)))
152 #elif defined(__GNUC__)
153 # define LLVM_ATTRIBUTE_DEPRECATED(decl, message) \
154   decl __attribute__((deprecated))
155 #elif defined(_MSC_VER)
156 # define LLVM_ATTRIBUTE_DEPRECATED(decl, message) \
157   __declspec(deprecated(message)) decl
158 #else
159 # define LLVM_ATTRIBUTE_DEPRECATED(decl, message) \
160   decl
161 #endif
162
163 // LLVM_BUILTIN_UNREACHABLE - On compilers which support it, expands
164 // to an expression which states that it is undefined behavior for the
165 // compiler to reach this point.  Otherwise is not defined.
166 #if defined(__clang__) || (__GNUC__ > 4) \
167  || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5)
168 # define LLVM_BUILTIN_UNREACHABLE __builtin_unreachable()
169 #endif
170
171 #endif