@@ -60,6 +60,37 @@ void StaticDataProfileInfo::addConstantProfileCount(
6060 OriginalCount = getInstrMaxCountValue ();
6161}
6262
63+ StaticDataProfileInfo::StaticDataHotness
64+ StaticDataProfileInfo::getSectionHotnessUsingProfileCount (
65+ 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.
68+ if (PSI->isHotCount (Count))
69+ return StaticDataHotness::Hot;
70+ // The constant is not hot, and seen by unprofiled functions. We don't want to
71+ // assign it to unlikely sections, even if the counter says 'cold'. So return
72+ // an empty prefix before checking whether the counter is cold.
73+ if (ConstantWithoutCounts.count (C))
74+ return StaticDataHotness::LukewarmOrUnknown;
75+ // The accummulated counter shows the constant is cold. Return 'unlikely'.
76+ if (PSI->isColdCount (Count))
77+ return StaticDataHotness::Cold;
78+
79+ return StaticDataHotness::LukewarmOrUnknown;
80+ }
81+
82+ StringRef StaticDataProfileInfo::hotnessToStr (
83+ StaticDataProfileInfo::StaticDataHotness Hotness) const {
84+ switch (Hotness) {
85+ case StaticDataProfileInfo::StaticDataHotness::Cold:
86+ return " unlikely" ;
87+ case StaticDataProfileInfo::StaticDataHotness::Hot:
88+ return " hot" ;
89+ default :
90+ return " " ;
91+ }
92+ }
93+
6394std::optional<uint64_t >
6495StaticDataProfileInfo::getConstantProfileCount (const Constant *C) const {
6596 auto I = ConstantProfileCounts.find (C);
@@ -70,23 +101,10 @@ StaticDataProfileInfo::getConstantProfileCount(const Constant *C) const {
70101
71102StringRef StaticDataProfileInfo::getConstantSectionPrefix (
72103 const Constant *C, const ProfileSummaryInfo *PSI) const {
73- auto Count = getConstantProfileCount (C);
104+ std::optional< uint64_t > Count = getConstantProfileCount (C);
74105 if (!Count)
75106 return " " ;
76- // The accummulated counter shows the constant is hot. Return 'hot' whether
77- // this variable is seen by unprofiled functions or not.
78- if (PSI->isHotCount (*Count))
79- return " hot" ;
80- // The constant is not hot, and seen by unprofiled functions. We don't want to
81- // assign it to unlikely sections, even if the counter says 'cold'. So return
82- // an empty prefix before checking whether the counter is cold.
83- if (ConstantWithoutCounts.count (C))
84- return " " ;
85- // The accummulated counter shows the constant is cold. Return 'unlikely'.
86- if (PSI->isColdCount (*Count))
87- return " unlikely" ;
88- // The counter says lukewarm. Return an empty prefix.
89- return " " ;
107+ return hotnessToStr (getSectionHotnessUsingProfileCount (C, PSI, *Count));
90108}
91109
92110bool StaticDataProfileInfoWrapperPass::doInitialization (Module &M) {
0 commit comments