Skip to content

Commit 15df878

Browse files
committed
[CSSPGO] Fix repeated reading of profile metadata
1 parent cb4f24b commit 15df878

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

llvm/include/llvm/ProfileData/SampleProfReader.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -777,7 +777,7 @@ class SampleProfileReaderExtBinaryBase : public SampleProfileReaderBinary {
777777
std::error_code readSecHdrTable();
778778

779779
std::error_code readFuncMetadata(bool ProfileHasAttribute,
780-
SampleProfileMap &Profiles);
780+
DenseSet<FunctionSamples *> &Profiles);
781781
std::error_code readFuncMetadata(bool ProfileHasAttribute);
782782
std::error_code readFuncMetadata(bool ProfileHasAttribute,
783783
FunctionSamples *FProfile);

llvm/lib/ProfileData/SampleProfReader.cpp

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -831,8 +831,15 @@ SampleProfileReaderExtBinaryBase::read(const DenseSet<StringRef> &FuncsToUse,
831831
if (std::error_code EC = readFuncProfiles(FuncsToUse, Profiles))
832832
return EC;
833833
End = Data;
834+
DenseSet<FunctionSamples *> ProfilesToReadMetadata;
835+
for (auto FName : FuncsToUse) {
836+
auto I = Profiles.find(FName);
837+
if (I != Profiles.end())
838+
ProfilesToReadMetadata.insert(&I->second);
839+
}
834840

835-
if (std::error_code EC = readFuncMetadata(ProfileHasAttribute, Profiles))
841+
if (std::error_code EC =
842+
readFuncMetadata(ProfileHasAttribute, ProfilesToReadMetadata))
836843
return EC;
837844
return sampleprof_error::success;
838845
}
@@ -1300,14 +1307,12 @@ SampleProfileReaderExtBinaryBase::readFuncMetadata(bool ProfileHasAttribute,
13001307
return sampleprof_error::success;
13011308
}
13021309

1303-
std::error_code
1304-
SampleProfileReaderExtBinaryBase::readFuncMetadata(bool ProfileHasAttribute,
1305-
SampleProfileMap &Profiles) {
1310+
std::error_code SampleProfileReaderExtBinaryBase::readFuncMetadata(
1311+
bool ProfileHasAttribute, DenseSet<FunctionSamples *> &Profiles) {
13061312
if (FuncMetadataIndex.empty())
13071313
return sampleprof_error::success;
13081314

1309-
for (auto &I : Profiles) {
1310-
FunctionSamples *FProfile = &I.second;
1315+
for (auto *FProfile : Profiles) {
13111316
auto R = FuncMetadataIndex.find(FProfile->getContext().getHashCode());
13121317
if (R == FuncMetadataIndex.end())
13131318
continue;

0 commit comments

Comments
 (0)