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 /* This header must be included after all others so it can provide fallback 11 definitions for stuff missing in system headers. */ 12 13 #ifndef PROFILE_INSTRPROFILING_PORT_H_ 14 #define PROFILE_INSTRPROFILING_PORT_H_ 15 16 #ifdef _MSC_VER 17 #define COMPILER_RT_ALIGNAS(x) __declspec(align(x)) 18 #define COMPILER_RT_VISIBILITY 19 /* FIXME: selectany does not have the same semantics as weak. */ 20 #define COMPILER_RT_WEAK __declspec(selectany) 21 /* Need to include <windows.h> */ 22 #define COMPILER_RT_ALLOCA _alloca 23 /* Need to include <stdio.h> and <io.h> */ 24 #define COMPILER_RT_FTRUNCATE(f,l) _chsize(_fileno(f),l) 25 #define COMPILER_RT_ALWAYS_INLINE __forceinline 26 #elif __GNUC__ 27 #define COMPILER_RT_ALIGNAS(x) __attribute__((aligned(x))) 28 #define COMPILER_RT_VISIBILITY __attribute__((visibility("hidden"))) 29 #define COMPILER_RT_WEAK __attribute__((weak)) 30 #define COMPILER_RT_ALLOCA __builtin_alloca 31 #define COMPILER_RT_FTRUNCATE(f,l) ftruncate(fileno(f),l) 32 #define COMPILER_RT_ALWAYS_INLINE inline __attribute((always_inline)) 33 #endif 34 35 #if defined(__APPLE__) 36 #define COMPILER_RT_SEG "__DATA," 37 #else 38 #define COMPILER_RT_SEG "" 39 #endif 40 41 #ifdef _MSC_VER 42 #define COMPILER_RT_SECTION(Sect) __declspec(allocate(Sect)) 43 #else 44 #define COMPILER_RT_SECTION(Sect) __attribute__((section(Sect))) 45 #endif 46 47 #define COMPILER_RT_MAX_HOSTLEN 128 48 #ifdef __ORBIS__ 49 #define COMPILER_RT_GETHOSTNAME(Name, Len) ((void)(Name), (void)(Len), (-1)) 50 #else 51 #define COMPILER_RT_GETHOSTNAME(Name, Len) lprofGetHostName(Name, Len) 52 #endif 53 54 #if COMPILER_RT_HAS_ATOMICS == 1 55 #ifdef _MSC_VER 56 #include <windows.h> 57 #if _MSC_VER < 1900 58 #define snprintf _snprintf 59 #endif 60 #if defined(_WIN64) 61 #define COMPILER_RT_BOOL_CMPXCHG(Ptr, OldV, NewV) \ 62 (InterlockedCompareExchange64((LONGLONG volatile *)Ptr, (LONGLONG)NewV, \ 63 (LONGLONG)OldV) == (LONGLONG)OldV) 64 #define COMPILER_RT_PTR_FETCH_ADD(DomType, PtrVar, PtrIncr) \ 65 (DomType *)InterlockedExchangeAdd64((LONGLONG volatile *)&PtrVar, \ 66 (LONGLONG)sizeof(DomType) * PtrIncr) 67 #else /* !defined(_WIN64) */ 68 #define COMPILER_RT_BOOL_CMPXCHG(Ptr, OldV, NewV) \ 69 (InterlockedCompareExchange((LONG volatile *)Ptr, (LONG)NewV, (LONG)OldV) == \ 70 (LONG)OldV) 71 #define COMPILER_RT_PTR_FETCH_ADD(DomType, PtrVar, PtrIncr) \ 72 (DomType *)InterlockedExchangeAdd((LONG volatile *)&PtrVar, \ 73 (LONG)sizeof(DomType) * PtrIncr) 74 #endif 75 #else /* !defined(_MSC_VER) */ 76 #define COMPILER_RT_BOOL_CMPXCHG(Ptr, OldV, NewV) \ 77 __sync_bool_compare_and_swap(Ptr, OldV, NewV) 78 #define COMPILER_RT_PTR_FETCH_ADD(DomType, PtrVar, PtrIncr) \ 79 (DomType *)__sync_fetch_and_add((long *)&PtrVar, sizeof(DomType) * PtrIncr) 80 #endif 81 #else /* COMPILER_RT_HAS_ATOMICS != 1 */ 82 #include "InstrProfilingUtil.h" 83 #define COMPILER_RT_BOOL_CMPXCHG(Ptr, OldV, NewV) \ 84 lprofBoolCmpXchg((void **)Ptr, OldV, NewV) 85 #define COMPILER_RT_PTR_FETCH_ADD(DomType, PtrVar, PtrIncr) \ 86 (DomType *)lprofPtrFetchAdd((void **)&PtrVar, sizeof(DomType) * PtrIncr) 87 #endif 88 89 #if defined(_WIN32) 90 #define DIR_SEPARATOR '\\' 91 #define DIR_SEPARATOR_2 '/' 92 #else 93 #define DIR_SEPARATOR '/' 94 #endif 95 96 #ifndef DIR_SEPARATOR_2 97 #define IS_DIR_SEPARATOR(ch) ((ch) == DIR_SEPARATOR) 98 #else /* DIR_SEPARATOR_2 */ 99 #define IS_DIR_SEPARATOR(ch) \ 100 (((ch) == DIR_SEPARATOR) || ((ch) == DIR_SEPARATOR_2)) 101 #endif /* DIR_SEPARATOR_2 */ 102 103 #define PROF_ERR(Format, ...) \ 104 fprintf(stderr, "LLVM Profile Error: " Format, __VA_ARGS__); 105 106 #define PROF_WARN(Format, ...) \ 107 fprintf(stderr, "LLVM Profile Warning: " Format, __VA_ARGS__); 108 109 #define PROF_NOTE(Format, ...) \ 110 fprintf(stderr, "LLVM Profile Note: " Format, __VA_ARGS__); 111 112 #ifndef MAP_FILE 113 #define MAP_FILE 0 114 #endif 115 116 #ifndef O_BINARY 117 #define O_BINARY 0 118 #endif 119 120 #if defined(__FreeBSD__) 121 122 #include <inttypes.h> 123 #include <sys/types.h> 124 125 #else /* defined(__FreeBSD__) */ 126 127 #include <inttypes.h> 128 #include <stdint.h> 129 130 #endif /* defined(__FreeBSD__) && defined(__i386__) */ 131 132 #endif /* PROFILE_INSTRPROFILING_PORT_H_ */ 133