llvm.org GIT mirror llvm / 9bee4a8
[PGO] Allow value profile writer interface to allocated target buffer Raw profile writer needs to write all data of one kind in one continuous block, so the buffer needs to be pre-allocated and passed to the writer method in pieces for function profile data. The change adds the support for raw value data writing. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@254219 91177308-0d34-0410-b5e6-96231b3b80d8 Xinliang David Li 3 years ago
3 changed file(s) with 19 addition(s) and 14 deletion(s). Raw diff Collapse all Expand all
512512 /// All data in the instance are properly byte swapped. The input
513513 /// data is assumed to be in little endian order.
514514 static ErrorOr>
515 getValueProfData(const unsigned char *D, const unsigned char *const BufferEnd,
515 getValueProfData(const unsigned char *SrcBuffer,
516 const unsigned char *const SrcBufferEnd,
516517 support::endianness SrcDataEndianness);
517518 /// Swap byte order from \c Endianness order to host byte order.
518519 void swapBytesToHost(support::endianness Endianness);
595596
596597 /* Return a ValueProfData instance that stores the data collected at runtime. */
597598 ValueProfData *
598 serializeValueProfDataFromRT(const ValueProfRuntimeRecord *Record);
599
599 serializeValueProfDataFromRT(const ValueProfRuntimeRecord *Record,
600 ValueProfData *Dst);
600601
601602 /*! \brief Return the \c ValueProfRecord header size including the
602603 * padding bytes.
169169 }
170170 }
171171
172 ValueProfData *serializeValueProfDataFrom(ValueProfRecordClosure *Closure) {
172 ValueProfData *serializeValueProfDataFrom(ValueProfRecordClosure *Closure,
173 ValueProfData *DstData) {
173174 uint32_t TotalSize = getValueProfDataSize(Closure);
174175
175 ValueProfData *VPD = Closure->AllocValueProfData(TotalSize);
176 ValueProfData *VPD =
177 DstData ? DstData : Closure->AllocValueProfData(TotalSize);
176178
177179 VPD->TotalSize = TotalSize;
178180 VPD->NumValueKinds = Closure->GetNumValueKinds(Closure->Record);
258260 InstrProfRecordClosure.Record = &Record;
259261
260262 std::unique_ptr VPD(
261 serializeValueProfDataFrom(&InstrProfRecordClosure));
263 serializeValueProfDataFrom(&InstrProfRecordClosure, 0));
262264 return VPD;
263265 }
264266
366368 }
367369
368370 /* Return a ValueProfData instance that stores the data collected
369 from runtime. */
371 * from runtime. If \c DstData is provided by the caller, the value
372 * profile data will be store in *DstData and DstData is returned,
373 * otherwise the method will allocate space for the value data and
374 * return pointer to the newly allocated space.
375 */
370376 ValueProfData *
371 serializeValueProfDataFromRT(const ValueProfRuntimeRecord *Record) {
377 serializeValueProfDataFromRT(const ValueProfRuntimeRecord *Record,
378 ValueProfData *DstData) {
372379 RTRecordClosure.Record = Record;
373 return serializeValueProfDataFrom(&RTRecordClosure);
374 }
375
376
377
380 return serializeValueProfDataFrom(&RTRecordClosure, DstData);
381 }
378382
379383 void ValueProfRecord::deserializeTo(InstrProfRecord &Record,
380384 InstrProfRecord::ValueMapType *VMap) {
408408 initializeValueProfRuntimeRecord(&RTRecord, &NumValueSites[0],
409409 &ValueProfNodes[0]);
410410
411 ValueProfData *VPData = serializeValueProfDataFromRT(&RTRecord);
411 ValueProfData *VPData = serializeValueProfDataFromRT(&RTRecord, 0);
412412
413413 InstrProfRecord Record("caller", 0x1234, {1ULL << 31, 2});
414414