blob: 5da814a4a3d73f635f0837098322c47d76c51cf0 [file] [log] [blame]
Xinliang David Li26bcd192015-12-10 18:17:01 +00001/*===- 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
Xinliang David Li01d06102015-12-17 23:37:30 +000014#define COMPILER_RT_ALIGNAS(x) __declspec(align(x))
Xinliang David Liabfd5532015-12-16 03:29:15 +000015#define COMPILER_RT_VISIBILITY
16#define COMPILER_RT_WEAK __declspec(selectany)
Xinliang David Li26bcd192015-12-10 18:17:01 +000017#elif __GNUC__
Xinliang David Liabfd5532015-12-16 03:29:15 +000018#define COMPILER_RT_ALIGNAS(x) __attribute__((aligned(x)))
19#define COMPILER_RT_VISIBILITY __attribute__((visibility("hidden")))
20#define COMPILER_RT_WEAK __attribute__((weak))
Xinliang David Li26bcd192015-12-10 18:17:01 +000021#endif
22
Xinliang David Liabfd5532015-12-16 03:29:15 +000023#define COMPILER_RT_SECTION(Sect) __attribute__((section(Sect)))
24
25#if COMPILER_RT_HAS_ATOMICS == 1
Xinliang David Lif82944d2015-12-20 19:11:44 +000026#ifdef _MSC_VER
27#include <windows.h>
Xinliang David Lid1c84b02015-12-20 19:55:15 +000028#if defined(_WIN64)
Xinliang David Lif82944d2015-12-20 19:11:44 +000029#define COMPILER_RT_BOOL_CMPXCHG(Ptr, OldV, NewV) \
30 (InterlockedCompareExchange64((LONGLONG volatile *)Ptr, (LONGLONG)NewV, \
31 (LONGLONG)OldV) == (LONGLONG)OldV)
Xinliang David Lid1c84b02015-12-20 19:55:15 +000032#else
33#define COMPILER_RT_BOOL_CMPXCHG(Ptr, OldV, NewV) \
34 (InterlockedCompareExchange((LONG volatile *)Ptr, (LONG)NewV, (LONG)OldV) == \
35 (LONG)OldV)
Xinliang David Lif82944d2015-12-20 19:11:44 +000036#endif
37#else
Xinliang David Liabfd5532015-12-16 03:29:15 +000038#define COMPILER_RT_BOOL_CMPXCHG(Ptr, OldV, NewV) \
39 __sync_bool_compare_and_swap(Ptr, OldV, NewV)
Xinliang David Lif82944d2015-12-20 19:11:44 +000040#endif
Xinliang David Liabfd5532015-12-16 03:29:15 +000041#else
42#define COMPILER_RT_BOOL_CMPXCHG(Ptr, OldV, NewV) \
43 BoolCmpXchg((void **)Ptr, OldV, NewV)
44#endif
Xinliang David Li26bcd192015-12-10 18:17:01 +000045
46#define PROF_ERR(Format, ...) \
47 if (GetEnvHook && GetEnvHook("LLVM_PROFILE_VERBOSE_ERRORS")) \
48 fprintf(stderr, Format, __VA_ARGS__);
49
Xinliang David Li3e0e6e72015-12-30 19:18:55 +000050#if defined(__FreeBSD__)
Xinliang David Li26bcd192015-12-10 18:17:01 +000051
Xinliang David Li3e0e6e72015-12-30 19:18:55 +000052#include <inttypes.h>
53#include <sys/types.h>
Xinliang David Li26bcd192015-12-10 18:17:01 +000054
Xinliang David Li3e0e6e72015-12-30 19:18:55 +000055#else /* defined(__FreeBSD__) */
Xinliang David Li26bcd192015-12-10 18:17:01 +000056
57#include <inttypes.h>
58#include <stdint.h>
59
60#endif /* defined(__FreeBSD__) && defined(__i386__) */
61
62#endif /* PROFILE_INSTRPROFILING_PORT_H_ */