I got tired of VISIBILITY_HIDDEN colliding with the gcc enum. Rename it
[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
23 /// LLVM_GLOBAL_VISIBILITY - If a class marked with this attribute is linked
24 /// into a shared library, then the class will be accessible from outside the
25 /// the library.  Can also be used to mark variables and functions, making them
26 /// accessible from outside any shared library they are linked into.
27 #if (__GNUC__ >= 4) && !defined(__MINGW32__) && !defined(__CYGWIN__)
28 #define LLVM_LIBRARY_VISIBILITY __attribute__ ((visibility("hidden")))
29 #define LLVM_GLOBAL_VISIBILITY __attribute__ ((visibility("default")))
30 #else
31 #define LLVM_LIBRARY_VISIBILITY
32 #define LLVM_GLOBAL_VISIBILITY
33 #endif
34
35 #if (__GNUC__ >= 4 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1))
36 #define ATTRIBUTE_USED __attribute__((__used__))
37 #else
38 #define ATTRIBUTE_USED
39 #endif
40
41 #if (__GNUC__ >= 4 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1))
42 #define ATTRIBUTE_UNUSED __attribute__((__unused__))
43 #else
44 #define ATTRIBUTE_UNUSED
45 #endif
46
47 #ifdef __GNUC__ // aka 'ATTRIBUTE_CONST' but following LLVM Conventions.
48 #define ATTRIBUTE_READNONE __attribute__((__const__))
49 #else
50 #define ATTRIBUTE_READNONE
51 #endif
52
53 #ifdef __GNUC__  // aka 'ATTRIBUTE_PURE' but following LLVM Conventions.
54 #define ATTRIBUTE_READONLY __attribute__((__pure__))
55 #else
56 #define ATTRIBUTE_READONLY
57 #endif
58
59 #if (__GNUC__ >= 4)
60 #define BUILTIN_EXPECT(EXPR, VALUE) __builtin_expect((EXPR), (VALUE))
61 #else
62 #define BUILTIN_EXPECT(EXPR, VALUE) (EXPR)
63 #endif
64
65 // C++ doesn't support 'extern template' of template specializations.  GCC does,
66 // but requires __extension__ before it.  In the header, use this:
67 //   EXTERN_TEMPLATE_INSTANTIATION(class foo<bar>);
68 // in the .cpp file, use this:
69 //   TEMPLATE_INSTANTIATION(class foo<bar>);
70 #ifdef __GNUC__
71 #define EXTERN_TEMPLATE_INSTANTIATION(X) __extension__ extern template X
72 #define TEMPLATE_INSTANTIATION(X) template X
73 #else
74 #define EXTERN_TEMPLATE_INSTANTIATION(X)
75 #define TEMPLATE_INSTANTIATION(X)
76 #endif
77
78 // DISABLE_INLINE - On compilers where we have a directive to do so, mark a
79 // method "not for inlining".
80 #if (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4))
81 #define DISABLE_INLINE __attribute__((noinline))
82 #elif defined(_MSC_VER)
83 #define DISABLE_INLINE __declspec(noinline)
84 #else
85 #define DISABLE_INLINE
86 #endif
87
88 // ALWAYS_INLINE - On compilers where we have a directive to do so, mark a
89 // method "always inline" because it is performance sensitive.
90 // GCC 3.4 supported this but is buggy in various cases and produces
91 // unimplemented errors, just use it in GCC 4.0 and later.
92 #if __GNUC__ > 3
93 #define ALWAYS_INLINE __attribute__((always_inline))
94 #else
95 // TODO: No idea how to do this with MSVC.
96 #define ALWAYS_INLINE
97 #endif
98
99
100 #ifdef __GNUC__
101 #define NORETURN __attribute__((noreturn))
102 #elif defined(_MSC_VER)
103 #define NORETURN __declspec(noreturn)
104 #else
105 #define NORETURN
106 #endif
107
108 #endif