Switch attribute macros to use 'LLVM_' as a prefix. We retain the old names
[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 /// LLVM_LIBRARY_VISIBILITY - If a class marked with this attribute is linked
19 /// into a shared library, then the class should be private to the library and
20 /// not accessible from outside it.  Can also be used to mark variables and
21 /// functions, making them private to any shared library they are linked into.
22 #if (__GNUC__ >= 4) && !defined(__MINGW32__) && !defined(__CYGWIN__)
23 #define LLVM_LIBRARY_VISIBILITY __attribute__ ((visibility("hidden")))
24 #else
25 #define LLVM_LIBRARY_VISIBILITY
26 #endif
27
28 #if (__GNUC__ >= 4 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1))
29 #define LLVM_ATTRIBUTE_USED __attribute__((__used__))
30 #else
31 #define LLVM_ATTRIBUTE_USED
32 #endif
33
34 // Some compilers warn about unused functions. When a function is sometimes
35 // used or not depending on build settings (e.g. a function only called from
36 // within "assert"), this attribute can be used to suppress such warnings.
37 //
38 // However, it shouldn't be used for unused *variables*, as those have a much
39 // more portable solution:
40 //   (void)unused_var_name;
41 // Prefer cast-to-void wherever it is sufficient.
42 #if (__GNUC__ >= 4 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1))
43 #define LLVM_ATTRIBUTE_UNUSED __attribute__((__unused__))
44 #else
45 #define LLVM_ATTRIBUTE_UNUSED
46 #endif
47
48 #ifdef __GNUC__ // aka 'ATTRIBUTE_CONST' but following LLVM Conventions.
49 #define LLVM_ATTRIBUTE_READNONE __attribute__((__const__))
50 #else
51 #define LLVM_ATTRIBUTE_READNONE
52 #endif
53
54 #ifdef __GNUC__  // aka 'ATTRIBUTE_PURE' but following LLVM Conventions.
55 #define LLVM_ATTRIBUTE_READONLY __attribute__((__pure__))
56 #else
57 #define LLVM_ATTRIBUTE_READONLY
58 #endif
59
60 #if (__GNUC__ >= 4)
61 #define BUILTIN_EXPECT(EXPR, VALUE) __builtin_expect((EXPR), (VALUE))
62 #else
63 #define BUILTIN_EXPECT(EXPR, VALUE) (EXPR)
64 #endif
65
66 // C++ doesn't support 'extern template' of template specializations.  GCC does,
67 // but requires __extension__ before it.  In the header, use this:
68 //   EXTERN_TEMPLATE_INSTANTIATION(class foo<bar>);
69 // in the .cpp file, use this:
70 //   TEMPLATE_INSTANTIATION(class foo<bar>);
71 #ifdef __GNUC__
72 #define EXTERN_TEMPLATE_INSTANTIATION(X) __extension__ extern template X
73 #define TEMPLATE_INSTANTIATION(X) template X
74 #else
75 #define EXTERN_TEMPLATE_INSTANTIATION(X)
76 #define TEMPLATE_INSTANTIATION(X)
77 #endif
78
79 // DISABLE_INLINE - On compilers where we have a directive to do so, mark a
80 // method "not for inlining".
81 #if (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4))
82 #define DISABLE_INLINE __attribute__((noinline))
83 #elif defined(_MSC_VER)
84 #define DISABLE_INLINE __declspec(noinline)
85 #else
86 #define DISABLE_INLINE
87 #endif
88
89 // ALWAYS_INLINE - On compilers where we have a directive to do so, mark a
90 // method "always inline" because it is performance sensitive.
91 // GCC 3.4 supported this but is buggy in various cases and produces
92 // unimplemented errors, just use it in GCC 4.0 and later.
93 #if __GNUC__ > 3
94 #define ALWAYS_INLINE __attribute__((always_inline))
95 #elif defined(_MSC_VER)
96 #define ALWAYS_INLINE __forceinline
97 #else
98 #define ALWAYS_INLINE
99 #endif
100
101
102 #ifdef __GNUC__
103 #define NORETURN __attribute__((noreturn))
104 #elif defined(_MSC_VER)
105 #define NORETURN __declspec(noreturn)
106 #else
107 #define NORETURN
108 #endif
109
110 // We provide definitions without the LLVM_ prefix briefly while transitioning
111 // to always-prefixed names. These will go away as soon as the migration is
112 // complete.
113 #define ATTRIBUTE_USED LLVM_ATTRIBUTE_USED
114 #define ATTRIBUTE_UNUSED LLVM_ATTRIBUTE_UNUSED
115 #define ATTRIBUTE_READNONE LLVM_ATTRIBUTE_READNONE
116 #define ATTRIBUTE_READONLY LLVM_ATTRIBUTE_READONLY
117
118 #endif