diff options
-rw-r--r-- | llvm/include/llvm/ProfileData/InstrProf.h | 7 | ||||
-rw-r--r-- | llvm/lib/ProfileData/InstrProf.cpp | 22 | ||||
-rw-r--r-- | llvm/unittests/ProfileData/InstrProfTest.cpp | 2 |
3 files changed, 18 insertions, 13 deletions
diff --git a/llvm/include/llvm/ProfileData/InstrProf.h b/llvm/include/llvm/ProfileData/InstrProf.h index 3a122666200..8fd3d7f8ffd 100644 --- a/llvm/include/llvm/ProfileData/InstrProf.h +++ b/llvm/include/llvm/ProfileData/InstrProf.h @@ -513,7 +513,8 @@ typedef struct ValueProfData { /// All data in the instance are properly byte swapped. The input /// data is assumed to be in little endian order. static ErrorOr<std::unique_ptr<ValueProfData>> - getValueProfData(const unsigned char *D, const unsigned char *const BufferEnd, + getValueProfData(const unsigned char *SrcBuffer, + const unsigned char *const SrcBufferEnd, support::endianness SrcDataEndianness); /// Swap byte order from \c Endianness order to host byte order. void swapBytesToHost(support::endianness Endianness); @@ -596,8 +597,8 @@ uint32_t getValueProfDataSizeRT(const ValueProfRuntimeRecord *Record); /* Return a ValueProfData instance that stores the data collected at runtime. */ ValueProfData * -serializeValueProfDataFromRT(const ValueProfRuntimeRecord *Record); - +serializeValueProfDataFromRT(const ValueProfRuntimeRecord *Record, + ValueProfData *Dst); /*! \brief Return the \c ValueProfRecord header size including the * padding bytes. diff --git a/llvm/lib/ProfileData/InstrProf.cpp b/llvm/lib/ProfileData/InstrProf.cpp index 54c37e30dba..3bbc8249c3d 100644 --- a/llvm/lib/ProfileData/InstrProf.cpp +++ b/llvm/lib/ProfileData/InstrProf.cpp @@ -170,10 +170,12 @@ void serializeValueProfRecordFrom(ValueProfRecord *This, } } -ValueProfData *serializeValueProfDataFrom(ValueProfRecordClosure *Closure) { +ValueProfData *serializeValueProfDataFrom(ValueProfRecordClosure *Closure, + ValueProfData *DstData) { uint32_t TotalSize = getValueProfDataSize(Closure); - ValueProfData *VPD = Closure->AllocValueProfData(TotalSize); + ValueProfData *VPD = + DstData ? DstData : Closure->AllocValueProfData(TotalSize); VPD->TotalSize = TotalSize; VPD->NumValueKinds = Closure->GetNumValueKinds(Closure->Record); @@ -259,7 +261,7 @@ ValueProfData::serializeFrom(const InstrProfRecord &Record) { InstrProfRecordClosure.Record = &Record; std::unique_ptr<ValueProfData> VPD( - serializeValueProfDataFrom(&InstrProfRecordClosure)); + serializeValueProfDataFrom(&InstrProfRecordClosure, 0)); return VPD; } @@ -367,16 +369,18 @@ uint32_t getValueProfDataSizeRT(const ValueProfRuntimeRecord *Record) { } /* Return a ValueProfData instance that stores the data collected - from runtime. */ + * from runtime. If \c DstData is provided by the caller, the value + * profile data will be store in *DstData and DstData is returned, + * otherwise the method will allocate space for the value data and + * return pointer to the newly allocated space. + */ ValueProfData * -serializeValueProfDataFromRT(const ValueProfRuntimeRecord *Record) { +serializeValueProfDataFromRT(const ValueProfRuntimeRecord *Record, + ValueProfData *DstData) { RTRecordClosure.Record = Record; - return serializeValueProfDataFrom(&RTRecordClosure); + return serializeValueProfDataFrom(&RTRecordClosure, DstData); } - - - void ValueProfRecord::deserializeTo(InstrProfRecord &Record, InstrProfRecord::ValueMapType *VMap) { Record.reserveSites(Kind, NumValueSites); diff --git a/llvm/unittests/ProfileData/InstrProfTest.cpp b/llvm/unittests/ProfileData/InstrProfTest.cpp index 051bf391b95..d50944ff77f 100644 --- a/llvm/unittests/ProfileData/InstrProfTest.cpp +++ b/llvm/unittests/ProfileData/InstrProfTest.cpp @@ -409,7 +409,7 @@ TEST_F(InstrProfTest, runtime_value_prof_data_read_write) { initializeValueProfRuntimeRecord(&RTRecord, &NumValueSites[0], &ValueProfNodes[0]); - ValueProfData *VPData = serializeValueProfDataFromRT(&RTRecord); + ValueProfData *VPData = serializeValueProfDataFromRT(&RTRecord, 0); InstrProfRecord Record("caller", 0x1234, {1ULL << 31, 2}); |