LLVM API Documentation

Compiler.h

Go to the documentation of this file.
00001 //===-- llvm/Support/Compiler.h - Compiler abstraction support --*- C++ -*-===//
00002 //
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file is distributed under the University of Illinois Open Source
00006 // License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 //
00010 // This file defines several macros, based on the current compiler.  This allows
00011 // use of compiler-specific features in a way that remains portable.
00012 //
00013 //===----------------------------------------------------------------------===//
00014 
00015 #ifndef LLVM_SUPPORT_COMPILER_H
00016 #define LLVM_SUPPORT_COMPILER_H
00017 
00018 // The VISIBILITY_HIDDEN macro, used for marking classes with the GCC-specific
00019 // visibility("hidden") attribute.
00020 #if (__GNUC__ >= 4) && !defined(__MINGW32__) && !defined(__CYGWIN__)
00021 #define VISIBILITY_HIDDEN __attribute__ ((visibility("hidden")))
00022 #else
00023 #define VISIBILITY_HIDDEN
00024 #endif
00025 
00026 #if (__GNUC__ >= 4 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1))
00027 #define ATTRIBUTE_USED __attribute__((__used__))
00028 #else
00029 #define ATTRIBUTE_USED
00030 #endif
00031 
00032 #if (__GNUC__ >= 4)
00033 #define BUILTIN_EXPECT(EXPR, VALUE) __builtin_expect((EXPR), (VALUE))
00034 #else
00035 #define BUILTIN_EXPECT(EXPR, VALUE) (EXPR)
00036 #endif
00037 
00038 // C++ doesn't support 'extern template' of template specializations.  GCC does,
00039 // but requires __extension__ before it.  In the header, use this:
00040 //   EXTERN_TEMPLATE_INSTANTIATION(class foo<bar>);
00041 // in the .cpp file, use this:
00042 //   TEMPLATE_INSTANTIATION(class foo<bar>);
00043 #ifdef __GNUC__
00044 #define EXTERN_TEMPLATE_INSTANTIATION(X) __extension__ extern template X
00045 #define TEMPLATE_INSTANTIATION(X) template X
00046 #else
00047 #define EXTERN_TEMPLATE_INSTANTIATION(X)
00048 #define TEMPLATE_INSTANTIATION(X)
00049 #endif
00050 
00051 // DISABLE_INLINE - On compilers where we have a directive to do so, mark a
00052 // method "not for inlining".
00053 #if (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4))
00054 #define DISABLE_INLINE __attribute__((noinline))
00055 #else
00056 #define DISABLE_INLINE
00057 #endif
00058 
00059 #ifdef __GNUC__
00060 #define NORETURN __attribute__((noreturn))
00061 #else
00062 #define NORETURN
00063 #endif
00064 
00065 #endif