[PATCH] D147740: [NFC][llvm-profdata] Refactoring Sample Profile Reader to increase FDO build speed
William Junda Huang via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Apr 6 14:27:20 PDT 2023
huangjd updated this revision to Diff 511528.
huangjd added a comment.
Use Dense map for main profiles
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D147740/new/
https://reviews.llvm.org/D147740
Files:
llvm/include/llvm/ProfileData/SampleProf.h
llvm/lib/ProfileData/SampleProf.cpp
llvm/lib/ProfileData/SampleProfReader.cpp
llvm/tools/llvm-profgen/ProfileGenerator.cpp
Index: llvm/tools/llvm-profgen/ProfileGenerator.cpp
===================================================================
--- llvm/tools/llvm-profgen/ProfileGenerator.cpp
+++ llvm/tools/llvm-profgen/ProfileGenerator.cpp
@@ -474,7 +474,8 @@
FunctionSamples &
ProfileGenerator::getTopLevelFunctionProfile(StringRef FuncName) {
SampleContext Context(FuncName);
- auto Ret = ProfileMap.emplace(Context.getHashCode(), FunctionSamples());
+ auto Ret = ProfileMap.insert(
+ std::make_pair(Context.getHashCode(), FunctionSamples()));
if (Ret.second) {
FunctionSamples &FProfile = Ret.first->second;
FProfile.setContext(Context);
@@ -967,8 +968,8 @@
Context.emplace_back(Node.getFuncName(), LineLocation(0, 0));
// Save the new context for future references.
SampleContextFrames NewContext = *Contexts.insert(Context).first;
- auto Ret = ProfileMap.emplace(SampleContext(NewContext).getHashCode(),
- std::move(*FProfile));
+ auto Ret = ProfileMap.insert(std::make_pair(
+ SampleContext(NewContext).getHashCode(), std::move(*FProfile)));
FunctionSamples &NewProfile = Ret.first->second;
NewProfile.getContext().setContext(NewContext);
Context.pop_back();
Index: llvm/lib/ProfileData/SampleProfReader.cpp
===================================================================
--- llvm/lib/ProfileData/SampleProfReader.cpp
+++ llvm/lib/ProfileData/SampleProfReader.cpp
@@ -877,6 +877,7 @@
if (!LoadFuncsToBeUsed ||
(UseOrderedFuncOffsets && OrderedFuncOffsets.empty()) ||
(!UseOrderedFuncOffsets && FuncOffsetTable.empty())) {
+
while (Data < End) {
if (std::error_code EC = readFuncProfile(Data))
return EC;
Index: llvm/lib/ProfileData/SampleProf.cpp
===================================================================
--- llvm/lib/ProfileData/SampleProf.cpp
+++ llvm/lib/ProfileData/SampleProf.cpp
@@ -375,8 +375,8 @@
MergedContext = MergedContext.take_back(ColdContextFrameLength);
FunctionSamples NewFunctionSamples;
NewFunctionSamples.setContext(MergedContext);
- auto Ret = MergedProfileMap.emplace(
- SampleContext(MergedContext).getHashCode(), NewFunctionSamples);
+ auto Ret = MergedProfileMap.insert(std::make_pair(
+ SampleContext(MergedContext).getHashCode(), NewFunctionSamples));
FunctionSamples &MergedProfile = Ret.first->second;
MergedProfile.merge(*I.second);
}
@@ -391,7 +391,7 @@
continue;
// Merge the profile if the original profile exists, otherwise just insert
// as a new profile
- auto Ret = ProfileMap.emplace(I.first, FunctionSamples());
+ auto Ret = ProfileMap.insert(std::make_pair(I.first, FunctionSamples()));
FunctionSamples &OrigProfile = Ret.first->second;
OrigProfile.merge(I.second);
}
Index: llvm/include/llvm/ProfileData/SampleProf.h
===================================================================
--- llvm/include/llvm/ProfileData/SampleProf.h
+++ llvm/include/llvm/ProfileData/SampleProf.h
@@ -1228,8 +1228,7 @@
raw_ostream &operator<<(raw_ostream &OS, const FunctionSamples &FS);
-using SampleProfileMap =
- std::unordered_map<FuncHash, FunctionSamples>;
+using SampleProfileMap = llvm::DenseMap<FuncHash, FunctionSamples>;
using NameFunctionSamples = std::pair<FuncHash, const FunctionSamples *>;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D147740.511528.patch
Type: text/x-patch
Size: 3385 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230406/c596d2c6/attachment.bin>
More information about the llvm-commits
mailing list