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 /* FIXME: selectany does not have the same semantics as weak. */
     17 #define COMPILER_RT_WEAK __declspec(selectany)
     18 /* Need to include <windows.h> */
     19 #define COMPILER_RT_ALLOCA _alloca
     20 /* Need to include <stdio.h> and <io.h> */
     21 #define COMPILER_RT_FTRUNCATE(f,l) _chsize(_fileno(f),l)
     22 #elif __GNUC__
     23 #define COMPILER_RT_ALIGNAS(x) __attribute__((aligned(x)))
     24 #define COMPILER_RT_VISIBILITY __attribute__((visibility("hidden")))
     25 #define COMPILER_RT_WEAK __attribute__((weak))
     26 #define COMPILER_RT_ALLOCA __builtin_alloca
     27 #define COMPILER_RT_FTRUNCATE(f,l) ftruncate(fileno(f),l)
     28 #endif
     29 
     30 #if defined(__APPLE__)
     31 #define COMPILER_RT_SEG "__DATA,"
     32 #else
     33 #define COMPILER_RT_SEG ""
     34 #endif
     35 
     36 #ifdef _MSC_VER
     37 #define COMPILER_RT_SECTION(Sect) __declspec(allocate(Sect))
     38 #else
     39 #define COMPILER_RT_SECTION(Sect) __attribute__((section(Sect)))
     40 #endif
     41 
     42 #define COMPILER_RT_MAX_HOSTLEN 128
     43 #ifdef _MSC_VER
     44 #define COMPILER_RT_GETHOSTNAME(Name, Len) gethostname(Name, Len)
     45 #elif defined(__ORBIS__)
     46 #define COMPILER_RT_GETHOSTNAME(Name, Len) ((void)(Name), (void)(Len), (-1))
     47 #else
     48 #define COMPILER_RT_GETHOSTNAME(Name, Len) lprofGetHostName(Name, Len)
     49 #define COMPILER_RT_HAS_UNAME 1
     50 #endif
     51 
     52 #if COMPILER_RT_HAS_ATOMICS == 1
     53 #ifdef _MSC_VER
     54 #include <windows.h>
     55 #if _MSC_VER < 1900
     56 #define snprintf _snprintf
     57 #endif
     58 #if defined(_WIN64)
     59 #define COMPILER_RT_BOOL_CMPXCHG(Ptr, OldV, NewV)                              \
     60   (InterlockedCompareExchange64((LONGLONG volatile *)Ptr, (LONGLONG)NewV,      \
     61                                 (LONGLONG)OldV) == (LONGLONG)OldV)
     62 #define COMPILER_RT_PTR_FETCH_ADD(DomType, PtrVar, PtrIncr)                    \
     63   (DomType *)InterlockedExchangeAdd64((LONGLONG volatile *)&PtrVar,            \
     64                                       (LONGLONG)sizeof(DomType) * PtrIncr)
     65 #else /* !defined(_WIN64) */
     66 #define COMPILER_RT_BOOL_CMPXCHG(Ptr, OldV, NewV)                              \
     67   (InterlockedCompareExchange((LONG volatile *)Ptr, (LONG)NewV, (LONG)OldV) == \
     68    (LONG)OldV)
     69 #define COMPILER_RT_PTR_FETCH_ADD(DomType, PtrVar, PtrIncr)                    \
     70   (DomType *)InterlockedExchangeAdd((LONG volatile *)&PtrVar,                  \
     71                                     (LONG)sizeof(DomType) * PtrIncr)
     72 #endif
     73 #else /* !defined(_MSC_VER) */
     74 #define COMPILER_RT_BOOL_CMPXCHG(Ptr, OldV, NewV)                              \
     75   __sync_bool_compare_and_swap(Ptr, OldV, NewV)
     76 #define COMPILER_RT_PTR_FETCH_ADD(DomType, PtrVar, PtrIncr)                    \
     77   (DomType *)__sync_fetch_and_add((long *)&PtrVar, sizeof(DomType) * PtrIncr)
     78 #endif
     79 #else /* COMPILER_RT_HAS_ATOMICS != 1 */
     80 #include "InstrProfilingUtil.h"
     81 #define COMPILER_RT_BOOL_CMPXCHG(Ptr, OldV, NewV)                              \
     82   lprofBoolCmpXchg((void **)Ptr, OldV, NewV)
     83 #define COMPILER_RT_PTR_FETCH_ADD(DomType, PtrVar, PtrIncr)                    \
     84   (DomType *)lprofPtrFetchAdd((void **)&PtrVar, sizeof(DomType) * PtrIncr)
     85 #endif
     86 
     87 #define PROF_ERR(Format, ...)                                                  \
     88   fprintf(stderr, "LLVM Profile Error: " Format, __VA_ARGS__);
     89 
     90 #define PROF_WARN(Format, ...)                                                 \
     91   fprintf(stderr, "LLVM Profile Warning: " Format, __VA_ARGS__);
     92 
     93 #define PROF_NOTE(Format, ...)                                                 \
     94   fprintf(stderr, "LLVM Profile Note: " Format, __VA_ARGS__);
     95 
     96 #if defined(__FreeBSD__)
     97 
     98 #include <inttypes.h>
     99 #include <sys/types.h>
    100 
    101 #else /* defined(__FreeBSD__) */
    102 
    103 #include <inttypes.h>
    104 #include <stdint.h>
    105 
    106 #endif /* defined(__FreeBSD__) && defined(__i386__) */
    107 
    108 #endif /* PROFILE_INSTRPROFILING_PORT_H_ */
    109