1 1.1 joerg /*===- InstrProfilingPort.h- Support library for PGO instrumentation ------===*\ 2 1.1 joerg |* 3 1.1 joerg |* The LLVM Compiler Infrastructure 4 1.1 joerg |* 5 1.1 joerg |* This file is distributed under the University of Illinois Open Source 6 1.1 joerg |* License. See LICENSE.TXT for details. 7 1.1 joerg |* 8 1.1 joerg \*===----------------------------------------------------------------------===*/ 9 1.1 joerg 10 1.1 joerg #ifndef PROFILE_INSTRPROFILING_PORT_H_ 11 1.1 joerg #define PROFILE_INSTRPROFILING_PORT_H_ 12 1.1 joerg 13 1.1 joerg #ifdef _MSC_VER 14 1.1 joerg #define COMPILER_RT_ALIGNAS(x) __declspec(align(x)) 15 1.1 joerg #define COMPILER_RT_VISIBILITY 16 1.1 joerg #define COMPILER_RT_WEAK __declspec(selectany) 17 1.1 joerg #elif __GNUC__ 18 1.1 joerg #define COMPILER_RT_ALIGNAS(x) __attribute__((aligned(x))) 19 1.1 joerg #define COMPILER_RT_VISIBILITY __attribute__((visibility("hidden"))) 20 1.1 joerg #define COMPILER_RT_WEAK __attribute__((weak)) 21 1.2 christos #elif defined(__lint__) 22 1.2 christos #define COMPILER_RT_ALIGNAS(x) 23 1.2 christos #define COMPILER_RT_VISIBILITY 24 1.2 christos #define COMPILER_RT_WEAK 25 1.1 joerg #endif 26 1.1 joerg 27 1.1 joerg #define COMPILER_RT_SECTION(Sect) __attribute__((section(Sect))) 28 1.1 joerg 29 1.1 joerg #if COMPILER_RT_HAS_ATOMICS == 1 30 1.1 joerg #ifdef _MSC_VER 31 1.1 joerg #include <windows.h> 32 1.1 joerg #define snprintf _snprintf 33 1.1 joerg #if defined(_WIN64) 34 1.1 joerg #define COMPILER_RT_BOOL_CMPXCHG(Ptr, OldV, NewV) \ 35 1.1 joerg (InterlockedCompareExchange64((LONGLONG volatile *)Ptr, (LONGLONG)NewV, \ 36 1.1 joerg (LONGLONG)OldV) == (LONGLONG)OldV) 37 1.1 joerg #else /* !defined(_WIN64) */ 38 1.1 joerg #define COMPILER_RT_BOOL_CMPXCHG(Ptr, OldV, NewV) \ 39 1.1 joerg (InterlockedCompareExchange((LONG volatile *)Ptr, (LONG)NewV, (LONG)OldV) == \ 40 1.1 joerg (LONG)OldV) 41 1.1 joerg #endif 42 1.1 joerg #else /* !defined(_MSC_VER) */ 43 1.1 joerg #define COMPILER_RT_BOOL_CMPXCHG(Ptr, OldV, NewV) \ 44 1.1 joerg __sync_bool_compare_and_swap(Ptr, OldV, NewV) 45 1.1 joerg #endif 46 1.1 joerg #else /* COMPILER_RT_HAS_ATOMICS != 1 */ 47 1.1 joerg #define COMPILER_RT_BOOL_CMPXCHG(Ptr, OldV, NewV) \ 48 1.1 joerg BoolCmpXchg((void **)Ptr, OldV, NewV) 49 1.1 joerg #endif 50 1.1 joerg 51 1.1 joerg #define PROF_ERR(Format, ...) \ 52 1.1 joerg if (GetEnvHook && GetEnvHook("LLVM_PROFILE_VERBOSE_ERRORS")) \ 53 1.1 joerg fprintf(stderr, Format, __VA_ARGS__); 54 1.1 joerg 55 1.1 joerg #if defined(__FreeBSD__) 56 1.1 joerg 57 1.1 joerg #include <inttypes.h> 58 1.1 joerg #include <sys/types.h> 59 1.1 joerg 60 1.1 joerg #else /* defined(__FreeBSD__) */ 61 1.1 joerg 62 1.1 joerg #include <inttypes.h> 63 1.1 joerg #include <stdint.h> 64 1.1 joerg 65 1.1 joerg #endif /* defined(__FreeBSD__) && defined(__i386__) */ 66 1.1 joerg 67 1.1 joerg #endif /* PROFILE_INSTRPROFILING_PORT_H_ */ 68