diff options
author | Renato Golin <renato.golin@linaro.org> | 2016-05-07 20:07:09 +0000 |
---|---|---|
committer | Renato Golin <renato.golin@linaro.org> | 2016-05-07 20:07:09 +0000 |
commit | 26642b4035a3742095c71c53e7372208b02c1550 (patch) | |
tree | 888ad2078ae68f58ea240cffbd929917f679e503 | |
parent | 6502975cf56d6a84f00f96100cf1e741d9b36493 (diff) | |
download | bcm5719-llvm-26642b4035a3742095c71c53e7372208b02c1550.tar.gz bcm5719-llvm-26642b4035a3742095c71c53e7372208b02c1550.zip |
Revert "[profile] Simplify value profile writing"
This reverts commit r268840, as it breaks Thumb2 self-hosting. There is something
unstable in the profiling for Thumb2 that needs to be sorted out before we continue
implementing these changes to the profiler. See PR27667.
llvm-svn: 268864
-rw-r--r-- | compiler-rt/lib/profile/InstrProfiling.h | 10 | ||||
-rw-r--r-- | compiler-rt/lib/profile/InstrProfilingBuffer.c | 4 | ||||
-rw-r--r-- | compiler-rt/lib/profile/InstrProfilingFile.c | 5 | ||||
-rw-r--r-- | compiler-rt/lib/profile/InstrProfilingInternal.h | 12 | ||||
-rw-r--r-- | compiler-rt/lib/profile/InstrProfilingValue.c | 56 | ||||
-rw-r--r-- | compiler-rt/lib/profile/InstrProfilingWriter.c | 55 |
6 files changed, 88 insertions, 54 deletions
diff --git a/compiler-rt/lib/profile/InstrProfiling.h b/compiler-rt/lib/profile/InstrProfiling.h index 5b1a91ea2a0..6ee54c51cb6 100644 --- a/compiler-rt/lib/profile/InstrProfiling.h +++ b/compiler-rt/lib/profile/InstrProfiling.h @@ -94,7 +94,15 @@ int __llvm_profile_check_compatibility(const char *Profile, void INSTR_PROF_VALUE_PROF_FUNC( #define VALUE_PROF_FUNC_PARAM(ArgType, ArgName, ArgLLVMType) ArgType ArgName #include "InstrProfData.inc" - ); +); + +/*! + * \brief Prepares the value profiling data for output. + * + * Returns an array of pointers to value profile data. + */ +struct ValueProfData; +struct ValueProfData **__llvm_profile_gather_value_data(uint64_t *Size); /*! * \brief Write instrumentation data to the current file. diff --git a/compiler-rt/lib/profile/InstrProfilingBuffer.c b/compiler-rt/lib/profile/InstrProfilingBuffer.c index ac259e83cbd..dcb6929cb0a 100644 --- a/compiler-rt/lib/profile/InstrProfilingBuffer.c +++ b/compiler-rt/lib/profile/InstrProfilingBuffer.c @@ -46,7 +46,7 @@ uint64_t __llvm_profile_get_size_for_buffer_internal( } COMPILER_RT_VISIBILITY int __llvm_profile_write_buffer(char *Buffer) { - return lprofWriteData(lprofBufferWriter, Buffer, 0); + return lprofWriteData(lprofBufferWriter, Buffer, 0, 0); } COMPILER_RT_VISIBILITY int __llvm_profile_write_buffer_internal( @@ -54,6 +54,6 @@ COMPILER_RT_VISIBILITY int __llvm_profile_write_buffer_internal( const __llvm_profile_data *DataEnd, const uint64_t *CountersBegin, const uint64_t *CountersEnd, const char *NamesBegin, const char *NamesEnd) { return lprofWriteDataImpl(lprofBufferWriter, Buffer, DataBegin, DataEnd, - CountersBegin, CountersEnd, 0, NamesBegin, + CountersBegin, CountersEnd, 0, 0, NamesBegin, NamesEnd); } diff --git a/compiler-rt/lib/profile/InstrProfilingFile.c b/compiler-rt/lib/profile/InstrProfilingFile.c index 14f7517b6a9..9d63269eb25 100644 --- a/compiler-rt/lib/profile/InstrProfilingFile.c +++ b/compiler-rt/lib/profile/InstrProfilingFile.c @@ -39,12 +39,15 @@ lprofCreateBufferIOInternal(void *File, uint32_t BufferSz) { static int writeFile(FILE *File) { const char *BufferSzStr = 0; + uint64_t ValueDataSize = 0; + struct ValueProfData **ValueDataArray = + __llvm_profile_gather_value_data(&ValueDataSize); FreeHook = &free; CallocHook = &calloc; BufferSzStr = getenv("LLVM_VP_BUFFER_SIZE"); if (BufferSzStr && BufferSzStr[0]) VPBufferSize = atoi(BufferSzStr); - return lprofWriteData(fileWriter, File, lprofGatherValueProfData); + return lprofWriteData(fileWriter, File, ValueDataArray, ValueDataSize); } static int writeFileWithName(const char *OutputName) { diff --git a/compiler-rt/lib/profile/InstrProfilingInternal.h b/compiler-rt/lib/profile/InstrProfilingInternal.h index 05892873dc1..2645858fc09 100644 --- a/compiler-rt/lib/profile/InstrProfilingInternal.h +++ b/compiler-rt/lib/profile/InstrProfilingInternal.h @@ -98,26 +98,22 @@ int lprofBufferIOFlush(ProfBufferIO *BufferIO); uint32_t lprofBufferWriter(ProfDataIOVec *IOVecs, uint32_t NumIOVecs, void **WriterCtx); -typedef struct ValueProfData *(*VPGatherHookType)( - const __llvm_profile_data *Data); int lprofWriteData(WriterCallback Writer, void *WriterCtx, - VPGatherHookType VPDataGatherer); + struct ValueProfData **ValueDataArray, + const uint64_t ValueDataSize); int lprofWriteDataImpl(WriterCallback Writer, void *WriterCtx, const __llvm_profile_data *DataBegin, const __llvm_profile_data *DataEnd, const uint64_t *CountersBegin, const uint64_t *CountersEnd, - VPGatherHookType VPDataGatherer, const char *NamesBegin, + struct ValueProfData **ValueDataBeginArray, + const uint64_t ValueDataSize, const char *NamesBegin, const char *NamesEnd); -/* Gather value profile data from \c Data and return it. */ -struct ValueProfData *lprofGatherValueProfData(const __llvm_profile_data *Data); - /* Merge value profile data pointed to by SrcValueProfData into * in-memory profile counters pointed by to DstData. */ void lprofMergeValueProfData(struct ValueProfData *SrcValueProfData, __llvm_profile_data *DstData); -extern VPGatherHookType VPGatherHook; extern char *(*GetEnvHook)(const char *); extern void (*FreeHook)(void *); extern void *(*CallocHook)(size_t, size_t); diff --git a/compiler-rt/lib/profile/InstrProfilingValue.c b/compiler-rt/lib/profile/InstrProfilingValue.c index 3fe913e9d58..4b4c82e8081 100644 --- a/compiler-rt/lib/profile/InstrProfilingValue.c +++ b/compiler-rt/lib/profile/InstrProfilingValue.c @@ -21,6 +21,7 @@ #define PROF_OOM_RETURN(Msg) \ { \ PROF_OOM(Msg) \ + free(ValueDataArray); \ return NULL; \ } @@ -117,22 +118,51 @@ __llvm_profile_instrument_target(uint64_t TargetValue, void *Data, } } -COMPILER_RT_VISIBILITY struct ValueProfData * -lprofGatherValueProfData(const __llvm_profile_data *Data) { - ValueProfData *VD = NULL; - ValueProfRuntimeRecord R; - if (initializeValueProfRuntimeRecord(&R, Data->NumValueSites, Data->Values)) +COMPILER_RT_VISIBILITY ValueProfData ** +__llvm_profile_gather_value_data(uint64_t *ValueDataSize) { + size_t S = 0; + __llvm_profile_data *I; + ValueProfData **ValueDataArray; + + const __llvm_profile_data *DataEnd = __llvm_profile_end_data(); + const __llvm_profile_data *DataBegin = __llvm_profile_begin_data(); + + if (!ValueDataSize) + return NULL; + + ValueDataArray = (ValueProfData **)calloc( + __llvm_profile_get_data_size(DataBegin, DataEnd), sizeof(void *)); + if (!ValueDataArray) PROF_OOM_RETURN("Failed to write value profile data "); - /* Compute the size of ValueProfData from this runtime record. */ - if (getNumValueKindsRT(&R) != 0) { - uint32_t VS = getValueProfDataSizeRT(&R); - VD = (ValueProfData *)calloc(VS, sizeof(uint8_t)); - if (!VD) + /* + * Compute the total Size of the buffer to hold ValueProfData + * structures for functions with value profile data. + */ + for (I = (__llvm_profile_data *)DataBegin; I < DataEnd; ++I) { + ValueProfRuntimeRecord R; + if (initializeValueProfRuntimeRecord(&R, I->NumValueSites, I->Values)) PROF_OOM_RETURN("Failed to write value profile data "); - serializeValueProfDataFromRT(&R, VD); + + /* Compute the size of ValueProfData from this runtime record. */ + if (getNumValueKindsRT(&R) != 0) { + ValueProfData *VD = NULL; + uint32_t VS = getValueProfDataSizeRT(&R); + VD = (ValueProfData *)calloc(VS, sizeof(uint8_t)); + if (!VD) + PROF_OOM_RETURN("Failed to write value profile data "); + serializeValueProfDataFromRT(&R, VD); + ValueDataArray[I - DataBegin] = VD; + S += VS; + } + finalizeValueProfRuntimeRecord(&R); + } + + if (!S) { + free(ValueDataArray); + ValueDataArray = NULL; } - finalizeValueProfRuntimeRecord(&R); - return VD; + *ValueDataSize = S; + return ValueDataArray; } diff --git a/compiler-rt/lib/profile/InstrProfilingWriter.c b/compiler-rt/lib/profile/InstrProfilingWriter.c index 8b3136d032f..18b3f34640b 100644 --- a/compiler-rt/lib/profile/InstrProfilingWriter.c +++ b/compiler-rt/lib/profile/InstrProfilingWriter.c @@ -91,29 +91,42 @@ COMPILER_RT_VISIBILITY int lprofBufferIOFlush(ProfBufferIO *BufferIO) { return 0; } +COMPILER_RT_VISIBILITY int lprofWriteData(WriterCallback Writer, + void *WriterCtx, + ValueProfData **ValueDataArray, + 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(); + const uint64_t *CountersBegin = __llvm_profile_begin_counters(); + const uint64_t *CountersEnd = __llvm_profile_end_counters(); + const char *NamesBegin = __llvm_profile_begin_names(); + const char *NamesEnd = __llvm_profile_end_names(); + return lprofWriteDataImpl(Writer, WriterCtx, DataBegin, DataEnd, + CountersBegin, CountersEnd, ValueDataArray, + ValueDataSize, NamesBegin, NamesEnd); +} + #define VP_BUFFER_SIZE 8 * 1024 static int writeValueProfData(WriterCallback Writer, void *WriterCtx, - VPGatherHookType VPDataGatherer, - const __llvm_profile_data *DataBegin, - const __llvm_profile_data *DataEnd) { + ValueProfData **ValueDataBegin, + uint64_t NumVData) { ProfBufferIO *BufferIO; - uint32_t BufferSz; - const __llvm_profile_data *DI = 0; + uint32_t I = 0, BufferSz; - if (!VPDataGatherer) + if (!ValueDataBegin) return 0; BufferSz = VPBufferSize ? VPBufferSize : VP_BUFFER_SIZE; BufferIO = lprofCreateBufferIO(Writer, WriterCtx, BufferSz); - for (DI = DataBegin; DI < DataEnd; DI++) { - ValueProfData *CurVData = VPDataGatherer(DI); + for (I = 0; I < NumVData; I++) { + ValueProfData *CurVData = ValueDataBegin[I]; if (!CurVData) continue; if (lprofBufferIOWrite(BufferIO, (const uint8_t *)CurVData, CurVData->TotalSize) != 0) return -1; - FreeHook(CurVData); } if (lprofBufferIOFlush(BufferIO) != 0) @@ -123,28 +136,13 @@ static int writeValueProfData(WriterCallback Writer, void *WriterCtx, return 0; } -COMPILER_RT_VISIBILITY int lprofWriteData(WriterCallback Writer, - void *WriterCtx, - VPGatherHookType VPDataGatherer) { - /* 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(); - const uint64_t *CountersBegin = __llvm_profile_begin_counters(); - const uint64_t *CountersEnd = __llvm_profile_end_counters(); - const char *NamesBegin = __llvm_profile_begin_names(); - const char *NamesEnd = __llvm_profile_end_names(); - return lprofWriteDataImpl(Writer, WriterCtx, DataBegin, DataEnd, - CountersBegin, CountersEnd, VPDataGatherer, - NamesBegin, NamesEnd); -} - COMPILER_RT_VISIBILITY int lprofWriteDataImpl(WriterCallback Writer, void *WriterCtx, const __llvm_profile_data *DataBegin, const __llvm_profile_data *DataEnd, const uint64_t *CountersBegin, const uint64_t *CountersEnd, - VPGatherHookType VPDataGatherer, const char *NamesBegin, - const char *NamesEnd) { + ValueProfData **ValueDataBegin, const uint64_t ValueDataSize, + const char *NamesBegin, const char *NamesEnd) { /* Calculate size of sections. */ const uint64_t DataSize = __llvm_profile_get_data_size(DataBegin, DataEnd); @@ -161,7 +159,7 @@ lprofWriteDataImpl(WriterCallback Writer, void *WriterCtx, if (!DataSize) return 0; -/* Initialize header structure. */ + /* Initialize header struture. */ #define INSTR_PROF_RAW_HEADER(Type, Name, Init) Header.Name = Init; #include "InstrProfData.inc" @@ -174,6 +172,5 @@ lprofWriteDataImpl(WriterCallback Writer, void *WriterCtx, if (Writer(IOVec, sizeof(IOVec) / sizeof(*IOVec), &WriterCtx)) return -1; - return writeValueProfData(Writer, WriterCtx, VPDataGatherer, DataBegin, - DataEnd); + return writeValueProfData(Writer, WriterCtx, ValueDataBegin, DataSize); } |