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
|
|
|
|
#define COMPILER_RT_WEAK __declspec(selectany)
|
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))
|
2015-12-11 02:17:01 +08:00
|
|
|
#endif
|
|
|
|
|
2015-12-16 11:29:15 +08:00
|
|
|
#define COMPILER_RT_SECTION(Sect) __attribute__((section(Sect)))
|
2015-12-11 02:17:01 +08:00
|
|
|
|
2016-01-30 07:52:11 +08:00
|
|
|
#define COMPILER_RT_MAX_HOSTLEN 128
|
|
|
|
#ifdef _MSC_VER
|
|
|
|
#define COMPILER_RT_GETHOSTNAME(Name, Len) gethostname(Name, Len)
|
Add some minimal portability code paths for PS4.
Summary:
Hi David, SCE folks,
What is implemented in this patch is enough for the upstream libprofile to
work for PGO with the PS4 game codebase I tested ("game7" for you SCE
folks; this is with a standalone build of compiler-rt).
The first change, which is simple, is to stub out gethostname. PS4
doesn't have a simple analog for this that doesn't bring in extra
OS libraries, so for now we do not support `%h` expansion.
This is consistent with internal B#136272.
The second change implies future work, but is a simple change at present.
PS4 does not have `getenv`, so for now we will introduce a shim.
This obviously makes it impossible for many of the tests to be run since
they require setting `LLVM_PROFILE_FILE=`.
I see two paths forward:
1. In the tests we are already wrapping execution with `%run` and so by
setting a PS4-specific expansion for `%run` we can pass the information
in another way We can adapt the getenv shim as appropriate.
We will need to experiment with this internally.
Maggie, Phillip, Filipe? Any ideas? Maybe ping me internally since we
may need to get into some PS4 vagaries. I'm thinking a fake getenv
library that uses some side channel for communication.
2. Another possibility which is more verbose is to use a separate clang
invocation with `-profile-generate=<filename>` to set the filename in
each test.
This might require redundant clang invocations though which may be
undesirable for upstream. David, thoughts?
Also, this is a fairly libprofile-specific workaround, so it e.g.
doesn't help Filipe's ASan work.
Overall, this approach sounds like a bit of a hack to me.
Small detail:
InstrProfilingPort.h seems like the natural place for the getenv shim,
but GCDAProfiling.c needs it as well. InstrProfilingUtil.h is currently
the only header common between InstrProfilingFile.c and GCDAProfiling.c.
I can move the shim to InstrProfilingPort.h and add an include to
GCDAProfiling.c as per your preference David.
Reviewers: davidxl, MaggieYi, phillip.power, filcab
Subscribers: simon.f.whittaker, slingn, probinson, llvm-commits
Differential Revision: http://reviews.llvm.org/D17676
llvm-svn: 262527
2016-03-03 06:05:46 +08:00
|
|
|
#elif defined(__PS4__)
|
|
|
|
#define COMPILER_RT_GETHOSTNAME(Name, Len) (-1)
|
2016-01-30 07:52:11 +08:00
|
|
|
#else
|
|
|
|
#define COMPILER_RT_GETHOSTNAME(Name, Len) GetHostName(Name, Len)
|
|
|
|
#define COMPILER_RT_HAS_UNAME 1
|
|
|
|
#endif
|
|
|
|
|
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-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)
|
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)
|
2015-12-21 03:11:44 +08:00
|
|
|
#endif
|
2016-01-08 08:49:34 +08:00
|
|
|
#else /* COMPILER_RT_HAS_ATOMICS != 1 */
|
2015-12-16 11:29:15 +08:00
|
|
|
#define COMPILER_RT_BOOL_CMPXCHG(Ptr, OldV, NewV) \
|
|
|
|
BoolCmpXchg((void **)Ptr, OldV, NewV)
|
2015-12-11 03:20:25 +08:00
|
|
|
#endif
|
|
|
|
|
2015-12-16 11:29:15 +08:00
|
|
|
#define PROF_ERR(Format, ...) \
|
|
|
|
if (GetEnvHook && GetEnvHook("LLVM_PROFILE_VERBOSE_ERRORS")) \
|
|
|
|
fprintf(stderr, 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_ */
|