[PGO] Allow value profile writer interface to allocated target buffer
[oota-llvm.git] / lib / ProfileData / InstrProf.cpp
index 54c37e30dba3f0df39b1fe6918a7886485a88b84..3bbc8249c3d0de9b1c905c1fdbd6732b2bfd70d5 100644 (file)
@@ -170,10 +170,12 @@ void serializeValueProfRecordFrom(ValueProfRecord *This,
   }
 }
 
   }
 }
 
-ValueProfData *serializeValueProfDataFrom(ValueProfRecordClosure *Closure) {
+ValueProfData *serializeValueProfDataFrom(ValueProfRecordClosure *Closure,
+                                          ValueProfData *DstData) {
   uint32_t TotalSize = getValueProfDataSize(Closure);
 
   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);
 
   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(
   InstrProfRecordClosure.Record = &Record;
 
   std::unique_ptr<ValueProfData> VPD(
-      serializeValueProfDataFrom(&InstrProfRecordClosure));
+      serializeValueProfDataFrom(&InstrProfRecordClosure, 0));
   return VPD;
 }
 
   return VPD;
 }
 
@@ -367,16 +369,18 @@ uint32_t getValueProfDataSizeRT(const ValueProfRuntimeRecord *Record) {
 }
 
 /* Return a ValueProfData instance that stores the data collected
 }
 
 /* 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 *
 ValueProfData *
-serializeValueProfDataFromRT(const ValueProfRuntimeRecord *Record) {
+serializeValueProfDataFromRT(const ValueProfRuntimeRecord *Record,
+                             ValueProfData *DstData) {
   RTRecordClosure.Record = Record;
   RTRecordClosure.Record = Record;
-  return serializeValueProfDataFrom(&RTRecordClosure);
+  return serializeValueProfDataFrom(&RTRecordClosure, DstData);
 }
 
 }
 
-
-
-
 void ValueProfRecord::deserializeTo(InstrProfRecord &Record,
                                     InstrProfRecord::ValueMapType *VMap) {
   Record.reserveSites(Kind, NumValueSites);
 void ValueProfRecord::deserializeTo(InstrProfRecord &Record,
                                     InstrProfRecord::ValueMapType *VMap) {
   Record.reserveSites(Kind, NumValueSites);