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 ATTRIBUTE_USED __attribute__((__used__))
31 #define ATTRIBUTE_USED
34 #if (__GNUC__ >= 4 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1))
35 #define ATTRIBUTE_UNUSED __attribute__((__unused__))
37 #define ATTRIBUTE_UNUSED
40 #ifdef __GNUC__ // aka 'ATTRIBUTE_CONST' but following LLVM Conventions.
41 #define ATTRIBUTE_READNONE __attribute__((__const__))
43 #define ATTRIBUTE_READNONE
46 #ifdef __GNUC__ // aka 'ATTRIBUTE_PURE' but following LLVM Conventions.
47 #define ATTRIBUTE_READONLY __attribute__((__pure__))
49 #define ATTRIBUTE_READONLY
53 #define BUILTIN_EXPECT(EXPR, VALUE) __builtin_expect((EXPR), (VALUE))
55 #define BUILTIN_EXPECT(EXPR, VALUE) (EXPR)
58 // C++ doesn't support 'extern template' of template specializations. GCC does,
59 // but requires __extension__ before it. In the header, use this:
60 // EXTERN_TEMPLATE_INSTANTIATION(class foo<bar>);
61 // in the .cpp file, use this:
62 // TEMPLATE_INSTANTIATION(class foo<bar>);
64 #define EXTERN_TEMPLATE_INSTANTIATION(X) __extension__ extern template X
65 #define TEMPLATE_INSTANTIATION(X) template X
67 #define EXTERN_TEMPLATE_INSTANTIATION(X)
68 #define TEMPLATE_INSTANTIATION(X)
71 // DISABLE_INLINE - On compilers where we have a directive to do so, mark a
72 // method "not for inlining".
73 #if (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4))
74 #define DISABLE_INLINE __attribute__((noinline))
75 #elif defined(_MSC_VER)
76 #define DISABLE_INLINE __declspec(noinline)
78 #define DISABLE_INLINE
81 // ALWAYS_INLINE - On compilers where we have a directive to do so, mark a
82 // method "always inline" because it is performance sensitive.
83 // GCC 3.4 supported this but is buggy in various cases and produces
84 // unimplemented errors, just use it in GCC 4.0 and later.
86 #define ALWAYS_INLINE __attribute__((always_inline))
88 // TODO: No idea how to do this with MSVC.
94 #define NORETURN __attribute__((noreturn))
95 #elif defined(_MSC_VER)
96 #define NORETURN __declspec(noreturn)