1 /*===- InstrProfilingPort.h- Support library for PGO instrumentation ------===*\
3 |* The LLVM Compiler Infrastructure
5 |* This file is distributed under the University of Illinois Open Source
6 |* License. See LICENSE.TXT for details.
8 \*===----------------------------------------------------------------------===*/
10 /* This header must be included after all others so it can provide fallback
11 definitions for stuff missing in system headers. */
13 #ifndef PROFILE_INSTRPROFILING_PORT_H_
14 #define PROFILE_INSTRPROFILING_PORT_H_
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
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))
35 #if defined(__APPLE__)
36 #define COMPILER_RT_SEG "__DATA,"
38 #define COMPILER_RT_SEG ""
42 #define COMPILER_RT_SECTION(Sect) __declspec(allocate(Sect))
44 #define COMPILER_RT_SECTION(Sect) __attribute__((section(Sect)))
47 #define COMPILER_RT_MAX_HOSTLEN 128
49 #define COMPILER_RT_GETHOSTNAME(Name, Len) ((void)(Name), (void)(Len), (-1))
51 #define COMPILER_RT_GETHOSTNAME(Name, Len) lprofGetHostName(Name, Len)
54 #if COMPILER_RT_HAS_ATOMICS == 1
58 #define snprintf _snprintf
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) == \
71 #define COMPILER_RT_PTR_FETCH_ADD(DomType, PtrVar, PtrIncr) \
72 (DomType *)InterlockedExchangeAdd((LONG volatile *)&PtrVar, \
73 (LONG)sizeof(DomType) * PtrIncr)
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)
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)
90 #define DIR_SEPARATOR '\\'
91 #define DIR_SEPARATOR_2 '/'
93 #define DIR_SEPARATOR '/'
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 */
103 #define PROF_ERR(Format, ...) \
104 fprintf(stderr, "LLVM Profile Error: " Format, __VA_ARGS__);
106 #define PROF_WARN(Format, ...) \
107 fprintf(stderr, "LLVM Profile Warning: " Format, __VA_ARGS__);
109 #define PROF_NOTE(Format, ...) \
110 fprintf(stderr, "LLVM Profile Note: " Format, __VA_ARGS__);
120 #if defined(__FreeBSD__)
122 #include <inttypes.h>
123 #include <sys/types.h>
125 #else /* defined(__FreeBSD__) */
127 #include <inttypes.h>
130 #endif /* defined(__FreeBSD__) && defined(__i386__) */
132 #endif /* PROFILE_INSTRPROFILING_PORT_H_ */