]>
Commit | Line | Data |
---|---|---|
3157f602 XL |
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 | |
5bcae85e | 16 | /* FIXME: selectany does not have the same semantics as weak. */ |
3157f602 | 17 | #define COMPILER_RT_WEAK __declspec(selectany) |
5bcae85e SL |
18 | /* Need to include <windows.h> */ |
19 | #define COMPILER_RT_ALLOCA _alloca | |
20 | /* Need to include <stdio.h> and <io.h> */ | |
21 | #define COMPILER_RT_FTRUNCATE(f,l) _chsize(_fileno(f),l) | |
3157f602 XL |
22 | #elif __GNUC__ |
23 | #define COMPILER_RT_ALIGNAS(x) __attribute__((aligned(x))) | |
24 | #define COMPILER_RT_VISIBILITY __attribute__((visibility("hidden"))) | |
25 | #define COMPILER_RT_WEAK __attribute__((weak)) | |
5bcae85e SL |
26 | #define COMPILER_RT_ALLOCA __builtin_alloca |
27 | #define COMPILER_RT_FTRUNCATE(f,l) ftruncate(fileno(f),l) | |
3157f602 XL |
28 | #endif |
29 | ||
5bcae85e SL |
30 | #if defined(__APPLE__) |
31 | #define COMPILER_RT_SEG "__DATA," | |
32 | #else | |
33 | #define COMPILER_RT_SEG "" | |
34 | #endif | |
35 | ||
36 | #ifdef _MSC_VER | |
37 | #define COMPILER_RT_SECTION(Sect) __declspec(allocate(Sect)) | |
38 | #else | |
3157f602 | 39 | #define COMPILER_RT_SECTION(Sect) __attribute__((section(Sect))) |
5bcae85e SL |
40 | #endif |
41 | ||
42 | #define COMPILER_RT_MAX_HOSTLEN 128 | |
43 | #ifdef _MSC_VER | |
44 | #define COMPILER_RT_GETHOSTNAME(Name, Len) gethostname(Name, Len) | |
45 | #elif defined(__ORBIS__) | |
46 | #define COMPILER_RT_GETHOSTNAME(Name, Len) ((void)(Name), (void)(Len), (-1)) | |
47 | #else | |
48 | #define COMPILER_RT_GETHOSTNAME(Name, Len) lprofGetHostName(Name, Len) | |
49 | #define COMPILER_RT_HAS_UNAME 1 | |
50 | #endif | |
3157f602 XL |
51 | |
52 | #if COMPILER_RT_HAS_ATOMICS == 1 | |
53 | #ifdef _MSC_VER | |
54 | #include <windows.h> | |
5bcae85e SL |
55 | #if _MSC_VER < 1900 |
56 | #define snprintf _snprintf | |
57 | #endif | |
3157f602 XL |
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) | |
5bcae85e SL |
62 | #define COMPILER_RT_PTR_FETCH_ADD(DomType, PtrVar, PtrIncr) \ |
63 | (DomType *)InterlockedExchangeAdd64((LONGLONG volatile *)&PtrVar, \ | |
64 | (LONGLONG)sizeof(DomType) * PtrIncr) | |
3157f602 XL |
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) | |
5bcae85e SL |
69 | #define COMPILER_RT_PTR_FETCH_ADD(DomType, PtrVar, PtrIncr) \ |
70 | (DomType *)InterlockedExchangeAdd((LONG volatile *)&PtrVar, \ | |
71 | (LONG)sizeof(DomType) * PtrIncr) | |
3157f602 XL |
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) | |
5bcae85e SL |
76 | #define COMPILER_RT_PTR_FETCH_ADD(DomType, PtrVar, PtrIncr) \ |
77 | (DomType *)__sync_fetch_and_add((long *)&PtrVar, sizeof(DomType) * PtrIncr) | |
3157f602 XL |
78 | #endif |
79 | #else /* COMPILER_RT_HAS_ATOMICS != 1 */ | |
5bcae85e | 80 | #include "InstrProfilingUtil.h" |
3157f602 | 81 | #define COMPILER_RT_BOOL_CMPXCHG(Ptr, OldV, NewV) \ |
5bcae85e SL |
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 '/' | |
3157f602 XL |
92 | #endif |
93 | ||
5bcae85e SL |
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 | ||
3157f602 | 101 | #define PROF_ERR(Format, ...) \ |
5bcae85e SL |
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__); | |
3157f602 XL |
109 | |
110 | #if defined(__FreeBSD__) | |
111 | ||
112 | #include <inttypes.h> | |
113 | #include <sys/types.h> | |
114 | ||
115 | #else /* defined(__FreeBSD__) */ | |
116 | ||
117 | #include <inttypes.h> | |
118 | #include <stdint.h> | |
119 | ||
120 | #endif /* defined(__FreeBSD__) && defined(__i386__) */ | |
121 | ||
122 | #endif /* PROFILE_INSTRPROFILING_PORT_H_ */ |