2015-12-11 02:17:01 +08:00
|
|
|
/*===- InstrProfilingPort.h- Support library for PGO instrumentation ------===*\
|
|
|
|
|*
|
|
|
|
|* The LLVM Compiler Infrastructure
|
|
|
|
|*
|
|
|
|
|* This file is distributed under the University of Illinois Open Source
|
|
|
|
|* License. See LICENSE.TXT for details.
|
|
|
|
|*
|
|
|
|
\*===----------------------------------------------------------------------===*/
|
|
|
|
|
|
|
|
#ifndef PROFILE_INSTRPROFILING_PORT_H_
|
|
|
|
#define PROFILE_INSTRPROFILING_PORT_H_
|
|
|
|
|
|
|
|
#ifdef _MSC_VER
|
2015-12-18 07:37:30 +08:00
|
|
|
#define COMPILER_RT_ALIGNAS(x) __declspec(align(x))
|
2015-12-16 11:29:15 +08:00
|
|
|
#define COMPILER_RT_VISIBILITY
|
2016-06-18 02:12:50 +08:00
|
|
|
/* FIXME: selectany does not have the same semantics as weak. */
|
2015-12-16 11:29:15 +08:00
|
|
|
#define COMPILER_RT_WEAK __declspec(selectany)
|
2016-06-09 07:43:56 +08:00
|
|
|
/* Need to include <windows.h> */
|
2016-05-16 00:41:58 +08:00
|
|
|
#define COMPILER_RT_ALLOCA _alloca
|
2016-06-09 07:43:56 +08:00
|
|
|
/* Need to include <stdio.h> and <io.h> */
|
|
|
|
#define COMPILER_RT_FTRUNCATE(f,l) _chsize(_fileno(f),l)
|
2015-12-11 02:17:01 +08:00
|
|
|
#elif __GNUC__
|
2015-12-16 11:29:15 +08:00
|
|
|
#define COMPILER_RT_ALIGNAS(x) __attribute__((aligned(x)))
|
|
|
|
#define COMPILER_RT_VISIBILITY __attribute__((visibility("hidden")))
|
|
|
|
#define COMPILER_RT_WEAK __attribute__((weak))
|
2016-05-16 00:41:58 +08:00
|
|
|
#define COMPILER_RT_ALLOCA __builtin_alloca
|
2016-06-09 07:43:56 +08:00
|
|
|
#define COMPILER_RT_FTRUNCATE(f,l) ftruncate(fileno(f),l)
|
2015-12-11 02:17:01 +08:00
|
|
|
#endif
|
|
|
|
|
2016-05-27 06:15:12 +08:00
|
|
|
#if defined(__APPLE__)
|
|
|
|
#define COMPILER_RT_SEG "__DATA,"
|
|
|
|
#else
|
|
|
|
#define COMPILER_RT_SEG ""
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef _MSC_VER
|
|
|
|
#define COMPILER_RT_SECTION(Sect) __declspec(allocate(Sect))
|
|
|
|
#else
|
2015-12-16 11:29:15 +08:00
|
|
|
#define COMPILER_RT_SECTION(Sect) __attribute__((section(Sect)))
|
2016-05-27 06:15:12 +08:00
|
|
|
#endif
|
2015-12-11 02:17:01 +08:00
|
|
|
|
2016-01-30 07:52:11 +08:00
|
|
|
#define COMPILER_RT_MAX_HOSTLEN 128
|
2016-11-29 23:24:00 +08:00
|
|
|
#ifdef __ORBIS__
|
2016-05-27 14:15:13 +08:00
|
|
|
#define COMPILER_RT_GETHOSTNAME(Name, Len) ((void)(Name), (void)(Len), (-1))
|
2016-01-30 07:52:11 +08:00
|
|
|
#else
|
2016-03-06 12:18:13 +08:00
|
|
|
#define COMPILER_RT_GETHOSTNAME(Name, Len) lprofGetHostName(Name, Len)
|
2016-11-29 23:24:00 +08:00
|
|
|
#ifndef _MSC_VER
|
2016-01-30 07:52:11 +08:00
|
|
|
#define COMPILER_RT_HAS_UNAME 1
|
|
|
|
#endif
|
2016-11-29 23:24:00 +08:00
|
|
|
#endif
|
2016-01-30 07:52:11 +08:00
|
|
|
|
2015-12-11 03:20:25 +08:00
|
|
|
#if COMPILER_RT_HAS_ATOMICS == 1
|
2015-12-21 03:11:44 +08:00
|
|
|
#ifdef _MSC_VER
|
|
|
|
#include <windows.h>
|
2016-01-30 15:14:31 +08:00
|
|
|
#if _MSC_VER < 1900
|
2016-01-29 02:37:43 +08:00
|
|
|
#define snprintf _snprintf
|
2016-01-30 15:14:31 +08:00
|
|
|
#endif
|
2015-12-21 03:55:15 +08:00
|
|
|
#if defined(_WIN64)
|
2015-12-21 03:11:44 +08:00
|
|
|
#define COMPILER_RT_BOOL_CMPXCHG(Ptr, OldV, NewV) \
|
|
|
|
(InterlockedCompareExchange64((LONGLONG volatile *)Ptr, (LONGLONG)NewV, \
|
|
|
|
(LONGLONG)OldV) == (LONGLONG)OldV)
|
2016-05-17 07:01:03 +08:00
|
|
|
#define COMPILER_RT_PTR_FETCH_ADD(DomType, PtrVar, PtrIncr) \
|
|
|
|
(DomType *)InterlockedExchangeAdd64((LONGLONG volatile *)&PtrVar, \
|
|
|
|
(LONGLONG)sizeof(DomType) * PtrIncr)
|
2016-01-08 08:49:34 +08:00
|
|
|
#else /* !defined(_WIN64) */
|
2015-12-21 03:55:15 +08:00
|
|
|
#define COMPILER_RT_BOOL_CMPXCHG(Ptr, OldV, NewV) \
|
|
|
|
(InterlockedCompareExchange((LONG volatile *)Ptr, (LONG)NewV, (LONG)OldV) == \
|
|
|
|
(LONG)OldV)
|
2016-05-17 07:01:03 +08:00
|
|
|
#define COMPILER_RT_PTR_FETCH_ADD(DomType, PtrVar, PtrIncr) \
|
|
|
|
(DomType *)InterlockedExchangeAdd((LONG volatile *)&PtrVar, \
|
|
|
|
(LONG)sizeof(DomType) * PtrIncr)
|
2015-12-21 03:11:44 +08:00
|
|
|
#endif
|
2016-01-08 08:49:34 +08:00
|
|
|
#else /* !defined(_MSC_VER) */
|
2015-12-16 11:29:15 +08:00
|
|
|
#define COMPILER_RT_BOOL_CMPXCHG(Ptr, OldV, NewV) \
|
2015-12-11 03:20:25 +08:00
|
|
|
__sync_bool_compare_and_swap(Ptr, OldV, NewV)
|
2016-05-17 07:01:03 +08:00
|
|
|
#define COMPILER_RT_PTR_FETCH_ADD(DomType, PtrVar, PtrIncr) \
|
|
|
|
(DomType *)__sync_fetch_and_add((long *)&PtrVar, sizeof(DomType) * PtrIncr)
|
2015-12-21 03:11:44 +08:00
|
|
|
#endif
|
2016-01-08 08:49:34 +08:00
|
|
|
#else /* COMPILER_RT_HAS_ATOMICS != 1 */
|
2016-03-07 21:42:17 +08:00
|
|
|
#include "InstrProfilingUtil.h"
|
2015-12-16 11:29:15 +08:00
|
|
|
#define COMPILER_RT_BOOL_CMPXCHG(Ptr, OldV, NewV) \
|
2016-03-06 12:18:13 +08:00
|
|
|
lprofBoolCmpXchg((void **)Ptr, OldV, NewV)
|
2016-05-17 07:01:03 +08:00
|
|
|
#define COMPILER_RT_PTR_FETCH_ADD(DomType, PtrVar, PtrIncr) \
|
|
|
|
(DomType *)lprofPtrFetchAdd((void **)&PtrVar, sizeof(DomType) * PtrIncr)
|
2015-12-11 03:20:25 +08:00
|
|
|
#endif
|
|
|
|
|
2016-07-16 02:48:14 +08:00
|
|
|
#if defined(_WIN32)
|
|
|
|
#define DIR_SEPARATOR '\\'
|
|
|
|
#define DIR_SEPARATOR_2 '/'
|
|
|
|
#else
|
|
|
|
#define DIR_SEPARATOR '/'
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef DIR_SEPARATOR_2
|
|
|
|
#define IS_DIR_SEPARATOR(ch) ((ch) == DIR_SEPARATOR)
|
|
|
|
#else /* DIR_SEPARATOR_2 */
|
|
|
|
#define IS_DIR_SEPARATOR(ch) \
|
|
|
|
(((ch) == DIR_SEPARATOR) || ((ch) == DIR_SEPARATOR_2))
|
|
|
|
#endif /* DIR_SEPARATOR_2 */
|
|
|
|
|
2015-12-16 11:29:15 +08:00
|
|
|
#define PROF_ERR(Format, ...) \
|
2016-05-20 13:15:42 +08:00
|
|
|
fprintf(stderr, "LLVM Profile Error: " Format, __VA_ARGS__);
|
|
|
|
|
|
|
|
#define PROF_WARN(Format, ...) \
|
|
|
|
fprintf(stderr, "LLVM Profile Warning: " Format, __VA_ARGS__);
|
2015-12-16 11:29:15 +08:00
|
|
|
|
2016-06-11 04:35:01 +08:00
|
|
|
#define PROF_NOTE(Format, ...) \
|
|
|
|
fprintf(stderr, "LLVM Profile Note: " Format, __VA_ARGS__);
|
|
|
|
|
2015-12-31 03:18:55 +08:00
|
|
|
#if defined(__FreeBSD__)
|
2015-12-11 02:17:01 +08:00
|
|
|
|
2015-12-31 03:18:55 +08:00
|
|
|
#include <inttypes.h>
|
|
|
|
#include <sys/types.h>
|
2015-12-11 02:17:01 +08:00
|
|
|
|
2015-12-31 03:18:55 +08:00
|
|
|
#else /* defined(__FreeBSD__) */
|
2015-12-11 02:17:01 +08:00
|
|
|
|
|
|
|
#include <inttypes.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
|
|
|
|
#endif /* defined(__FreeBSD__) && defined(__i386__) */
|
|
|
|
|
|
|
|
#endif /* PROFILE_INSTRPROFILING_PORT_H_ */
|