]>
git.proxmox.com Git - rustc.git/blob - src/compiler-rt/lib/profile/InstrProfilingPort.h
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 #ifndef PROFILE_INSTRPROFILING_PORT_H_
11 #define PROFILE_INSTRPROFILING_PORT_H_
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)
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)
30 #if defined(__APPLE__)
31 #define COMPILER_RT_SEG "__DATA,"
33 #define COMPILER_RT_SEG ""
37 #define COMPILER_RT_SECTION(Sect) __declspec(allocate(Sect))
39 #define COMPILER_RT_SECTION(Sect) __attribute__((section(Sect)))
42 #define COMPILER_RT_MAX_HOSTLEN 128
44 #define COMPILER_RT_GETHOSTNAME(Name, Len) ((void)(Name), (void)(Len), (-1))
46 #define COMPILER_RT_GETHOSTNAME(Name, Len) lprofGetHostName(Name, Len)
48 #define COMPILER_RT_HAS_UNAME 1
52 #if COMPILER_RT_HAS_ATOMICS == 1
56 #define snprintf _snprintf
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) == \
69 #define COMPILER_RT_PTR_FETCH_ADD(DomType, PtrVar, PtrIncr) \
70 (DomType *)InterlockedExchangeAdd((LONG volatile *)&PtrVar, \
71 (LONG)sizeof(DomType) * PtrIncr)
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)
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)
88 #define DIR_SEPARATOR '\\'
89 #define DIR_SEPARATOR_2 '/'
91 #define DIR_SEPARATOR '/'
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 */
101 #define PROF_ERR(Format, ...) \
102 fprintf(stderr, "LLVM Profile Error: " Format, __VA_ARGS__);
104 #define PROF_WARN(Format, ...) \
105 fprintf(stderr, "LLVM Profile Warning: " Format, __VA_ARGS__);
107 #define PROF_NOTE(Format, ...) \
108 fprintf(stderr, "LLVM Profile Note: " Format, __VA_ARGS__);
110 #if defined(__FreeBSD__)
112 #include <inttypes.h>
113 #include <sys/types.h>
115 #else /* defined(__FreeBSD__) */
117 #include <inttypes.h>
120 #endif /* defined(__FreeBSD__) && defined(__i386__) */
122 #endif /* PROFILE_INSTRPROFILING_PORT_H_ */