Skip to content

Commit d6790a0

Browse files
committed
[NFC] ProfileSummary: const most of the fields.
This simplifies readability / maintainability.
1 parent 6638112 commit d6790a0

File tree

7 files changed

+19
-15
lines changed

7 files changed

+19
-15
lines changed

llvm/include/llvm/IR/ProfileSummary.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,9 @@ class ProfileSummary {
4848

4949
private:
5050
const Kind PSK;
51-
SummaryEntryVector DetailedSummary;
52-
uint64_t TotalCount, MaxCount, MaxInternalCount, MaxFunctionCount;
53-
uint32_t NumCounts, NumFunctions;
51+
const SummaryEntryVector DetailedSummary;
52+
const uint64_t TotalCount, MaxCount, MaxInternalCount, MaxFunctionCount;
53+
const uint32_t NumCounts, NumFunctions;
5454
/// If 'Partial' is false, it means the profile being used to optimize
5555
/// a target is collected from the same target.
5656
/// If 'Partial' is true, it means the profile is for common/shared
@@ -68,7 +68,7 @@ class ProfileSummary {
6868
public:
6969
static const int Scale = 1000000;
7070

71-
ProfileSummary(Kind K, SummaryEntryVector DetailedSummary,
71+
ProfileSummary(Kind K, const SummaryEntryVector &DetailedSummary,
7272
uint64_t TotalCount, uint64_t MaxCount,
7373
uint64_t MaxInternalCount, uint64_t MaxFunctionCount,
7474
uint32_t NumCounts, uint32_t NumFunctions,
@@ -85,7 +85,7 @@ class ProfileSummary {
8585
bool AddPartialProfileRatioField = true);
8686
/// Construct profile summary from metdata.
8787
static ProfileSummary *getFromMD(Metadata *MD);
88-
SummaryEntryVector &getDetailedSummary() { return DetailedSummary; }
88+
const SummaryEntryVector &getDetailedSummary() { return DetailedSummary; }
8989
uint32_t getNumFunctions() const { return NumFunctions; }
9090
uint64_t getMaxFunctionCount() const { return MaxFunctionCount; }
9191
uint32_t getNumCounts() const { return NumCounts; }

llvm/include/llvm/ProfileData/ProfileCommon.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,9 @@ class ProfileSummaryBuilder {
6666

6767
/// Find the summary entry for a desired percentile of counts.
6868
static const ProfileSummaryEntry &
69-
getEntryForPercentile(SummaryEntryVector &DS, uint64_t Percentile);
70-
static uint64_t getHotCountThreshold(SummaryEntryVector &DS);
71-
static uint64_t getColdCountThreshold(SummaryEntryVector &DS);
69+
getEntryForPercentile(const SummaryEntryVector &DS, uint64_t Percentile);
70+
static uint64_t getHotCountThreshold(const SummaryEntryVector &DS);
71+
static uint64_t getColdCountThreshold(const SummaryEntryVector &DS);
7272
};
7373

7474
class InstrProfSummaryBuilder final : public ProfileSummaryBuilder {

llvm/lib/ProfileData/InstrProfWriter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ static void setSummary(IndexedInstrProf::Summary *TheSummary,
271271
ProfileSummary &PS) {
272272
using namespace IndexedInstrProf;
273273

274-
std::vector<ProfileSummaryEntry> &Res = PS.getDetailedSummary();
274+
const std::vector<ProfileSummaryEntry> &Res = PS.getDetailedSummary();
275275
TheSummary->NumSummaryFields = Summary::NumKinds;
276276
TheSummary->NumCutoffEntries = Res.size();
277277
TheSummary->set(Summary::MaxFunctionCount, PS.getMaxFunctionCount());

llvm/lib/ProfileData/ProfileSummaryBuilder.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ const ArrayRef<uint32_t> ProfileSummaryBuilder::DefaultCutoffs =
8080
DefaultCutoffsData;
8181

8282
const ProfileSummaryEntry &
83-
ProfileSummaryBuilder::getEntryForPercentile(SummaryEntryVector &DS,
83+
ProfileSummaryBuilder::getEntryForPercentile(const SummaryEntryVector &DS,
8484
uint64_t Percentile) {
8585
auto It = partition_point(DS, [=](const ProfileSummaryEntry &Entry) {
8686
return Entry.Cutoff < Percentile;
@@ -154,7 +154,8 @@ void ProfileSummaryBuilder::computeDetailedSummary() {
154154
}
155155
}
156156

157-
uint64_t ProfileSummaryBuilder::getHotCountThreshold(SummaryEntryVector &DS) {
157+
uint64_t
158+
ProfileSummaryBuilder::getHotCountThreshold(const SummaryEntryVector &DS) {
158159
auto &HotEntry =
159160
ProfileSummaryBuilder::getEntryForPercentile(DS, ProfileSummaryCutoffHot);
160161
uint64_t HotCountThreshold = HotEntry.MinCount;
@@ -163,7 +164,8 @@ uint64_t ProfileSummaryBuilder::getHotCountThreshold(SummaryEntryVector &DS) {
163164
return HotCountThreshold;
164165
}
165166

166-
uint64_t ProfileSummaryBuilder::getColdCountThreshold(SummaryEntryVector &DS) {
167+
uint64_t
168+
ProfileSummaryBuilder::getColdCountThreshold(const SummaryEntryVector &DS) {
167169
auto &ColdEntry = ProfileSummaryBuilder::getEntryForPercentile(
168170
DS, ProfileSummaryCutoffCold);
169171
uint64_t ColdCountThreshold = ColdEntry.MinCount;

llvm/lib/ProfileData/SampleProfWriter.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -734,7 +734,8 @@ std::error_code SampleProfileWriterBinary::writeSummary() {
734734
encodeULEB128(Summary->getMaxFunctionCount(), OS);
735735
encodeULEB128(Summary->getNumCounts(), OS);
736736
encodeULEB128(Summary->getNumFunctions(), OS);
737-
std::vector<ProfileSummaryEntry> &Entries = Summary->getDetailedSummary();
737+
const std::vector<ProfileSummaryEntry> &Entries =
738+
Summary->getDetailedSummary();
738739
encodeULEB128(Entries.size(), OS);
739740
for (auto Entry : Entries) {
740741
encodeULEB128(Entry.Cutoff, OS);

llvm/unittests/ProfileData/InstrProfTest.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ TEST_F(InstrProfTest, get_profile_summary) {
158158
ASSERT_EQ(2305843009213693952U, IPS.getMaxCount());
159159
ASSERT_EQ(10U, IPS.getNumCounts());
160160
ASSERT_EQ(4539628424389557499U, IPS.getTotalCount());
161-
std::vector<ProfileSummaryEntry> &Details = IPS.getDetailedSummary();
161+
const std::vector<ProfileSummaryEntry> &Details = IPS.getDetailedSummary();
162162
uint32_t Cutoff = 800000;
163163
auto Predicate = [&Cutoff](const ProfileSummaryEntry &PE) {
164164
return PE.Cutoff == Cutoff;

llvm/unittests/ProfileData/SampleProfTest.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,8 @@ struct SampleProfTest : ::testing::Test {
9999
auto Predicate = [&Cutoff](const ProfileSummaryEntry &PE) {
100100
return PE.Cutoff == Cutoff;
101101
};
102-
std::vector<ProfileSummaryEntry> &Details = Summary.getDetailedSummary();
102+
const std::vector<ProfileSummaryEntry> &Details =
103+
Summary.getDetailedSummary();
103104
auto EightyPerc = find_if(Details, Predicate);
104105
Cutoff = 900000;
105106
auto NinetyPerc = find_if(Details, Predicate);

0 commit comments

Comments
 (0)