@@ -60,6 +60,36 @@ void StaticDataProfileInfo::addConstantProfileCount(
6060 OriginalCount = getInstrMaxCountValue ();
6161}
6262
63+ StaticDataProfileInfo::StaticDataHotness
64+ StaticDataProfileInfo::getConstantHotnessUsingProfileCount (
65+ const Constant *C, const ProfileSummaryInfo *PSI, uint64_t Count) const {
66+ // The accummulated counter shows the constant is hot. Return enum 'hot'
67+ // whether 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+ // enum 'LukewarmOrUnknown'.
73+ if (ConstantWithoutCounts.count (C))
74+ return StaticDataHotness::LukewarmOrUnknown;
75+ // The accummulated counter shows the constant is cold so return enum 'cold'.
76+ if (PSI->isColdCount (Count))
77+ return StaticDataHotness::Cold;
78+
79+ return StaticDataHotness::LukewarmOrUnknown;
80+ }
81+
82+ StringRef StaticDataProfileInfo::hotnessToStr (StaticDataHotness Hotness) const {
83+ switch (Hotness) {
84+ case StaticDataHotness::Cold:
85+ return " unlikely" ;
86+ case StaticDataHotness::Hot:
87+ return " hot" ;
88+ default :
89+ return " " ;
90+ }
91+ }
92+
6393std::optional<uint64_t >
6494StaticDataProfileInfo::getConstantProfileCount (const Constant *C) const {
6595 auto I = ConstantProfileCounts.find (C);
@@ -70,23 +100,10 @@ StaticDataProfileInfo::getConstantProfileCount(const Constant *C) const {
70100
71101StringRef StaticDataProfileInfo::getConstantSectionPrefix (
72102 const Constant *C, const ProfileSummaryInfo *PSI) const {
73- auto Count = getConstantProfileCount (C);
103+ std::optional< uint64_t > Count = getConstantProfileCount (C);
74104 if (!Count)
75105 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 " " ;
106+ return hotnessToStr (getConstantHotnessUsingProfileCount (C, PSI, *Count));
90107}
91108
92109bool StaticDataProfileInfoWrapperPass::doInitialization (Module &M) {
0 commit comments