blob: 94c2e13b46ecb171820ab4f0d0c87bf334de86cf [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 Li6c7bddb2016-05-15 16:41:58 +000017#define COMPILER_RT_ALLOCA _alloca
Xinliang David Li26bcd192015-12-10 18:17:01 +000018#elif __GNUC__
Xinliang David Liabfd5532015-12-16 03:29:15 +000019#define COMPILER_RT_ALIGNAS(x) __attribute__((aligned(x)))
20#define COMPILER_RT_VISIBILITY __attribute__((visibility("hidden")))
21#define COMPILER_RT_WEAK __attribute__((weak))
Xinliang David Li6c7bddb2016-05-15 16:41:58 +000022#define COMPILER_RT_ALLOCA __builtin_alloca
Xinliang David Li26bcd192015-12-10 18:17:01 +000023#endif
24
Xinliang David Liabfd5532015-12-16 03:29:15 +000025#define COMPILER_RT_SECTION(Sect) __attribute__((section(Sect)))
26
Vedant Kumara06e8ca2016-01-29 23:52:11 +000027#define COMPILER_RT_MAX_HOSTLEN 128
28#ifdef _MSC_VER
29#define COMPILER_RT_GETHOSTNAME(Name, Len) gethostname(Name, Len)
Paul Robinson595b9692016-05-16 17:22:32 +000030#elif defined(__ORBIS__)
Sean Silva6470f762016-03-02 22:05:46 +000031#define COMPILER_RT_GETHOSTNAME(Name, Len) (-1)
Vedant Kumara06e8ca2016-01-29 23:52:11 +000032#else
Xinliang David Licf1a8d62016-03-06 04:18:13 +000033#define COMPILER_RT_GETHOSTNAME(Name, Len) lprofGetHostName(Name, Len)
Vedant Kumara06e8ca2016-01-29 23:52:11 +000034#define COMPILER_RT_HAS_UNAME 1
35#endif
36
Xinliang David Liabfd5532015-12-16 03:29:15 +000037#if COMPILER_RT_HAS_ATOMICS == 1
Xinliang David Lif82944d2015-12-20 19:11:44 +000038#ifdef _MSC_VER
39#include <windows.h>
Ismail Donmez7bf46bf2016-01-30 07:14:31 +000040#if _MSC_VER < 1900
Xinliang David Liec8d0862016-01-28 18:37:43 +000041#define snprintf _snprintf
Ismail Donmez7bf46bf2016-01-30 07:14:31 +000042#endif
Xinliang David Lid1c84b02015-12-20 19:55:15 +000043#if defined(_WIN64)
Xinliang David Lif82944d2015-12-20 19:11:44 +000044#define COMPILER_RT_BOOL_CMPXCHG(Ptr, OldV, NewV) \
45 (InterlockedCompareExchange64((LONGLONG volatile *)Ptr, (LONGLONG)NewV, \
46 (LONGLONG)OldV) == (LONGLONG)OldV)
Vedant Kumar750a6292016-01-08 00:49:34 +000047#else /* !defined(_WIN64) */
Xinliang David Lid1c84b02015-12-20 19:55:15 +000048#define COMPILER_RT_BOOL_CMPXCHG(Ptr, OldV, NewV) \
49 (InterlockedCompareExchange((LONG volatile *)Ptr, (LONG)NewV, (LONG)OldV) == \
50 (LONG)OldV)
Xinliang David Lif82944d2015-12-20 19:11:44 +000051#endif
Vedant Kumar750a6292016-01-08 00:49:34 +000052#else /* !defined(_MSC_VER) */
Xinliang David Liabfd5532015-12-16 03:29:15 +000053#define COMPILER_RT_BOOL_CMPXCHG(Ptr, OldV, NewV) \
54 __sync_bool_compare_and_swap(Ptr, OldV, NewV)
Xinliang David Lif82944d2015-12-20 19:11:44 +000055#endif
Vedant Kumar750a6292016-01-08 00:49:34 +000056#else /* COMPILER_RT_HAS_ATOMICS != 1 */
Filipe Cabecinhas19aeaf72016-03-07 13:42:17 +000057#include "InstrProfilingUtil.h"
Xinliang David Liabfd5532015-12-16 03:29:15 +000058#define COMPILER_RT_BOOL_CMPXCHG(Ptr, OldV, NewV) \
Xinliang David Licf1a8d62016-03-06 04:18:13 +000059 lprofBoolCmpXchg((void **)Ptr, OldV, NewV)
Xinliang David Liabfd5532015-12-16 03:29:15 +000060#endif
Xinliang David Li26bcd192015-12-10 18:17:01 +000061
62#define PROF_ERR(Format, ...) \
63 if (GetEnvHook && GetEnvHook("LLVM_PROFILE_VERBOSE_ERRORS")) \
64 fprintf(stderr, Format, __VA_ARGS__);
65
Xinliang David Li3e0e6e72015-12-30 19:18:55 +000066#if defined(__FreeBSD__)
Xinliang David Li26bcd192015-12-10 18:17:01 +000067
Xinliang David Li3e0e6e72015-12-30 19:18:55 +000068#include <inttypes.h>
69#include <sys/types.h>
Xinliang David Li26bcd192015-12-10 18:17:01 +000070
Xinliang David Li3e0e6e72015-12-30 19:18:55 +000071#else /* defined(__FreeBSD__) */
Xinliang David Li26bcd192015-12-10 18:17:01 +000072
73#include <inttypes.h>
74#include <stdint.h>
75
76#endif /* defined(__FreeBSD__) && defined(__i386__) */
77
78#endif /* PROFILE_INSTRPROFILING_PORT_H_ */