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
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")))
25 #define LLVM_LIBRARY_VISIBILITY
28 #if (__GNUC__ >= 4 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1))
29 #define LLVM_ATTRIBUTE_USED __attribute__((__used__))
31 #define LLVM_ATTRIBUTE_USED
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.
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__))
45 #define LLVM_ATTRIBUTE_UNUSED
48 #ifdef __GNUC__ // aka 'ATTRIBUTE_CONST' but following LLVM Conventions.
49 #define LLVM_ATTRIBUTE_READNONE __attribute__((__const__))
51 #define LLVM_ATTRIBUTE_READNONE
54 #ifdef __GNUC__ // aka 'ATTRIBUTE_PURE' but following LLVM Conventions.
55 #define LLVM_ATTRIBUTE_READONLY __attribute__((__pure__))
57 #define LLVM_ATTRIBUTE_READONLY
61 #define BUILTIN_EXPECT(EXPR, VALUE) __builtin_expect((EXPR), (VALUE))
63 #define BUILTIN_EXPECT(EXPR, VALUE) (EXPR)
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>);
72 #define EXTERN_TEMPLATE_INSTANTIATION(X) __extension__ extern template X
73 #define TEMPLATE_INSTANTIATION(X) template X
75 #define EXTERN_TEMPLATE_INSTANTIATION(X)
76 #define TEMPLATE_INSTANTIATION(X)
79 // LLVM_ATTRIBUTE_NOINLINE - On compilers where we have a directive to do so,
80 // mark a method "not for inlining".
81 #if (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4))
82 #define LLVM_ATTRIBUTE_NOINLINE __attribute__((noinline))
83 #elif defined(_MSC_VER)
84 #define LLVM_ATTRIBUTE_NOINLINE __declspec(noinline)
86 #define LLVM_ATTRIBUTE_NOINLINE
89 // LLVM_ATTRIBUTE_ALWAYS_INLINE - On compilers where we have a directive to do
90 // so, mark a method "always inline" because it is performance sensitive. GCC
91 // 3.4 supported this but is buggy in various cases and produces unimplemented
92 // errors, just use it in GCC 4.0 and later.
94 #define LLVM_ATTRIBUTE_ALWAYS_INLINE __attribute__((always_inline))
95 #elif defined(_MSC_VER)
96 #define LLVM_ATTRIBUTE_ALWAYS_INLINE __forceinline
98 #define LLVM_ATTRIBUTE_ALWAYS_INLINE
103 #define LLVM_ATTRIBUTE_NORETURN __attribute__((noreturn))
104 #elif defined(_MSC_VER)
105 #define LLVM_ATTRIBUTE_NORETURN __declspec(noreturn)
107 #define LLVM_ATTRIBUTE_NORETURN