[llvm] d6790a0 - [NFC] ProfileSummary: const most of the fields.
Mircea Trofin via llvm-commits
llvm-commits at lists.llvm.org
Fri Oct 29 08:36:37 PDT 2021
Author: Mircea Trofin
Date: 2021-10-29T08:36:08-07:00
New Revision: d6790a0a3ce769fc6f37b2577c074d30cb92dbc2
URL: https://github.com/llvm/llvm-project/commit/d6790a0a3ce769fc6f37b2577c074d30cb92dbc2
DIFF: https://github.com/llvm/llvm-project/commit/d6790a0a3ce769fc6f37b2577c074d30cb92dbc2.diff
LOG: [NFC] ProfileSummary: const most of the fields.
This simplifies readability / maintainability.
Added:
Modified:
llvm/include/llvm/IR/ProfileSummary.h
llvm/include/llvm/ProfileData/ProfileCommon.h
llvm/lib/ProfileData/InstrProfWriter.cpp
llvm/lib/ProfileData/ProfileSummaryBuilder.cpp
llvm/lib/ProfileData/SampleProfWriter.cpp
llvm/unittests/ProfileData/InstrProfTest.cpp
llvm/unittests/ProfileData/SampleProfTest.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/IR/ProfileSummary.h b/llvm/include/llvm/IR/ProfileSummary.h
index d00bfae897117..4bb6bb8d4a405 100644
--- a/llvm/include/llvm/IR/ProfileSummary.h
+++ b/llvm/include/llvm/IR/ProfileSummary.h
@@ -48,9 +48,9 @@ class ProfileSummary {
private:
const Kind PSK;
- SummaryEntryVector DetailedSummary;
- uint64_t TotalCount, MaxCount, MaxInternalCount, MaxFunctionCount;
- uint32_t NumCounts, NumFunctions;
+ const SummaryEntryVector DetailedSummary;
+ const uint64_t TotalCount, MaxCount, MaxInternalCount, MaxFunctionCount;
+ const uint32_t NumCounts, NumFunctions;
/// If 'Partial' is false, it means the profile being used to optimize
/// a target is collected from the same target.
/// If 'Partial' is true, it means the profile is for common/shared
@@ -68,7 +68,7 @@ class ProfileSummary {
public:
static const int Scale = 1000000;
- ProfileSummary(Kind K, SummaryEntryVector DetailedSummary,
+ ProfileSummary(Kind K, const SummaryEntryVector &DetailedSummary,
uint64_t TotalCount, uint64_t MaxCount,
uint64_t MaxInternalCount, uint64_t MaxFunctionCount,
uint32_t NumCounts, uint32_t NumFunctions,
@@ -85,7 +85,7 @@ class ProfileSummary {
bool AddPartialProfileRatioField = true);
/// Construct profile summary from metdata.
static ProfileSummary *getFromMD(Metadata *MD);
- SummaryEntryVector &getDetailedSummary() { return DetailedSummary; }
+ const SummaryEntryVector &getDetailedSummary() { return DetailedSummary; }
uint32_t getNumFunctions() const { return NumFunctions; }
uint64_t getMaxFunctionCount() const { return MaxFunctionCount; }
uint32_t getNumCounts() const { return NumCounts; }
diff --git a/llvm/include/llvm/ProfileData/ProfileCommon.h b/llvm/include/llvm/ProfileData/ProfileCommon.h
index 2cb01483a58d3..ad92af22d92e5 100644
--- a/llvm/include/llvm/ProfileData/ProfileCommon.h
+++ b/llvm/include/llvm/ProfileData/ProfileCommon.h
@@ -66,9 +66,9 @@ class ProfileSummaryBuilder {
/// Find the summary entry for a desired percentile of counts.
static const ProfileSummaryEntry &
- getEntryForPercentile(SummaryEntryVector &DS, uint64_t Percentile);
- static uint64_t getHotCountThreshold(SummaryEntryVector &DS);
- static uint64_t getColdCountThreshold(SummaryEntryVector &DS);
+ getEntryForPercentile(const SummaryEntryVector &DS, uint64_t Percentile);
+ static uint64_t getHotCountThreshold(const SummaryEntryVector &DS);
+ static uint64_t getColdCountThreshold(const SummaryEntryVector &DS);
};
class InstrProfSummaryBuilder final : public ProfileSummaryBuilder {
diff --git a/llvm/lib/ProfileData/InstrProfWriter.cpp b/llvm/lib/ProfileData/InstrProfWriter.cpp
index 1c897570135e0..492e3541cb5a7 100644
--- a/llvm/lib/ProfileData/InstrProfWriter.cpp
+++ b/llvm/lib/ProfileData/InstrProfWriter.cpp
@@ -271,7 +271,7 @@ static void setSummary(IndexedInstrProf::Summary *TheSummary,
ProfileSummary &PS) {
using namespace IndexedInstrProf;
- std::vector<ProfileSummaryEntry> &Res = PS.getDetailedSummary();
+ const std::vector<ProfileSummaryEntry> &Res = PS.getDetailedSummary();
TheSummary->NumSummaryFields = Summary::NumKinds;
TheSummary->NumCutoffEntries = Res.size();
TheSummary->set(Summary::MaxFunctionCount, PS.getMaxFunctionCount());
diff --git a/llvm/lib/ProfileData/ProfileSummaryBuilder.cpp b/llvm/lib/ProfileData/ProfileSummaryBuilder.cpp
index d1f1afbfcf04f..49d1c39fda712 100644
--- a/llvm/lib/ProfileData/ProfileSummaryBuilder.cpp
+++ b/llvm/lib/ProfileData/ProfileSummaryBuilder.cpp
@@ -80,7 +80,7 @@ const ArrayRef<uint32_t> ProfileSummaryBuilder::DefaultCutoffs =
DefaultCutoffsData;
const ProfileSummaryEntry &
-ProfileSummaryBuilder::getEntryForPercentile(SummaryEntryVector &DS,
+ProfileSummaryBuilder::getEntryForPercentile(const SummaryEntryVector &DS,
uint64_t Percentile) {
auto It = partition_point(DS, [=](const ProfileSummaryEntry &Entry) {
return Entry.Cutoff < Percentile;
@@ -154,7 +154,8 @@ void ProfileSummaryBuilder::computeDetailedSummary() {
}
}
-uint64_t ProfileSummaryBuilder::getHotCountThreshold(SummaryEntryVector &DS) {
+uint64_t
+ProfileSummaryBuilder::getHotCountThreshold(const SummaryEntryVector &DS) {
auto &HotEntry =
ProfileSummaryBuilder::getEntryForPercentile(DS, ProfileSummaryCutoffHot);
uint64_t HotCountThreshold = HotEntry.MinCount;
@@ -163,7 +164,8 @@ uint64_t ProfileSummaryBuilder::getHotCountThreshold(SummaryEntryVector &DS) {
return HotCountThreshold;
}
-uint64_t ProfileSummaryBuilder::getColdCountThreshold(SummaryEntryVector &DS) {
+uint64_t
+ProfileSummaryBuilder::getColdCountThreshold(const SummaryEntryVector &DS) {
auto &ColdEntry = ProfileSummaryBuilder::getEntryForPercentile(
DS, ProfileSummaryCutoffCold);
uint64_t ColdCountThreshold = ColdEntry.MinCount;
diff --git a/llvm/lib/ProfileData/SampleProfWriter.cpp b/llvm/lib/ProfileData/SampleProfWriter.cpp
index 790fd3ef3376f..78006aab1541a 100644
--- a/llvm/lib/ProfileData/SampleProfWriter.cpp
+++ b/llvm/lib/ProfileData/SampleProfWriter.cpp
@@ -734,7 +734,8 @@ std::error_code SampleProfileWriterBinary::writeSummary() {
encodeULEB128(Summary->getMaxFunctionCount(), OS);
encodeULEB128(Summary->getNumCounts(), OS);
encodeULEB128(Summary->getNumFunctions(), OS);
- std::vector<ProfileSummaryEntry> &Entries = Summary->getDetailedSummary();
+ const std::vector<ProfileSummaryEntry> &Entries =
+ Summary->getDetailedSummary();
encodeULEB128(Entries.size(), OS);
for (auto Entry : Entries) {
encodeULEB128(Entry.Cutoff, OS);
diff --git a/llvm/unittests/ProfileData/InstrProfTest.cpp b/llvm/unittests/ProfileData/InstrProfTest.cpp
index d7661776d75fa..7bdd6c2992859 100644
--- a/llvm/unittests/ProfileData/InstrProfTest.cpp
+++ b/llvm/unittests/ProfileData/InstrProfTest.cpp
@@ -158,7 +158,7 @@ TEST_F(InstrProfTest, get_profile_summary) {
ASSERT_EQ(2305843009213693952U, IPS.getMaxCount());
ASSERT_EQ(10U, IPS.getNumCounts());
ASSERT_EQ(4539628424389557499U, IPS.getTotalCount());
- std::vector<ProfileSummaryEntry> &Details = IPS.getDetailedSummary();
+ const std::vector<ProfileSummaryEntry> &Details = IPS.getDetailedSummary();
uint32_t Cutoff = 800000;
auto Predicate = [&Cutoff](const ProfileSummaryEntry &PE) {
return PE.Cutoff == Cutoff;
diff --git a/llvm/unittests/ProfileData/SampleProfTest.cpp b/llvm/unittests/ProfileData/SampleProfTest.cpp
index d4c657edc8c5a..92925c7e9e683 100644
--- a/llvm/unittests/ProfileData/SampleProfTest.cpp
+++ b/llvm/unittests/ProfileData/SampleProfTest.cpp
@@ -99,7 +99,8 @@ struct SampleProfTest : ::testing::Test {
auto Predicate = [&Cutoff](const ProfileSummaryEntry &PE) {
return PE.Cutoff == Cutoff;
};
- std::vector<ProfileSummaryEntry> &Details = Summary.getDetailedSummary();
+ const std::vector<ProfileSummaryEntry> &Details =
+ Summary.getDetailedSummary();
auto EightyPerc = find_if(Details, Predicate);
Cutoff = 900000;
auto NinetyPerc = find_if(Details, Predicate);
More information about the llvm-commits
mailing list