cleanup: Enforce caller to set total size to avoid redundant size compute

llvm-svn: 269237
This commit is contained in:
Xinliang David Li 2016-05-11 21:16:11 +00:00
parent 31d7da3b5f
commit eb836a3dec
2 changed files with 6 additions and 2 deletions

View File

@ -531,12 +531,15 @@ void serializeValueProfRecordFrom(ValueProfRecord *This,
/*!
* Extract value profile data of a function from the \c Closure
* and serialize the data into \c DstData if it is not NULL or heap
* memory allocated by the \c Closure's allocator method.
* memory allocated by the \c Closure's allocator method. If \c
* DstData is not null, the caller is expected to set the TotalSize
* in DstData.
*/
ValueProfData *serializeValueProfDataFrom(ValueProfRecordClosure *Closure,
ValueProfData *DstData) {
uint32_t Kind;
uint32_t TotalSize = getValueProfDataSize(Closure);
uint32_t TotalSize =
DstData ? DstData->TotalSize : getValueProfDataSize(Closure);
ValueProfData *VPD =
DstData ? DstData : Closure->AllocValueProfData(TotalSize);

View File

@ -130,6 +130,7 @@ lprofGatherValueProfData(const __llvm_profile_data *Data) {
VD = (ValueProfData *)calloc(VS, sizeof(uint8_t));
if (!VD)
PROF_OOM_RETURN("Failed to write value profile data ");
VD->TotalSize = VS;
serializeValueProfDataFromRT(&R, VD);
}
finalizeValueProfRuntimeRecord(&R);