]> git.proxmox.com Git - rustc.git/blob - src/libcompiler_builtins/compiler-rt/lib/profile/InstrProfilingPort.h
New upstream version 1.20.0+dfsg1
[rustc.git] / src / libcompiler_builtins / 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 #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 /* FIXME: selectany does not have the same semantics as weak. */
17 #define COMPILER_RT_WEAK __declspec(selectany)
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)
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))
26 #define COMPILER_RT_ALLOCA __builtin_alloca
27 #define COMPILER_RT_FTRUNCATE(f,l) ftruncate(fileno(f),l)
28 #endif
29
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
39 #define COMPILER_RT_SECTION(Sect) __attribute__((section(Sect)))
40 #endif
41
42 #define COMPILER_RT_MAX_HOSTLEN 128
43 #ifdef __ORBIS__
44 #define COMPILER_RT_GETHOSTNAME(Name, Len) ((void)(Name), (void)(Len), (-1))
45 #else
46 #define COMPILER_RT_GETHOSTNAME(Name, Len) lprofGetHostName(Name, Len)
47 #ifndef _MSC_VER
48 #define COMPILER_RT_HAS_UNAME 1
49 #endif
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 #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_ */