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 defined(__MINGW32__) || defined(__CYGWIN__)
28
#define LLVM_LIBRARY_VISIBILITY
29
#define LLVM_GLOBAL_VISIBILITY __declspec(dllexport)
31
#define LLVM_LIBRARY_VISIBILITY __attribute__ ((visibility("hidden")))
32
#define LLVM_GLOBAL_VISIBILITY __attribute__ ((visibility("default")))
34
#define LLVM_LIBRARY_VISIBILITY
35
#define LLVM_GLOBAL_VISIBILITY
38
#if (__GNUC__ >= 4 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1))
39
#define ATTRIBUTE_USED __attribute__((__used__))
41
#define ATTRIBUTE_USED
44
#if (__GNUC__ >= 4 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1))
45
#define ATTRIBUTE_UNUSED __attribute__((__unused__))
47
#define ATTRIBUTE_UNUSED
50
#ifdef __GNUC__ // aka 'ATTRIBUTE_CONST' but following LLVM Conventions.
51
#define ATTRIBUTE_READNONE __attribute__((__const__))
53
#define ATTRIBUTE_READNONE
56
#ifdef __GNUC__ // aka 'ATTRIBUTE_PURE' but following LLVM Conventions.
57
#define ATTRIBUTE_READONLY __attribute__((__pure__))
59
#define ATTRIBUTE_READONLY
63
#define BUILTIN_EXPECT(EXPR, VALUE) __builtin_expect((EXPR), (VALUE))
65
#define BUILTIN_EXPECT(EXPR, VALUE) (EXPR)
68
// C++ doesn't support 'extern template' of template specializations. GCC does,
69
// but requires __extension__ before it. In the header, use this:
70
// EXTERN_TEMPLATE_INSTANTIATION(class foo<bar>);
71
// in the .cpp file, use this:
72
// TEMPLATE_INSTANTIATION(class foo<bar>);
74
#define EXTERN_TEMPLATE_INSTANTIATION(X) __extension__ extern template X
75
#define TEMPLATE_INSTANTIATION(X) template X
77
#define EXTERN_TEMPLATE_INSTANTIATION(X)
78
#define TEMPLATE_INSTANTIATION(X)
81
// DISABLE_INLINE - On compilers where we have a directive to do so, mark a
82
// method "not for inlining".
83
#if (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4))
84
#define DISABLE_INLINE __attribute__((noinline))
85
#elif defined(_MSC_VER)
86
#define DISABLE_INLINE __declspec(noinline)
88
#define DISABLE_INLINE
91
// ALWAYS_INLINE - On compilers where we have a directive to do so, mark a
92
// method "always inline" because it is performance sensitive.
93
// GCC 3.4 supported this but is buggy in various cases and produces
94
// unimplemented errors, just use it in GCC 4.0 and later.
96
#define ALWAYS_INLINE __attribute__((always_inline))
98
// TODO: No idea how to do this with MSVC.
104
#define NORETURN __attribute__((noreturn))
105
#elif defined(_MSC_VER)
106
#define NORETURN __declspec(noreturn)