<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Nov 24, 2015 at 3:36 PM, Xinliang David Li via llvm-commits <span dir="ltr"><<a href="mailto:llvm-commits@lists.llvm.org" target="_blank">llvm-commits@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: davidxl<br>
Date: Tue Nov 24 17:36:52 2015<br>
New Revision: 254038<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=254038&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project?rev=254038&view=rev</a><br>
Log:<br>
[PGO] Add mapper callback to interfaces retrieving value data for site (NFC)<br>
<br>
This allows cleaner implementation and merging retrieving/mapping in<br>
one pass.<br>
<br>
<br>
Modified:<br>
llvm/trunk/include/llvm/ProfileData/InstrProf.h<br>
llvm/trunk/lib/ProfileData/InstrProf.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=254038&r1=254037&r2=254038&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ProfileData/InstrProf.h?rev=254038&r1=254037&r2=254038&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/include/llvm/ProfileData/InstrProf.h (original)<br>
+++ llvm/trunk/include/llvm/ProfileData/InstrProf.h Tue Nov 24 17:36:52 2015<br>
@@ -261,9 +261,11 @@ struct InstrProfRecord {<br>
uint32_t Site) const;<br>
/// Return the array of profiled values at \p Site.<br>
inline std::unique_ptr<InstrProfValueData[]><br>
- getValueForSite(uint32_t ValueKind, uint32_t Site) const;<br>
- inline void getValueForSite(InstrProfValueData Dest[], uint32_t ValueKind,<br>
- uint32_t Site) const;<br>
+ getValueForSite(uint32_t ValueKind, uint32_t Site,<br>
+ uint64_t (*ValueMapper)(uint32_t, uint64_t) = 0) const;<br>
+ inline void<br>
+ getValueForSite(InstrProfValueData Dest[], uint32_t ValueKind, uint32_t Site,<br>
+ uint64_t (*ValueMapper)(uint32_t, uint64_t) = 0) const;<br>
/// Reserve space for NumValueSites sites.<br>
inline void reserveSites(uint32_t ValueKind, uint32_t NumValueSites);<br>
/// Add ValueData for ValueKind at value Site.<br>
@@ -365,22 +367,27 @@ uint32_t InstrProfRecord::getNumValueDat<br>
return getValueSitesForKind(ValueKind)[Site].ValueData.size();<br>
}<br>
<br>
-std::unique_ptr<InstrProfValueData[]><br>
-InstrProfRecord::getValueForSite(uint32_t ValueKind, uint32_t Site) const {<br>
+std::unique_ptr<InstrProfValueData[]> InstrProfRecord::getValueForSite(<br>
+ uint32_t ValueKind, uint32_t Site,<br>
+ uint64_t (*ValueMapper)(uint32_t, uint64_t)) const {<br>
uint32_t N = getNumValueDataForSite(ValueKind, Site);<br>
if (N == 0)<br>
return std::unique_ptr<InstrProfValueData[]>(nullptr);<br>
<br>
auto VD = llvm::make_unique<InstrProfValueData[]>(N);<br>
- getValueForSite(VD.get(), ValueKind, Site);<br>
+ getValueForSite(VD.get(), ValueKind, Site, ValueMapper);<br>
<br>
return VD;<br>
}<br>
+<br>
void InstrProfRecord::getValueForSite(InstrProfValueData Dest[],<br>
- uint32_t ValueKind, uint32_t Site) const {<br>
+ uint32_t ValueKind, uint32_t Site,<br>
+ uint64_t (*ValueMapper)(uint32_t,<br>
+ uint64_t)) const {<br>
uint32_t I = 0;<br>
for (auto V : getValueSitesForKind(ValueKind)[Site].ValueData) {<br>
- Dest[I] = V;<br>
+ Dest[I].Value = ValueMapper ? ValueMapper(ValueKind, V.Value) : V.Value;<br>
+ Dest[I].Count = V.Count;<br>
I++;<br>
}<br>
}<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=254038&r1=254037&r2=254038&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ProfileData/InstrProf.cpp?rev=254038&r1=254037&r2=254038&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/lib/ProfileData/InstrProf.cpp (original)<br>
+++ llvm/trunk/lib/ProfileData/InstrProf.cpp Tue Nov 24 17:36:52 2015<br>
@@ -131,6 +131,18 @@ GlobalVariable *createPGOFuncNameVar(Fun<br>
return createPGOFuncNameVar(*F.getParent(), F.getLinkage(), FuncName);<br>
}<br>
<br>
+uint64_t StringToHash(uint32_t ValueKind, uint64_t Value) {<br></blockquote><div><br></div><div>Please follow the naming convention.</div><div><br></div><div>-- Sean Silva</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
+ switch (ValueKind) {<br>
+ case IPVK_IndirectCallTarget:<br>
+ return IndexedInstrProf::ComputeHash(IndexedInstrProf::HashType,<br>
+ (const char *)Value);<br>
+ break;<br>
+ default:<br>
+ llvm_unreachable("value kind not handled !");<br>
+ }<br>
+ return Value;<br>
+}<br>
+<br>
void ValueProfRecord::deserializeTo(InstrProfRecord &Record,<br>
InstrProfRecord::ValueMapType *VMap) {<br>
Record.reserveSites(Kind, NumValueSites);<br>
@@ -152,17 +164,7 @@ void ValueProfRecord::serializeFrom(cons<br>
for (uint32_t S = 0; S < NumValueSites; S++) {<br>
uint32_t ND = Record.getNumValueDataForSite(ValueKind, S);<br>
SiteCountArray[S] = ND;<br>
- Record.getValueForSite(DstVD, ValueKind, S);<br>
- for (uint32_t I = 0; I < ND; I++) {<br>
- switch (ValueKind) {<br>
- case IPVK_IndirectCallTarget:<br>
- DstVD[I].Value = IndexedInstrProf::ComputeHash(<br>
- IndexedInstrProf::HashType, (const char *)DstVD[I].Value);<br>
- break;<br>
- default:<br>
- llvm_unreachable("value kind not handled !");<br>
- }<br>
- }<br>
+ Record.getValueForSite(DstVD, ValueKind, S, StringToHash);<br>
DstVD += ND;<br>
}<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>
</blockquote></div><br></div></div>