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.
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")))
31 #define LLVM_LIBRARY_VISIBILITY
32 #define LLVM_GLOBAL_VISIBILITY
35 #if (__GNUC__ >= 4 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1))
36 #define ATTRIBUTE_USED __attribute__((__used__))
38 #define ATTRIBUTE_USED
41 #if (__GNUC__ >= 4 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1))
42 #define ATTRIBUTE_UNUSED __attribute__((__unused__))
44 #define ATTRIBUTE_UNUSED
47 #ifdef __GNUC__ // aka 'ATTRIBUTE_CONST' but following LLVM Conventions.
48 #define ATTRIBUTE_READNONE __attribute__((__const__))
50 #define ATTRIBUTE_READNONE
53 #ifdef __GNUC__ // aka 'ATTRIBUTE_PURE' but following LLVM Conventions.
54 #define ATTRIBUTE_READONLY __attribute__((__pure__))
56 #define ATTRIBUTE_READONLY
60 #define BUILTIN_EXPECT(EXPR, VALUE) __builtin_expect((EXPR), (VALUE))
62 #define BUILTIN_EXPECT(EXPR, VALUE) (EXPR)
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>);
71 #define EXTERN_TEMPLATE_INSTANTIATION(X) __extension__ extern template X
72 #define TEMPLATE_INSTANTIATION(X) template X
74 #define EXTERN_TEMPLATE_INSTANTIATION(X)
75 #define TEMPLATE_INSTANTIATION(X)
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)
85 #define DISABLE_INLINE
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.
93 #define ALWAYS_INLINE __attribute__((always_inline))
95 // TODO: No idea how to do this with MSVC.
101 #define NORETURN __attribute__((noreturn))
102 #elif defined(_MSC_VER)
103 #define NORETURN __declspec(noreturn)