Home | History | Annotate | 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 #endif
     22 
     23 #define COMPILER_RT_SECTION(Sect) __attribute__((section(Sect)))
     24 
     25 #if COMPILER_RT_HAS_ATOMICS == 1
     26 #ifdef _MSC_VER
     27 #include <windows.h>
     28 #if defined(_WIN64)
     29 #define COMPILER_RT_BOOL_CMPXCHG(Ptr, OldV, NewV)                              \
     30   (InterlockedCompareExchange64((LONGLONG volatile *)Ptr, (LONGLONG)NewV,      \
     31                                 (LONGLONG)OldV) == (LONGLONG)OldV)
     32 #else
     33 #define COMPILER_RT_BOOL_CMPXCHG(Ptr, OldV, NewV)                              \
     34   (InterlockedCompareExchange((LONG volatile *)Ptr, (LONG)NewV, (LONG)OldV) == \
     35    (LONG)OldV)
     36 #endif
     37 #else
     38 #define COMPILER_RT_BOOL_CMPXCHG(Ptr, OldV, NewV)                              \
     39   __sync_bool_compare_and_swap(Ptr, OldV, NewV)
     40 #endif
     41 #else
     42 #define COMPILER_RT_BOOL_CMPXCHG(Ptr, OldV, NewV)                              \
     43   BoolCmpXchg((void **)Ptr, OldV, NewV)
     44 #endif
     45 
     46 #define PROF_ERR(Format, ...)                                                  \
     47   if (GetEnvHook && GetEnvHook("LLVM_PROFILE_VERBOSE_ERRORS"))                 \
     48     fprintf(stderr, Format, __VA_ARGS__);
     49 
     50 #if defined(__FreeBSD__) && defined(__i386__)
     51 
     52 /* System headers define 'size_t' incorrectly on x64 FreeBSD (prior to
     53  * FreeBSD 10, r232261) when compiled in 32-bit mode.
     54  */
     55 #define PRIu64 "llu"
     56 typedef unsigned char uint8_t;
     57 typedef unsigned short uint16_t;
     58 typedef unsigned int uint32_t;
     59 typedef unsigned long long uint64_t;
     60 typedef uint32_t uintptr_t;
     61 #elif defined(__FreeBSD__) && defined(__x86_64__)
     62 #define PRIu64 "lu"
     63 typedef unsigned char uint8_t;
     64 typedef unsigned short uint16_t;
     65 typedef unsigned int uint32_t;
     66 typedef unsigned long long uint64_t;
     67 typedef unsigned long int uintptr_t;
     68 
     69 #else /* defined(__FreeBSD__) && defined(__i386__) */
     70 
     71 #include <inttypes.h>
     72 #include <stdint.h>
     73 
     74 #endif /* defined(__FreeBSD__) && defined(__i386__) */
     75 
     76 #endif /* PROFILE_INSTRPROFILING_PORT_H_ */
     77