]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/compiler-rt/lib/profile/InstrProfilingPort.h
Merge llvm trunk r321414 to contrib/llvm.
[FreeBSD/FreeBSD.git] / contrib / compiler-rt / lib / profile / InstrProfilingPort.h
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 #elif __GNUC__
26 #define COMPILER_RT_ALIGNAS(x) __attribute__((aligned(x)))
27 #define COMPILER_RT_VISIBILITY __attribute__((visibility("hidden")))
28 #define COMPILER_RT_WEAK __attribute__((weak))
29 #define COMPILER_RT_ALLOCA __builtin_alloca
30 #define COMPILER_RT_FTRUNCATE(f,l) ftruncate(fileno(f),l)
31 #endif
32
33 #if defined(__APPLE__)
34 #define COMPILER_RT_SEG "__DATA,"
35 #else
36 #define COMPILER_RT_SEG ""
37 #endif
38
39 #ifdef _MSC_VER
40 #define COMPILER_RT_SECTION(Sect) __declspec(allocate(Sect))
41 #else
42 #define COMPILER_RT_SECTION(Sect) __attribute__((section(Sect)))
43 #endif
44
45 #define COMPILER_RT_MAX_HOSTLEN 128
46 #ifdef __ORBIS__
47 #define COMPILER_RT_GETHOSTNAME(Name, Len) ((void)(Name), (void)(Len), (-1))
48 #else
49 #define COMPILER_RT_GETHOSTNAME(Name, Len) lprofGetHostName(Name, Len)
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 #if defined(_WIN32)
88 #define DIR_SEPARATOR '\\'
89 #define DIR_SEPARATOR_2 '/'
90 #else
91 #define DIR_SEPARATOR '/'
92 #endif
93
94 #ifndef DIR_SEPARATOR_2
95 #define IS_DIR_SEPARATOR(ch) ((ch) == DIR_SEPARATOR)
96 #else /* DIR_SEPARATOR_2 */
97 #define IS_DIR_SEPARATOR(ch)                                                   \
98   (((ch) == DIR_SEPARATOR) || ((ch) == DIR_SEPARATOR_2))
99 #endif /* DIR_SEPARATOR_2 */
100
101 #define PROF_ERR(Format, ...)                                                  \
102   fprintf(stderr, "LLVM Profile Error: " Format, __VA_ARGS__);
103
104 #define PROF_WARN(Format, ...)                                                 \
105   fprintf(stderr, "LLVM Profile Warning: " Format, __VA_ARGS__);
106
107 #define PROF_NOTE(Format, ...)                                                 \
108   fprintf(stderr, "LLVM Profile Note: " Format, __VA_ARGS__);
109
110 #ifndef MAP_FILE
111 #define MAP_FILE 0
112 #endif
113
114 #ifndef O_BINARY
115 #define O_BINARY 0
116 #endif
117
118 #if defined(__FreeBSD__)
119
120 #include <inttypes.h>
121 #include <sys/types.h>
122
123 #else /* defined(__FreeBSD__) */
124
125 #include <inttypes.h>
126 #include <stdint.h>
127
128 #endif /* defined(__FreeBSD__) && defined(__i386__) */
129
130 #endif /* PROFILE_INSTRPROFILING_PORT_H_ */