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