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 #define COMPILER_RT_MAX_HOSTLEN 128 26 #ifdef _MSC_VER 27 #define COMPILER_RT_GETHOSTNAME(Name, Len) gethostname(Name, Len) 28 #elif defined(__PS4__) 29 #define COMPILER_RT_GETHOSTNAME(Name, Len) (-1) 30 #else 31 #define COMPILER_RT_GETHOSTNAME(Name, Len) lprofGetHostName(Name, Len) 32 #define COMPILER_RT_HAS_UNAME 1 33 #endif 34 35 #if COMPILER_RT_HAS_ATOMICS == 1 36 #ifdef _MSC_VER 37 #include <windows.h> 38 #if _MSC_VER < 1900 39 #define snprintf _snprintf 40 #endif 41 #if defined(_WIN64) 42 #define COMPILER_RT_BOOL_CMPXCHG(Ptr, OldV, NewV) \ 43 (InterlockedCompareExchange64((LONGLONG volatile *)Ptr, (LONGLONG)NewV, \ 44 (LONGLONG)OldV) == (LONGLONG)OldV) 45 #else /* !defined(_WIN64) */ 46 #define COMPILER_RT_BOOL_CMPXCHG(Ptr, OldV, NewV) \ 47 (InterlockedCompareExchange((LONG volatile *)Ptr, (LONG)NewV, (LONG)OldV) == \ 48 (LONG)OldV) 49 #endif 50 #else /* !defined(_MSC_VER) */ 51 #define COMPILER_RT_BOOL_CMPXCHG(Ptr, OldV, NewV) \ 52 __sync_bool_compare_and_swap(Ptr, OldV, NewV) 53 #endif 54 #else /* COMPILER_RT_HAS_ATOMICS != 1 */ 55 #include "InstrProfilingUtil.h" 56 #define COMPILER_RT_BOOL_CMPXCHG(Ptr, OldV, NewV) \ 57 lprofBoolCmpXchg((void **)Ptr, OldV, NewV) 58 #endif 59 60 #define PROF_ERR(Format, ...) \ 61 if (GetEnvHook && GetEnvHook("LLVM_PROFILE_VERBOSE_ERRORS")) \ 62 fprintf(stderr, Format, __VA_ARGS__); 63 64 #if defined(__FreeBSD__) 65 66 #include <inttypes.h> 67 #include <sys/types.h> 68 69 #else /* defined(__FreeBSD__) */ 70 71 #include <inttypes.h> 72 #include <stdint.h> 73 74 #endif /* defined(__FreeBSD__) && defined(__i386__) */ 75 76 #endif /* PROFILE_INSTRPROFILING_PORT_H_ */ 77