Home | History | Annotate | Line # | Download | only in profile
      1 /*===- InstrProfilingPort.h- Support library for PGO instrumentation ------===*\
      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 #ifndef PROFILE_INSTRPROFILING_PORT_H_
     11 #define PROFILE_INSTRPROFILING_PORT_H_
     12 
     13 #ifdef _MSC_VER
     14 #define COMPILER_RT_ALIGNAS(x) __declspec(align(x))
     15 #define COMPILER_RT_VISIBILITY
     16 #define COMPILER_RT_WEAK __declspec(selectany)
     17 #elif __GNUC__
     18 #define COMPILER_RT_ALIGNAS(x) __attribute__((aligned(x)))
     19 #define COMPILER_RT_VISIBILITY __attribute__((visibility("hidden")))
     20 #define COMPILER_RT_WEAK __attribute__((weak))
     21 #elif defined(__lint__)
     22 #define COMPILER_RT_ALIGNAS(x)
     23 #define COMPILER_RT_VISIBILITY
     24 #define COMPILER_RT_WEAK
     25 #endif
     26 
     27 #define COMPILER_RT_SECTION(Sect) __attribute__((section(Sect)))
     28 
     29 #if COMPILER_RT_HAS_ATOMICS == 1
     30 #ifdef _MSC_VER
     31 #include <windows.h>
     32 #define snprintf _snprintf
     33 #if defined(_WIN64)
     34 #define COMPILER_RT_BOOL_CMPXCHG(Ptr, OldV, NewV)                              \
     35   (InterlockedCompareExchange64((LONGLONG volatile *)Ptr, (LONGLONG)NewV,      \
     36                                 (LONGLONG)OldV) == (LONGLONG)OldV)
     37 #else /* !defined(_WIN64) */
     38 #define COMPILER_RT_BOOL_CMPXCHG(Ptr, OldV, NewV)                              \
     39   (InterlockedCompareExchange((LONG volatile *)Ptr, (LONG)NewV, (LONG)OldV) == \
     40    (LONG)OldV)
     41 #endif
     42 #else /* !defined(_MSC_VER) */
     43 #define COMPILER_RT_BOOL_CMPXCHG(Ptr, OldV, NewV)                              \
     44   __sync_bool_compare_and_swap(Ptr, OldV, NewV)
     45 #endif
     46 #else /* COMPILER_RT_HAS_ATOMICS != 1 */
     47 #define COMPILER_RT_BOOL_CMPXCHG(Ptr, OldV, NewV)                              \
     48   BoolCmpXchg((void **)Ptr, OldV, NewV)
     49 #endif
     50 
     51 #define PROF_ERR(Format, ...)                                                  \
     52   if (GetEnvHook && GetEnvHook("LLVM_PROFILE_VERBOSE_ERRORS"))                 \
     53     fprintf(stderr, Format, __VA_ARGS__);
     54 
     55 #if defined(__FreeBSD__)
     56 
     57 #include <inttypes.h>
     58 #include <sys/types.h>
     59 
     60 #else /* defined(__FreeBSD__) */
     61 
     62 #include <inttypes.h>
     63 #include <stdint.h>
     64 
     65 #endif /* defined(__FreeBSD__) && defined(__i386__) */
     66 
     67 #endif /* PROFILE_INSTRPROFILING_PORT_H_ */
     68