diff options
author | Xinliang David Li <davidxl@google.com> | 2015-11-23 04:38:17 +0000 |
---|---|---|
committer | Xinliang David Li <davidxl@google.com> | 2015-11-23 04:38:17 +0000 |
commit | c507191b72eb2ecd965a38b1805a349b5b227ee9 (patch) | |
tree | c516a1a96b973872ed91be6c440b052b246b89c1 /lib/profile | |
parent | 9160d53d5927e5e3dd9642027c038ed0393fed6d (diff) |
[PGO] Compiler-rt cleanup -- introduces macros for various macros
This makes code more readable and be made more portable in the future.
There is no functional change.
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@253845 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/profile')
-rw-r--r-- | lib/profile/InstrProfiling.c | 18 | ||||
-rw-r--r-- | lib/profile/InstrProfiling.h | 5 | ||||
-rw-r--r-- | lib/profile/InstrProfilingBuffer.c | 15 | ||||
-rw-r--r-- | lib/profile/InstrProfilingFile.c | 14 | ||||
-rw-r--r-- | lib/profile/InstrProfilingPlatformDarwin.c | 37 | ||||
-rw-r--r-- | lib/profile/InstrProfilingPlatformLinux.c | 38 | ||||
-rw-r--r-- | lib/profile/InstrProfilingPlatformOther.c | 24 | ||||
-rw-r--r-- | lib/profile/InstrProfilingUtil.c | 3 | ||||
-rw-r--r-- | lib/profile/InstrProfilingWriter.c | 9 |
9 files changed, 75 insertions, 88 deletions
diff --git a/lib/profile/InstrProfiling.c b/lib/profile/InstrProfiling.c index 75daeeb87..54103a0d6 100644 --- a/lib/profile/InstrProfiling.c +++ b/lib/profile/InstrProfiling.c @@ -17,7 +17,7 @@ typedef struct ValueProfNode { struct ValueProfNode *Next; } ValueProfNode; -__attribute__((visibility("hidden"))) uint64_t __llvm_profile_get_magic(void) { +LLVM_LIBRARY_VISIBILITY uint64_t __llvm_profile_get_magic(void) { /* Magic number to detect file format and endianness. * * Use 255 at one end, since no UTF-8 file can use that character. Avoid 0, @@ -36,18 +36,17 @@ __attribute__((visibility("hidden"))) uint64_t __llvm_profile_get_magic(void) { /* Return the number of bytes needed to add to SizeInBytes to make it * the result a multiple of 8. */ -__attribute__((visibility("hidden"))) uint8_t +LLVM_LIBRARY_VISIBILITY uint8_t __llvm_profile_get_num_padding_bytes(uint64_t SizeInBytes) { return 7 & (sizeof(uint64_t) - SizeInBytes % sizeof(uint64_t)); } -__attribute__((visibility("hidden"))) uint64_t -__llvm_profile_get_version(void) { +LLVM_LIBRARY_VISIBILITY uint64_t __llvm_profile_get_version(void) { /* This should be bumped any time the output format changes. */ return 2; } -__attribute__((visibility("hidden"))) void __llvm_profile_reset_counters(void) { +LLVM_LIBRARY_VISIBILITY void __llvm_profile_reset_counters(void) { uint64_t *I = __llvm_profile_begin_counters(); uint64_t *E = __llvm_profile_end_counters(); @@ -82,10 +81,9 @@ __attribute__((visibility("hidden"))) void __llvm_profile_reset_counters(void) { static uint64_t TotalValueDataSize = 0; #ifdef _MIPS_ARCH -__attribute__((visibility("hidden"))) void +LLVM_LIBRARY_VISIBILITY void __llvm_profile_instrument_target(uint64_t TargetValue, void *Data_, - uint32_t CounterIndex) { -} + uint32_t CounterIndex) {} #else @@ -119,7 +117,7 @@ static int allocateValueProfileCounters(__llvm_profile_data *Data) { return 1; } -__attribute__((visibility("hidden"))) void +LLVM_LIBRARY_VISIBILITY void __llvm_profile_instrument_target(uint64_t TargetValue, void *Data, uint32_t CounterIndex) { @@ -172,7 +170,7 @@ __llvm_profile_instrument_target(uint64_t TargetValue, void *Data, } #endif -__attribute__((visibility("hidden"))) uint64_t +LLVM_LIBRARY_VISIBILITY uint64_t __llvm_profile_gather_value_data(uint8_t **VDataArray) { if (!VDataArray || 0 == TotalValueDataSize) diff --git a/lib/profile/InstrProfiling.h b/lib/profile/InstrProfiling.h index cc1fcb16a..c8178fce9 100644 --- a/lib/profile/InstrProfiling.h +++ b/lib/profile/InstrProfiling.h @@ -13,9 +13,12 @@ #ifdef _MSC_VER # define LLVM_ALIGNAS(x) __declspec(align(x)) #elif __GNUC__ -# define LLVM_ALIGNAS(x) __attribute__((aligned(x))) +#define LLVM_ALIGNAS(x) __attribute__((aligned(x))) #endif +#define LLVM_LIBRARY_VISIBILITY __attribute__((visibility("hidden"))) +#define LLVM_SECTION(Sect) __attribute__((section(Sect))) + #if defined(__FreeBSD__) && defined(__i386__) /* System headers define 'size_t' incorrectly on x64 FreeBSD (prior to diff --git a/lib/profile/InstrProfilingBuffer.c b/lib/profile/InstrProfilingBuffer.c index 130b30e7a..4f8412687 100644 --- a/lib/profile/InstrProfilingBuffer.c +++ b/lib/profile/InstrProfilingBuffer.c @@ -12,7 +12,7 @@ #include <string.h> -__attribute__((visibility("hidden"))) +LLVM_LIBRARY_VISIBILITY uint64_t __llvm_profile_get_size_for_buffer(void) { const __llvm_profile_data *DataBegin = __llvm_profile_begin_data(); const __llvm_profile_data *DataEnd = __llvm_profile_end_data(); @@ -27,12 +27,11 @@ uint64_t __llvm_profile_get_size_for_buffer(void) { #define PROFILE_RANGE_SIZE(Range) (Range##End - Range##Begin) -__attribute__((visibility("hidden"))) +LLVM_LIBRARY_VISIBILITY uint64_t __llvm_profile_get_size_for_buffer_internal( - const __llvm_profile_data *DataBegin, - const __llvm_profile_data *DataEnd, const uint64_t *CountersBegin, - const uint64_t *CountersEnd, const char *NamesBegin, - const char *NamesEnd) { + const __llvm_profile_data *DataBegin, const __llvm_profile_data *DataEnd, + const uint64_t *CountersBegin, const uint64_t *CountersEnd, + const char *NamesBegin, const char *NamesEnd) { /* Match logic in __llvm_profile_write_buffer(). */ const uint64_t NamesSize = PROFILE_RANGE_SIZE(Names) * sizeof(char); const uint8_t Padding = __llvm_profile_get_num_padding_bytes(NamesSize); @@ -56,12 +55,12 @@ static uint32_t bufferWriter(ProfDataIOVec *IOVecs, uint32_t NumIOVecs, return 0; } -__attribute__((visibility("hidden"))) int +LLVM_LIBRARY_VISIBILITY __llvm_profile_write_buffer(char *Buffer) { return llvmWriteProfData(bufferWriter, Buffer, 0, 0); } -__attribute__((visibility("hidden"))) int __llvm_profile_write_buffer_internal( +LLVM_LIBRARY_VISIBILITY int __llvm_profile_write_buffer_internal( char *Buffer, const __llvm_profile_data *DataBegin, const __llvm_profile_data *DataEnd, const uint64_t *CountersBegin, const uint64_t *CountersEnd, const char *NamesBegin, const char *NamesEnd) { diff --git a/lib/profile/InstrProfilingFile.c b/lib/profile/InstrProfilingFile.c index 742df21d9..5663bab34 100644 --- a/lib/profile/InstrProfilingFile.c +++ b/lib/profile/InstrProfilingFile.c @@ -164,7 +164,7 @@ static void setFilenameAutomatically(void) { resetFilenameToDefault(); } -__attribute__((visibility("hidden"))) +LLVM_LIBRARY_VISIBILITY void __llvm_profile_initialize_file(void) { /* Check if the filename has been initialized. */ if (__llvm_profile_CurrentFilename) @@ -174,12 +174,12 @@ void __llvm_profile_initialize_file(void) { setFilenameAutomatically(); } -__attribute__((visibility("hidden"))) +LLVM_LIBRARY_VISIBILITY void __llvm_profile_set_filename(const char *Filename) { setFilenamePossiblyWithPid(Filename); } -__attribute__((visibility("hidden"))) +LLVM_LIBRARY_VISIBILITY void __llvm_profile_override_default_filename(const char *Filename) { /* If the env var is set, skip setting filename from argument. */ const char *Env_Filename = getenv("LLVM_PROFILE_FILE"); @@ -188,7 +188,7 @@ void __llvm_profile_override_default_filename(const char *Filename) { setFilenamePossiblyWithPid(Filename); } -__attribute__((visibility("hidden"))) +LLVM_LIBRARY_VISIBILITY int __llvm_profile_write_file(void) { int rc; @@ -204,11 +204,9 @@ int __llvm_profile_write_file(void) { return rc; } -static void writeFileWithoutReturn(void) { - __llvm_profile_write_file(); -} +static void writeFileWithoutReturn(void) { __llvm_profile_write_file(); } -__attribute__((visibility("hidden"))) +LLVM_LIBRARY_VISIBILITY int __llvm_profile_register_write_file_atexit(void) { static int HasBeenRegistered = 0; diff --git a/lib/profile/InstrProfilingPlatformDarwin.c b/lib/profile/InstrProfilingPlatformDarwin.c index 02299cc46..97c76366e 100644 --- a/lib/profile/InstrProfilingPlatformDarwin.c +++ b/lib/profile/InstrProfilingPlatformDarwin.c @@ -11,33 +11,32 @@ #if defined(__APPLE__) /* Use linker magic to find the bounds of the Data section. */ -__attribute__((visibility("hidden"))) -extern __llvm_profile_data DataStart __asm("section$start$__DATA$__llvm_prf_data"); -__attribute__((visibility("hidden"))) -extern __llvm_profile_data DataEnd __asm("section$end$__DATA$__llvm_prf_data"); -__attribute__((visibility("hidden"))) +LLVM_LIBRARY_VISIBILITY +extern __llvm_profile_data + DataStart __asm("section$start$__DATA$__llvm_prf_data"); +LLVM_LIBRARY_VISIBILITY +extern __llvm_profile_data DataEnd __asm("section$end$__DATA$__llvm_prf_data"); +LLVM_LIBRARY_VISIBILITY extern char NamesStart __asm("section$start$__DATA$__llvm_prf_names"); -__attribute__((visibility("hidden"))) -extern char NamesEnd __asm("section$end$__DATA$__llvm_prf_names"); -__attribute__((visibility("hidden"))) +LLVM_LIBRARY_VISIBILITY +extern char NamesEnd __asm("section$end$__DATA$__llvm_prf_names"); +LLVM_LIBRARY_VISIBILITY extern uint64_t CountersStart __asm("section$start$__DATA$__llvm_prf_cnts"); -__attribute__((visibility("hidden"))) -extern uint64_t CountersEnd __asm("section$end$__DATA$__llvm_prf_cnts"); +LLVM_LIBRARY_VISIBILITY +extern uint64_t CountersEnd __asm("section$end$__DATA$__llvm_prf_cnts"); -__attribute__((visibility("hidden"))) +LLVM_LIBRARY_VISIBILITY const __llvm_profile_data *__llvm_profile_begin_data(void) { return &DataStart; } -__attribute__((visibility("hidden"))) -const __llvm_profile_data *__llvm_profile_end_data(void) { - return &DataEnd; -} -__attribute__((visibility("hidden"))) +LLVM_LIBRARY_VISIBILITY +const __llvm_profile_data *__llvm_profile_end_data(void) { return &DataEnd; } +LLVM_LIBRARY_VISIBILITY const char *__llvm_profile_begin_names(void) { return &NamesStart; } -__attribute__((visibility("hidden"))) +LLVM_LIBRARY_VISIBILITY const char *__llvm_profile_end_names(void) { return &NamesEnd; } -__attribute__((visibility("hidden"))) +LLVM_LIBRARY_VISIBILITY uint64_t *__llvm_profile_begin_counters(void) { return &CountersStart; } -__attribute__((visibility("hidden"))) +LLVM_LIBRARY_VISIBILITY uint64_t *__llvm_profile_end_counters(void) { return &CountersEnd; } #endif diff --git a/lib/profile/InstrProfilingPlatformLinux.c b/lib/profile/InstrProfilingPlatformLinux.c index 282d6b4a9..ea0bd1328 100644 --- a/lib/profile/InstrProfilingPlatformLinux.c +++ b/lib/profile/InstrProfilingPlatformLinux.c @@ -12,44 +12,36 @@ #if defined(__linux__) || defined(__FreeBSD__) #include <stdlib.h> -extern __llvm_profile_data __start___llvm_prf_data - __attribute__((visibility("hidden"))); -extern __llvm_profile_data __stop___llvm_prf_data - __attribute__((visibility("hidden"))); -extern uint64_t __start___llvm_prf_cnts __attribute__((visibility("hidden"))); -extern uint64_t __stop___llvm_prf_cnts __attribute__((visibility("hidden"))); -extern char __start___llvm_prf_names __attribute__((visibility("hidden"))); -extern char __stop___llvm_prf_names __attribute__((visibility("hidden"))); +extern __llvm_profile_data __start___llvm_prf_data LLVM_LIBRARY_VISIBILITY; +extern __llvm_profile_data __stop___llvm_prf_data LLVM_LIBRARY_VISIBILITY; +extern uint64_t __start___llvm_prf_cnts LLVM_LIBRARY_VISIBILITY; +extern uint64_t __stop___llvm_prf_cnts LLVM_LIBRARY_VISIBILITY; +extern char __start___llvm_prf_names LLVM_LIBRARY_VISIBILITY; +extern char __stop___llvm_prf_names LLVM_LIBRARY_VISIBILITY; /* Add dummy data to ensure the section is always created. */ -__llvm_profile_data __llvm_prof_sect_data[0] - __attribute__((section("__llvm_prf_data"))); -uint64_t __llvm_prof_cnts_sect_data[0] - __attribute__((section("__llvm_prf_cnts"))); -char __llvm_prof_nms_sect_data[0] __attribute__((section("__llvm_prf_names"))); +__llvm_profile_data __llvm_prof_sect_data[0] LLVM_SECTION("__llvm_prf_data"); +uint64_t __llvm_prof_cnts_sect_data[0] LLVM_SECTION("__llvm_prf_cnts"); +char __llvm_prof_nms_sect_data[0] LLVM_SECTION("__llvm_prf_names"); -__attribute__((visibility("hidden"))) const __llvm_profile_data * +LLVM_LIBRARY_VISIBILITY const __llvm_profile_data * __llvm_profile_begin_data(void) { return &__start___llvm_prf_data; } -__attribute__((visibility("hidden"))) const __llvm_profile_data * +LLVM_LIBRARY_VISIBILITY const __llvm_profile_data * __llvm_profile_end_data(void) { return &__stop___llvm_prf_data; } -__attribute__((visibility("hidden"))) const char *__llvm_profile_begin_names( - void) { +LLVM_LIBRARY_VISIBILITY const char *__llvm_profile_begin_names(void) { return &__start___llvm_prf_names; } -__attribute__((visibility("hidden"))) const char *__llvm_profile_end_names( - void) { +LLVM_LIBRARY_VISIBILITY const char *__llvm_profile_end_names(void) { return &__stop___llvm_prf_names; } -__attribute__((visibility("hidden"))) uint64_t *__llvm_profile_begin_counters( - void) { +LLVM_LIBRARY_VISIBILITY uint64_t *__llvm_profile_begin_counters(void) { return &__start___llvm_prf_cnts; } -__attribute__((visibility("hidden"))) uint64_t *__llvm_profile_end_counters( - void) { +LLVM_LIBRARY_VISIBILITY uint64_t *__llvm_profile_end_counters(void) { return &__stop___llvm_prf_cnts; } #endif diff --git a/lib/profile/InstrProfilingPlatformOther.c b/lib/profile/InstrProfilingPlatformOther.c index eb6eb01db..02f4b2191 100644 --- a/lib/profile/InstrProfilingPlatformOther.c +++ b/lib/profile/InstrProfilingPlatformOther.c @@ -26,10 +26,10 @@ static uint64_t *CountersLast = NULL; * calls are only required (and only emitted) on targets where we haven't * implemented linker magic to find the bounds of the sections. */ -__attribute__((visibility("hidden"))) +LLVM_LIBRARY_VISIBILITY void __llvm_profile_register_function(void *Data_) { /* TODO: Only emit this function if we can't use linker magic. */ - const __llvm_profile_data *Data = (__llvm_profile_data*)Data_; + const __llvm_profile_data *Data = (__llvm_profile_data *)Data_; if (!DataFirst) { DataFirst = Data; DataLast = Data + 1; @@ -55,20 +55,16 @@ void __llvm_profile_register_function(void *Data_) { #undef UPDATE_LAST } -__attribute__((visibility("hidden"))) -const __llvm_profile_data *__llvm_profile_begin_data(void) { - return DataFirst; -} -__attribute__((visibility("hidden"))) -const __llvm_profile_data *__llvm_profile_end_data(void) { - return DataLast; -} -__attribute__((visibility("hidden"))) +LLVM_LIBRARY_VISIBILITY +const __llvm_profile_data *__llvm_profile_begin_data(void) { return DataFirst; } +LLVM_LIBRARY_VISIBILITY +const __llvm_profile_data *__llvm_profile_end_data(void) { return DataLast; } +LLVM_LIBRARY_VISIBILITY const char *__llvm_profile_begin_names(void) { return NamesFirst; } -__attribute__((visibility("hidden"))) +LLVM_LIBRARY_VISIBILITY const char *__llvm_profile_end_names(void) { return NamesLast; } -__attribute__((visibility("hidden"))) +LLVM_LIBRARY_VISIBILITY uint64_t *__llvm_profile_begin_counters(void) { return CountersFirst; } -__attribute__((visibility("hidden"))) +LLVM_LIBRARY_VISIBILITY uint64_t *__llvm_profile_end_counters(void) { return CountersLast; } #endif diff --git a/lib/profile/InstrProfilingUtil.c b/lib/profile/InstrProfilingUtil.c index e146dfca8..96d1e47d1 100644 --- a/lib/profile/InstrProfilingUtil.c +++ b/lib/profile/InstrProfilingUtil.c @@ -8,6 +8,7 @@ \*===----------------------------------------------------------------------===*/ #include "InstrProfilingUtil.h" +#include "InstrProfiling.h" #ifdef _WIN32 #include <direct.h> @@ -18,7 +19,7 @@ int mkdir(const char*, unsigned short); #include <sys/types.h> #endif -__attribute__((visibility("hidden"))) +LLVM_LIBRARY_VISIBILITY void __llvm_profile_recursive_mkdir(char *path) { int i; diff --git a/lib/profile/InstrProfilingWriter.c b/lib/profile/InstrProfilingWriter.c index e1aecec89..ec3bd1654 100644 --- a/lib/profile/InstrProfilingWriter.c +++ b/lib/profile/InstrProfilingWriter.c @@ -10,9 +10,10 @@ #include "InstrProfiling.h" #include "InstrProfilingInternal.h" -__attribute__((visibility("hidden"))) int -llvmWriteProfData(WriterCallback Writer, void *WriterCtx, - const uint8_t *ValueDataBegin, const uint64_t ValueDataSize) { +LLVM_LIBRARY_VISIBILITY int llvmWriteProfData(WriterCallback Writer, + void *WriterCtx, + const uint8_t *ValueDataBegin, + const uint64_t ValueDataSize) { /* Match logic in __llvm_profile_write_buffer(). */ const __llvm_profile_data *DataBegin = __llvm_profile_begin_data(); const __llvm_profile_data *DataEnd = __llvm_profile_end_data(); @@ -25,7 +26,7 @@ llvmWriteProfData(WriterCallback Writer, void *WriterCtx, ValueDataSize, NamesBegin, NamesEnd); } -__attribute__((visibility("hidden"))) int llvmWriteProfDataImpl( +LLVM_LIBRARY_VISIBILITY int llvmWriteProfDataImpl( WriterCallback Writer, void *WriterCtx, const __llvm_profile_data *DataBegin, const __llvm_profile_data *DataEnd, const uint64_t *CountersBegin, const uint64_t *CountersEnd, |