Skip to content

Commit 433f716

Browse files
resolve comments
1 parent 9a177c2 commit 433f716

File tree

2 files changed

+16
-15
lines changed

2 files changed

+16
-15
lines changed

llvm/include/llvm/Analysis/StaticDataProfileInfo.h

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,17 @@ class StaticDataProfileInfo {
4747
LLVM_ABI std::optional<uint64_t>
4848
getConstantProfileCount(const Constant *C) const;
4949

50-
enum class StaticDataHotness : uint8_t {
51-
Cold = 0,
52-
LukewarmOrUnknown = 1,
53-
Hot = 2,
50+
/// Use signed enums for enum value comparison, and make 'LukewarmOrUnknown'
51+
/// as 0 so any accidentally uninitialized value will default to unknown.
52+
enum class StaticDataHotness : int8_t {
53+
Cold = -1,
54+
LukewarmOrUnknown = 0,
55+
Hot = 1,
5456
};
5557

5658
/// Return the hotness of the constant \p C based on its profile count \p
5759
/// Count.
58-
LLVM_ABI StaticDataHotness getSectionHotnessUsingProfileCount(
60+
LLVM_ABI StaticDataHotness getConstantHotnessUsingProfileCount(
5961
const Constant *C, const ProfileSummaryInfo *PSI, uint64_t Count) const;
6062

6163
/// Return the string representation of the hotness enum \p Hotness.

llvm/lib/Analysis/StaticDataProfileInfo.cpp

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -61,30 +61,29 @@ void StaticDataProfileInfo::addConstantProfileCount(
6161
}
6262

6363
StaticDataProfileInfo::StaticDataHotness
64-
StaticDataProfileInfo::getSectionHotnessUsingProfileCount(
64+
StaticDataProfileInfo::getConstantHotnessUsingProfileCount(
6565
const Constant *C, const ProfileSummaryInfo *PSI, uint64_t Count) const {
66-
// The accummulated counter shows the constant is hot. Return 'hot' whether
67-
// this variable is seen by unprofiled functions or not.
66+
// The accummulated counter shows the constant is hot. Return enum 'hot'
67+
// whether this variable is seen by unprofiled functions or not.
6868
if (PSI->isHotCount(Count))
6969
return StaticDataHotness::Hot;
7070
// The constant is not hot, and seen by unprofiled functions. We don't want to
7171
// assign it to unlikely sections, even if the counter says 'cold'. So return
72-
// an empty prefix before checking whether the counter is cold.
72+
// enum 'LukewarmOrUnknown'.
7373
if (ConstantWithoutCounts.count(C))
7474
return StaticDataHotness::LukewarmOrUnknown;
75-
// The accummulated counter shows the constant is cold. Return 'unlikely'.
75+
// The accummulated counter shows the constant is cold so return enum 'cold'.
7676
if (PSI->isColdCount(Count))
7777
return StaticDataHotness::Cold;
7878

7979
return StaticDataHotness::LukewarmOrUnknown;
8080
}
8181

82-
StringRef StaticDataProfileInfo::hotnessToStr(
83-
StaticDataProfileInfo::StaticDataHotness Hotness) const {
82+
StringRef StaticDataProfileInfo::hotnessToStr(StaticDataHotness Hotness) const {
8483
switch (Hotness) {
85-
case StaticDataProfileInfo::StaticDataHotness::Cold:
84+
case StaticDataHotness::Cold:
8685
return "unlikely";
87-
case StaticDataProfileInfo::StaticDataHotness::Hot:
86+
case StaticDataHotness::Hot:
8887
return "hot";
8988
default:
9089
return "";
@@ -104,7 +103,7 @@ StringRef StaticDataProfileInfo::getConstantSectionPrefix(
104103
std::optional<uint64_t> Count = getConstantProfileCount(C);
105104
if (!Count)
106105
return "";
107-
return hotnessToStr(getSectionHotnessUsingProfileCount(C, PSI, *Count));
106+
return hotnessToStr(getConstantHotnessUsingProfileCount(C, PSI, *Count));
108107
}
109108

110109
bool StaticDataProfileInfoWrapperPass::doInitialization(Module &M) {

0 commit comments

Comments
 (0)