diff options
author | Xinliang David Li <davidxl@google.com> | 2016-05-07 02:50:11 +0000 |
---|---|---|
committer | Xinliang David Li <davidxl@google.com> | 2016-05-07 02:50:11 +0000 |
commit | 2c920abc2fc34be7f400179ebc284ec2832f77b0 (patch) | |
tree | 9f3331d01f870a0b4537dd15dfc6f8ed034e3722 /lib/profile/InstrProfilingValue.c | |
parent | a7f0947760499f1a12d966e7ff307c8b71bafc93 (diff) |
[profile] Simplify value profile writing
With this patch, value data are longer pre-collected
before writing. The code is simplified and requires
less heap space for dumping.
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@268840 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/profile/InstrProfilingValue.c')
-rw-r--r-- | lib/profile/InstrProfilingValue.c | 56 |
1 files changed, 13 insertions, 43 deletions
diff --git a/lib/profile/InstrProfilingValue.c b/lib/profile/InstrProfilingValue.c index 4b4c82e80..3fe913e9d 100644 --- a/lib/profile/InstrProfilingValue.c +++ b/lib/profile/InstrProfilingValue.c @@ -21,7 +21,6 @@ #define PROF_OOM_RETURN(Msg) \ { \ PROF_OOM(Msg) \ - free(ValueDataArray); \ return NULL; \ } @@ -118,51 +117,22 @@ __llvm_profile_instrument_target(uint64_t TargetValue, void *Data, } } -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) +COMPILER_RT_VISIBILITY struct ValueProfData * +lprofGatherValueProfData(const __llvm_profile_data *Data) { + ValueProfData *VD = NULL; + ValueProfRuntimeRecord R; + if (initializeValueProfRuntimeRecord(&R, Data->NumValueSites, Data->Values)) PROF_OOM_RETURN("Failed to write value profile data "); - /* - * 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)) + /* 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) PROF_OOM_RETURN("Failed to write value profile data "); - - /* 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; + serializeValueProfDataFromRT(&R, VD); } + finalizeValueProfRuntimeRecord(&R); - *ValueDataSize = S; - return ValueDataArray; + return VD; } |