summaryrefslogtreecommitdiffstats
path: root/llvm/lib/ProfileData/InstrProfWriter.cpp
diff options
context:
space:
mode:
authorXinliang David Li <davidxl@google.com>2015-12-20 06:22:13 +0000
committerXinliang David Li <davidxl@google.com>2015-12-20 06:22:13 +0000
commita716cc5c33cb22b84c8f91c94e1682c6c8245cc2 (patch)
tree43977a99dc295b1ba2dda5ff76434ae0b74a0e22 /llvm/lib/ProfileData/InstrProfWriter.cpp
parent5c24da5d8e1c27f06598576c51b8d7e2784e2f17 (diff)
downloadbcm5719-llvm-a716cc5c33cb22b84c8f91c94e1682c6c8245cc2.tar.gz
bcm5719-llvm-a716cc5c33cb22b84c8f91c94e1682c6c8245cc2.zip
[PGO] Improve Indexed Profile Reader efficiency
With the support of value profiling added, the Indexed prof reader gets less efficient. The prof reader initialization used to be just reading the file header, but with VP support added, initialization needs to walk through all profile keys of ondisk hash table resulting in very poor locality and large memory increase (keys are stored together with the profile data in the mapped profile buffer). Even worse, when the reader is used by the compiler (not llvm-profdata too), the penalty becomes very high as compilation of each single module requires touching profile data buffer for the whole program. In this patch, the icall target values (MD5hash) are no longer eargerly converted back to name strings when the data is read into memory. New interface is added to to profile reader so that InstrProfSymtab can be lazily created for Indexed profile reader on-demand. Creating of the symtab is intended to be used by llvm-profdata tool for symbolic dumping of VP data. It can be used with compiler (for legacy out of tree uses) too but not recommended due to compile time and memory reasons mentioned above. Some other cleanups are also included: Function Addr to md5 map is now consolated into InstrProfSymtab. InstrProfStringtab is no longer used and eliminated. llvm-svn: 256114
Diffstat (limited to 'llvm/lib/ProfileData/InstrProfWriter.cpp')
-rw-r--r--llvm/lib/ProfileData/InstrProfWriter.cpp16
1 files changed, 8 insertions, 8 deletions
diff --git a/llvm/lib/ProfileData/InstrProfWriter.cpp b/llvm/lib/ProfileData/InstrProfWriter.cpp
index 2f4ef082906..1e18c268892 100644
--- a/llvm/lib/ProfileData/InstrProfWriter.cpp
+++ b/llvm/lib/ProfileData/InstrProfWriter.cpp
@@ -94,13 +94,8 @@ void InstrProfWriter::setValueProfDataEndianness(
ValueProfDataEndianness = Endianness;
}
-void InstrProfWriter::updateStringTableReferences(InstrProfRecord &I) {
- I.updateStrings(&StringTable);
-}
-
std::error_code InstrProfWriter::addRecord(InstrProfRecord &&I,
uint64_t Weight) {
- updateStringTableReferences(I);
auto &ProfileDataMap = FunctionData[I.Name];
bool NewFunc;
@@ -188,6 +183,7 @@ static const char *ValueProfKindStr[] = {
};
void InstrProfWriter::writeRecordInText(const InstrProfRecord &Func,
+ InstrProfSymtab &Symtab,
raw_fd_ostream &OS) {
OS << Func.Name << "\n";
OS << "# Func Hash:\n" << Func.Hash << "\n";
@@ -215,8 +211,7 @@ void InstrProfWriter::writeRecordInText(const InstrProfRecord &Func,
std::unique_ptr<InstrProfValueData[]> VD = Func.getValueForSite(VK, S);
for (uint32_t I = 0; I < ND; I++) {
if (VK == IPVK_IndirectCallTarget)
- OS << reinterpret_cast<const char *>(VD[I].Value) << ":"
- << VD[I].Count << "\n";
+ OS << Symtab.getFuncName(VD[I].Value) << ":" << VD[I].Count << "\n";
else
OS << VD[I].Value << ":" << VD[I].Count << "\n";
}
@@ -227,9 +222,14 @@ void InstrProfWriter::writeRecordInText(const InstrProfRecord &Func,
}
void InstrProfWriter::writeText(raw_fd_ostream &OS) {
+ InstrProfSymtab Symtab;
+ for (const auto &I : FunctionData)
+ Symtab.addFuncName(I.getKey());
+ Symtab.finalizeSymtab();
+
for (const auto &I : FunctionData)
for (const auto &Func : I.getValue())
- writeRecordInText(Func.second, OS);
+ writeRecordInText(Func.second, Symtab, OS);
}
std::unique_ptr<MemoryBuffer> InstrProfWriter::writeBuffer() {
OpenPOWER on IntegriCloud