diff options
| author | Duncan P. N. Exon Smith <dexonsmith@apple.com> | 2014-03-21 18:29:15 +0000 |
|---|---|---|
| committer | Duncan P. N. Exon Smith <dexonsmith@apple.com> | 2014-03-21 18:29:15 +0000 |
| commit | be0a5e176b6cadae34b14a7efac7eae2d918cfb6 (patch) | |
| tree | 585c0ec1ada6e845167029fa5ec7e388a0bc22c7 /compiler-rt/lib | |
| parent | 24b4b6533925e6dbd0faef7976c7f794499e0ec6 (diff) | |
| download | bcm5719-llvm-be0a5e176b6cadae34b14a7efac7eae2d918cfb6.tar.gz bcm5719-llvm-be0a5e176b6cadae34b14a7efac7eae2d918cfb6.zip | |
InstrProf: Reorganize files; no functionality change
Move functions around to prepare for some other changes.
- Merge InstrProfilingExtras.h with InstrProfiling.h. There's no
benefit to having these split.
- Rename InstrProfilingExtras.c to InstrProfilingFile.c.
- Split actual buffer writing code out of InstrProfiling.c into
InstrProfilingBuffer.c.
- Drive-by corrections of a couple of header comments.
<rdar://problem/15943240>
llvm-svn: 204497
Diffstat (limited to 'compiler-rt/lib')
| -rw-r--r-- | compiler-rt/lib/profile/CMakeLists.txt | 10 | ||||
| -rw-r--r-- | compiler-rt/lib/profile/InstrProfiling.c | 51 | ||||
| -rw-r--r-- | compiler-rt/lib/profile/InstrProfiling.h | 40 | ||||
| -rw-r--r-- | compiler-rt/lib/profile/InstrProfilingBuffer.c | 54 | ||||
| -rw-r--r-- | compiler-rt/lib/profile/InstrProfilingExtras.h | 31 | ||||
| -rw-r--r-- | compiler-rt/lib/profile/InstrProfilingFile.c (renamed from compiler-rt/lib/profile/InstrProfilingExtras.c) | 39 | ||||
| -rw-r--r-- | compiler-rt/lib/profile/InstrProfilingPlatformDarwin.c | 2 | ||||
| -rw-r--r-- | compiler-rt/lib/profile/InstrProfilingPlatformOther.c | 3 | ||||
| -rw-r--r-- | compiler-rt/lib/profile/InstrProfilingRuntime.cc | 2 |
9 files changed, 126 insertions, 106 deletions
diff --git a/compiler-rt/lib/profile/CMakeLists.txt b/compiler-rt/lib/profile/CMakeLists.txt index 949e174b40c..526017f2e93 100644 --- a/compiler-rt/lib/profile/CMakeLists.txt +++ b/compiler-rt/lib/profile/CMakeLists.txt @@ -6,9 +6,10 @@ if(APPLE) set(PROFILE_SOURCES GCDAProfiling.c InstrProfiling.c + InstrProfilingBuffer.c + InstrProfilingFile.c InstrProfilingPlatformDarwin.c - InstrProfilingRuntime.cc - InstrProfilingExtras.c) + InstrProfilingRuntime.cc) add_compiler_rt_osx_static_runtime(clang_rt.profile_osx ARCH ${PROFILE_SUPPORTED_ARCH} @@ -18,9 +19,10 @@ else() set(PROFILE_SOURCES GCDAProfiling.c InstrProfiling.c + InstrProfilingBuffer.c + InstrProfilingFile.c InstrProfilingPlatformOther.c - InstrProfilingRuntime.cc - InstrProfilingExtras.c) + InstrProfilingRuntime.cc) foreach(arch ${PROFILE_SUPPORTED_ARCH}) add_compiler_rt_static_runtime(clang_rt.profile-${arch} diff --git a/compiler-rt/lib/profile/InstrProfiling.c b/compiler-rt/lib/profile/InstrProfiling.c index a62c214c164..de88f1ba30d 100644 --- a/compiler-rt/lib/profile/InstrProfiling.c +++ b/compiler-rt/lib/profile/InstrProfiling.c @@ -10,9 +10,8 @@ #include "InstrProfiling.h" #include <string.h> -/* TODO: void __llvm_profile_get_size_for_buffer(void); */ - -static uint64_t getMagic(void) { +uint64_t __llvm_profile_get_magic(void) { + /* Magic number to detect file format and endianness. */ return (uint64_t)'l' << 56 | (uint64_t)'p' << 48 | @@ -24,53 +23,11 @@ static uint64_t getMagic(void) { (uint64_t)'w'; } -static uint64_t getVersion(void) { +uint64_t __llvm_profile_get_version(void) { + /* This should be bumped any time the output format changes. */ return 1; } -int __llvm_profile_write_buffer(FILE *OutputFile) { - /* TODO: Requires libc: break requirement by taking a char* buffer instead of - * a FILE stream. - */ - const __llvm_profile_data *DataBegin = __llvm_profile_data_begin(); - const __llvm_profile_data *DataEnd = __llvm_profile_data_end(); - const uint64_t *CountersBegin = __llvm_profile_counters_begin(); - const uint64_t *CountersEnd = __llvm_profile_counters_end(); - const char *NamesBegin = __llvm_profile_names_begin(); - const char *NamesEnd = __llvm_profile_names_end(); - - /* Calculate size of sections. */ - const uint64_t DataSize = DataEnd - DataBegin; - const uint64_t CountersSize = CountersEnd - CountersBegin; - const uint64_t NamesSize = NamesEnd - NamesBegin; - - /* Get rest of header data. */ - const uint64_t Magic = getMagic(); - const uint64_t Version = getVersion(); - const uint64_t CountersDelta = (uint64_t)CountersBegin; - const uint64_t NamesDelta = (uint64_t)NamesBegin; - -#define CHECK_fwrite(Data, Size, Length, File) \ - do { if (fwrite(Data, Size, Length, File) != Length) return -1; } while (0) - - /* Write the header. */ - CHECK_fwrite(&Magic, sizeof(uint64_t), 1, OutputFile); - CHECK_fwrite(&Version, sizeof(uint64_t), 1, OutputFile); - CHECK_fwrite(&DataSize, sizeof(uint64_t), 1, OutputFile); - CHECK_fwrite(&CountersSize, sizeof(uint64_t), 1, OutputFile); - CHECK_fwrite(&NamesSize, sizeof(uint64_t), 1, OutputFile); - CHECK_fwrite(&CountersDelta, sizeof(uint64_t), 1, OutputFile); - CHECK_fwrite(&NamesDelta, sizeof(uint64_t), 1, OutputFile); - - /* Write the data. */ - CHECK_fwrite(DataBegin, sizeof(__llvm_profile_data), DataSize, OutputFile); - CHECK_fwrite(CountersBegin, sizeof(uint64_t), CountersSize, OutputFile); - CHECK_fwrite(NamesBegin, sizeof(char), NamesSize, OutputFile); -#undef CHECK_fwrite - - return 0; -} - void __llvm_profile_reset_counters(void) { uint64_t *I = __llvm_profile_counters_begin(); uint64_t *E = __llvm_profile_counters_end(); diff --git a/compiler-rt/lib/profile/InstrProfiling.h b/compiler-rt/lib/profile/InstrProfiling.h index 17d3fd42401..d3600accf9f 100644 --- a/compiler-rt/lib/profile/InstrProfiling.h +++ b/compiler-rt/lib/profile/InstrProfiling.h @@ -7,8 +7,10 @@ |* \*===----------------------------------------------------------------------===*/ +#ifndef PROFILE_INSTRPROFILING_H__ +#define PROFILE_INSTRPROFILING_H__ + #include <stdio.h> -#include <stdlib.h> #define I386_FREEBSD (defined(__FreeBSD__) && defined(__i386__)) @@ -40,7 +42,7 @@ typedef struct __llvm_profile_data { uint64_t *const Counters; } __llvm_profile_data; -/* TODO: void __llvm_profile_get_size_for_buffer(void); */ +/* TODO: void __llvm_profile_get_size_for_buffer(void); */ /*! * \brief Write instrumentation data to the given buffer. @@ -57,3 +59,37 @@ const char *__llvm_profile_names_begin(void); const char *__llvm_profile_names_end(void); uint64_t *__llvm_profile_counters_begin(void); uint64_t *__llvm_profile_counters_end(void); + +#define PROFILE_RANGE_SIZE(Range) \ + (__llvm_profile_ ## Range ## _end() - __llvm_profile_ ## Range ## _begin()) + +/*! + * \brief Write instrumentation data to the current file. + * + * Writes to the file with the last name given to \a __llvm_profile_set_filename(), + * or if it hasn't been called, the \c LLVM_PROFILE_FILE environment variable, + * or if that's not set, \c "default.profdata". + */ +int __llvm_profile_write_file(void); + +/*! + * \brief Set the filename for writing instrumentation data. + * + * Sets the filename to be used for subsequent calls to + * \a __llvm_profile_write_file(). + * + * \c Name is not copied, so it must remain valid. Passing NULL resets the + * filename logic to the default behaviour. + */ +void __llvm_profile_set_filename(const char *Name); + +/*! \brief Register to write instrumentation data to file at exit. */ +int __llvm_profile_register_write_file_atexit(void); + +/*! \brief Get the magic token for the file format. */ +uint64_t __llvm_profile_get_magic(void); + +/*! \brief Get the version of the file format. */ +uint64_t __llvm_profile_get_version(void); + +#endif /* PROFILE_INSTRPROFILING_H__ */ diff --git a/compiler-rt/lib/profile/InstrProfilingBuffer.c b/compiler-rt/lib/profile/InstrProfilingBuffer.c new file mode 100644 index 00000000000..7b662ca7dd9 --- /dev/null +++ b/compiler-rt/lib/profile/InstrProfilingBuffer.c @@ -0,0 +1,54 @@ +/*===- InstrProfilingBuffer.c - Write instrumentation to a memory buffer --===*\ +|* +|* The LLVM Compiler Infrastructure +|* +|* This file is distributed under the University of Illinois Open Source +|* License. See LICENSE.TXT for details. +|* +\*===----------------------------------------------------------------------===*/ + +#include "InstrProfiling.h" +#include <string.h> + +/* TODO: uint64_t __llvm_profile_get_size_for_buffer(void) */ + +int __llvm_profile_write_buffer(FILE *OutputFile) { + const __llvm_profile_data *DataBegin = __llvm_profile_data_begin(); + const __llvm_profile_data *DataEnd = __llvm_profile_data_end(); + const uint64_t *CountersBegin = __llvm_profile_counters_begin(); + const uint64_t *CountersEnd = __llvm_profile_counters_end(); + const char *NamesBegin = __llvm_profile_names_begin(); + const char *NamesEnd = __llvm_profile_names_end(); + + /* Calculate size of sections. */ + const uint64_t DataSize = DataEnd - DataBegin; + const uint64_t CountersSize = CountersEnd - CountersBegin; + const uint64_t NamesSize = NamesEnd - NamesBegin; + + /* Get rest of header data. */ + const uint64_t Magic = __llvm_profile_get_magic(); + const uint64_t Version = __llvm_profile_get_version(); + const uint64_t CountersDelta = (uint64_t)CountersBegin; + const uint64_t NamesDelta = (uint64_t)NamesBegin; + +#define CHECK_fwrite(Data, Size, Length, File) \ + do { if (fwrite(Data, Size, Length, File) != Length) return -1; } while (0) + + /* Write the header. */ + CHECK_fwrite(&Magic, sizeof(uint64_t), 1, OutputFile); + CHECK_fwrite(&Version, sizeof(uint64_t), 1, OutputFile); + CHECK_fwrite(&DataSize, sizeof(uint64_t), 1, OutputFile); + CHECK_fwrite(&CountersSize, sizeof(uint64_t), 1, OutputFile); + CHECK_fwrite(&NamesSize, sizeof(uint64_t), 1, OutputFile); + CHECK_fwrite(&CountersDelta, sizeof(uint64_t), 1, OutputFile); + CHECK_fwrite(&NamesDelta, sizeof(uint64_t), 1, OutputFile); + + /* Write the data. */ + CHECK_fwrite(DataBegin, sizeof(__llvm_profile_data), DataSize, OutputFile); + CHECK_fwrite(CountersBegin, sizeof(uint64_t), CountersSize, OutputFile); + CHECK_fwrite(NamesBegin, sizeof(char), NamesSize, OutputFile); + +#undef CHECK_fwrite + + return 0; +} diff --git a/compiler-rt/lib/profile/InstrProfilingExtras.h b/compiler-rt/lib/profile/InstrProfilingExtras.h deleted file mode 100644 index 1ab90cc873f..00000000000 --- a/compiler-rt/lib/profile/InstrProfilingExtras.h +++ /dev/null @@ -1,31 +0,0 @@ -/*===- InstrProfilingExtras.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. -|* -\*===----------------------------------------------------------------------===*/ - -/*! - * \brief Write instrumentation data to the current file. - * - * Writes to the file with the last name given to \a __llvm_profile_set_filename(), - * or if it hasn't been called, the \c LLVM_PROFILE_FILE environment variable, - * or if that's not set, \c "default.profdata". - */ -int __llvm_profile_write_file(void); - -/*! - * \brief Set the filename for writing instrumentation data. - * - * Sets the filename to be used for subsequent calls to - * \a __llvm_profile_write_file(). - * - * \c Name is not copied, so it must remain valid. Passing NULL resets the - * filename logic to the default behaviour. - */ -void __llvm_profile_set_filename(const char *Name); - -/*! \brief Register to write instrumentation data to file at exit. */ -int __llvm_profile_register_write_file_atexit(void); diff --git a/compiler-rt/lib/profile/InstrProfilingExtras.c b/compiler-rt/lib/profile/InstrProfilingFile.c index 723952f0856..505d748f77c 100644 --- a/compiler-rt/lib/profile/InstrProfilingExtras.c +++ b/compiler-rt/lib/profile/InstrProfilingFile.c @@ -1,4 +1,4 @@ -/*===- InstrProfilingExtras.c - Support library for PGO instrumentation ---===*\ +/*===- InstrProfilingFile.c - Write instrumentation to a file -------------===*\ |* |* The LLVM Compiler Infrastructure |* @@ -8,9 +8,11 @@ \*===----------------------------------------------------------------------===*/ #include "InstrProfiling.h" +#include <stdio.h> +#include <stdlib.h> #include <string.h> -static int __llvm_profile_write_file_with_name(const char *OutputName) { +static int writeFileWithName(const char *OutputName) { int RetVal; FILE *OutputFile; if (!OutputName || !OutputName[0]) @@ -19,9 +21,6 @@ static int __llvm_profile_write_file_with_name(const char *OutputName) { if (!OutputFile) return -1; - /* TODO: mmap file to buffer of size __llvm_profile_get_size_for_buffer() and - * pass the buffer in, instead of the file. - */ RetVal = __llvm_profile_write_buffer(OutputFile); fclose(OutputFile); @@ -44,7 +43,7 @@ int __llvm_profile_write_file(void) { int PidLength = 0; int NumPids = 0; - // Get the filename. + /* Get the filename. */ const char *Filename = CurrentFilename; #define UPDATE_FILENAME(NextFilename) \ if (!Filename || !Filename[0]) Filename = NextFilename @@ -52,7 +51,7 @@ int __llvm_profile_write_file(void) { UPDATE_FILENAME("default.profdata"); #undef UPDATE_FILENAME - // Check the filename for "%p", which indicates a pid-substitution. + /* Check the filename for "%p", which indicates a pid-substitution. */ for (I = 0; Filename[I]; ++I) if (Filename[I] == '%' && Filename[++I] == 'p') if (!NumPids++) { @@ -61,31 +60,31 @@ int __llvm_profile_write_file(void) { return -1; } if (NumPids) { - // Allocate enough space for the substituted filename. + /* Allocate enough space for the substituted filename. */ AllocatedFilename = (char*)malloc(I + NumPids*(PidLength - 2) + 1); if (!AllocatedFilename) return -1; - // Construct the new filename. + /* Construct the new filename. */ for (I = 0, J = 0; Filename[I]; ++I) if (Filename[I] == '%') { if (Filename[++I] == 'p') { memcpy(AllocatedFilename + J, PidChars, PidLength); J += PidLength; } - // Drop any unknown substitutions. + /* Drop any unknown substitutions. */ } else AllocatedFilename[J++] = Filename[I]; AllocatedFilename[J] = 0; - // Actually use the computed name. + /* Actually use the computed name. */ Filename = AllocatedFilename; } - // Write the file. - RetVal = __llvm_profile_write_file_with_name(Filename); + /* Write the file. */ + RetVal = writeFileWithName(Filename); - // Free the filename. + /* Free the filename. */ if (AllocatedFilename) free(AllocatedFilename); @@ -95,11 +94,13 @@ int __llvm_profile_write_file(void) { static void writeFileWithoutReturn(void) { __llvm_profile_write_file(); } -void __llvm_profile_register_write_file_atexit(void) { + +int __llvm_profile_register_write_file_atexit(void) { static int HasBeenRegistered = 0; - if (!HasBeenRegistered) { - HasBeenRegistered = 1; - atexit(writeFileWithoutReturn); - } + if (HasBeenRegistered) + return 0; + + HasBeenRegistered = 1; + return atexit(writeFileWithoutReturn); } diff --git a/compiler-rt/lib/profile/InstrProfilingPlatformDarwin.c b/compiler-rt/lib/profile/InstrProfilingPlatformDarwin.c index fdb1d66a0e8..1ba672d1ea5 100644 --- a/compiler-rt/lib/profile/InstrProfilingPlatformDarwin.c +++ b/compiler-rt/lib/profile/InstrProfilingPlatformDarwin.c @@ -1,4 +1,4 @@ -/*===- InstrProfilingDarwin.c - Profile data on Darwin --------------------===*\ +/*===- InstrProfilingPlatformDarwin.c - Profile data on Darwin ------------===*\ |* |* The LLVM Compiler Infrastructure |* diff --git a/compiler-rt/lib/profile/InstrProfilingPlatformOther.c b/compiler-rt/lib/profile/InstrProfilingPlatformOther.c index da24f59fe19..69b59254f58 100644 --- a/compiler-rt/lib/profile/InstrProfilingPlatformOther.c +++ b/compiler-rt/lib/profile/InstrProfilingPlatformOther.c @@ -1,4 +1,4 @@ -/*===- InstrProfilingDefault.c - Profile data default platfrom ------------===*\ +/*===- InstrProfilingPlatformOther.c - Profile data default platfrom ------===*\ |* |* The LLVM Compiler Infrastructure |* @@ -8,6 +8,7 @@ \*===----------------------------------------------------------------------===*/ #include "InstrProfiling.h" +#include <stdlib.h> static const __llvm_profile_data *DataFirst = NULL; static const __llvm_profile_data *DataLast = NULL; diff --git a/compiler-rt/lib/profile/InstrProfilingRuntime.cc b/compiler-rt/lib/profile/InstrProfilingRuntime.cc index 6116b0c1f3a..709b96c7af1 100644 --- a/compiler-rt/lib/profile/InstrProfilingRuntime.cc +++ b/compiler-rt/lib/profile/InstrProfilingRuntime.cc @@ -9,7 +9,7 @@ extern "C" { -#include "InstrProfilingExtras.h" +#include "InstrProfiling.h" extern int __llvm_profile_runtime; int __llvm_profile_runtime; |

