<div dir="ltr">Done.<div><br></div><div>David</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Dec 1, 2015 at 11:34 AM, Vedant Kumar <span dir="ltr"><<a href="mailto:vsk@apple.com" target="_blank">vsk@apple.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br>
> On Nov 27, 2015, at 9:37 PM, Xinliang David Li via llvm-commits <<a href="mailto:llvm-commits@lists.llvm.org">llvm-commits@lists.llvm.org</a>> wrote:<br>
><br>
> Author: davidxl<br>
> Date: Fri Nov 27 23:37:01 2015<br>
> New Revision: 254219<br>
><br>
> URL: <a href="http://llvm.org/viewvc/llvm-project?rev=254219&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project?rev=254219&view=rev</a><br>
> Log:<br>
> [PGO] Allow value profile writer interface to allocated target buffer<br>
><br>
> Raw profile writer needs to write all data of one kind in one continuous block,<br>
> so the buffer needs to be pre-allocated and passed to the writer method in<br>
> pieces for function profile data. The change adds the support for raw value data<br>
> writing.<br>
><br>
> Modified:<br>
>    llvm/trunk/include/llvm/ProfileData/InstrProf.h<br>
>    llvm/trunk/lib/ProfileData/InstrProf.cpp<br>
>    llvm/trunk/unittests/ProfileData/InstrProfTest.cpp<br>
><br>
> Modified: llvm/trunk/include/llvm/ProfileData/InstrProf.h<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ProfileData/InstrProf.h?rev=254219&r1=254218&r2=254219&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ProfileData/InstrProf.h?rev=254219&r1=254218&r2=254219&view=diff</a><br>
> ==============================================================================<br>
> --- llvm/trunk/include/llvm/ProfileData/InstrProf.h (original)<br>
> +++ llvm/trunk/include/llvm/ProfileData/InstrProf.h Fri Nov 27 23:37:01 2015<br>
> @@ -513,7 +513,8 @@ typedef struct ValueProfData {<br>
>   /// All data in the instance are properly byte swapped. The input<br>
>   /// data is assumed to be in little endian order.<br>
>   static ErrorOr<std::unique_ptr<ValueProfData>><br>
> -  getValueProfData(const unsigned char *D, const unsigned char *const BufferEnd,<br>
> +  getValueProfData(const unsigned char *SrcBuffer,<br>
> +                   const unsigned char *const SrcBufferEnd,<br>
>                    support::endianness SrcDataEndianness);<br>
>   /// Swap byte order from \c Endianness order to host byte order.<br>
>   void swapBytesToHost(support::endianness Endianness);<br>
> @@ -596,8 +597,8 @@ uint32_t getValueProfDataSizeRT(const Va<br>
><br>
> /* Return a ValueProfData instance that stores the data collected at runtime. */<br>
> ValueProfData *<br>
> -serializeValueProfDataFromRT(const ValueProfRuntimeRecord *Record);<br>
> -<br>
> +serializeValueProfDataFromRT(const ValueProfRuntimeRecord *Record,<br>
> +                             ValueProfData *Dst);<br>
><br>
> /*! \brief Return the \c ValueProfRecord header size including the<br>
>  * padding bytes.<br>
><br>
> Modified: llvm/trunk/lib/ProfileData/InstrProf.cpp<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ProfileData/InstrProf.cpp?rev=254219&r1=254218&r2=254219&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ProfileData/InstrProf.cpp?rev=254219&r1=254218&r2=254219&view=diff</a><br>
> ==============================================================================<br>
> --- llvm/trunk/lib/ProfileData/InstrProf.cpp (original)<br>
> +++ llvm/trunk/lib/ProfileData/InstrProf.cpp Fri Nov 27 23:37:01 2015<br>
> @@ -170,10 +170,12 @@ void serializeValueProfRecordFrom(ValueP<br>
>   }<br>
> }<br>
><br>
> -ValueProfData *serializeValueProfDataFrom(ValueProfRecordClosure *Closure) {<br>
> +ValueProfData *serializeValueProfDataFrom(ValueProfRecordClosure *Closure,<br>
> +                                          ValueProfData *DstData) {<br>
>   uint32_t TotalSize = getValueProfDataSize(Closure);<br>
><br>
> -  ValueProfData *VPD = Closure->AllocValueProfData(TotalSize);<br>
> +  ValueProfData *VPD =<br>
> +      DstData ? DstData : Closure->AllocValueProfData(TotalSize);<br>
><br>
>   VPD->TotalSize = TotalSize;<br>
>   VPD->NumValueKinds = Closure->GetNumValueKinds(Closure->Record);<br>
> @@ -259,7 +261,7 @@ ValueProfData::serializeFrom(const Instr<br>
>   InstrProfRecordClosure.Record = &Record;<br>
><br>
>   std::unique_ptr<ValueProfData> VPD(<br>
> -      serializeValueProfDataFrom(&InstrProfRecordClosure));<br>
> +      serializeValueProfDataFrom(&InstrProfRecordClosure, 0));<br>
<br>
Could you use `nullptr` here?<br>
<br>
<br>
>   return VPD;<br>
> }<br>
><br>
> @@ -367,16 +369,18 @@ uint32_t getValueProfDataSizeRT(const Va<br>
> }<br>
><br>
> /* Return a ValueProfData instance that stores the data collected<br>
> -   from runtime. */<br>
> + * from runtime. If \c DstData is provided by the caller, the value<br>
> + * profile data will be store in *DstData and DstData is returned,<br>
> + * otherwise the method will allocate space for the value data and<br>
> + * return pointer to the newly allocated space.<br>
> + */<br>
> ValueProfData *<br>
> -serializeValueProfDataFromRT(const ValueProfRuntimeRecord *Record) {<br>
> +serializeValueProfDataFromRT(const ValueProfRuntimeRecord *Record,<br>
> +                             ValueProfData *DstData) {<br>
>   RTRecordClosure.Record = Record;<br>
> -  return serializeValueProfDataFrom(&RTRecordClosure);<br>
> +  return serializeValueProfDataFrom(&RTRecordClosure, DstData);<br>
> }<br>
><br>
> -<br>
> -<br>
> -<br>
> void ValueProfRecord::deserializeTo(InstrProfRecord &Record,<br>
>                                     InstrProfRecord::ValueMapType *VMap) {<br>
>   Record.reserveSites(Kind, NumValueSites);<br>
><br>
> Modified: llvm/trunk/unittests/ProfileData/InstrProfTest.cpp<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/ProfileData/InstrProfTest.cpp?rev=254219&r1=254218&r2=254219&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/ProfileData/InstrProfTest.cpp?rev=254219&r1=254218&r2=254219&view=diff</a><br>
> ==============================================================================<br>
> --- llvm/trunk/unittests/ProfileData/InstrProfTest.cpp (original)<br>
> +++ llvm/trunk/unittests/ProfileData/InstrProfTest.cpp Fri Nov 27 23:37:01 2015<br>
> @@ -409,7 +409,7 @@ TEST_F(InstrProfTest, runtime_value_prof<br>
>   initializeValueProfRuntimeRecord(&RTRecord, &NumValueSites[0],<br>
>                                    &ValueProfNodes[0]);<br>
><br>
> -  ValueProfData *VPData = serializeValueProfDataFromRT(&RTRecord);<br>
> +  ValueProfData *VPData = serializeValueProfDataFromRT(&RTRecord, 0);<br>
<br>
Ditto.<br>
<br>
<br>
><br>
>   InstrProfRecord Record("caller", 0x1234, {1ULL << 31, 2});<br>
><br>
><br>
><br>
> _______________________________________________<br>
> llvm-commits mailing list<br>
> <a href="mailto:llvm-commits@lists.llvm.org">llvm-commits@lists.llvm.org</a><br>
> <a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits</a><br>
<br>
</blockquote></div><br></div>