@@ -57,6 +57,37 @@ void StaticDataProfileInfo::addConstantProfileCount(
5757 OriginalCount = getInstrMaxCountValue ();
5858}
5959
60+ StaticDataProfileInfo::StaticDataHotness
61+ StaticDataProfileInfo::getSectionHotnessUsingProfileCount (
62+ const Constant *C, const ProfileSummaryInfo *PSI, uint64_t Count) const {
63+ // The accummulated counter shows the constant is hot. Return 'hot' whether
64+ // this variable is seen by unprofiled functions or not.
65+ if (PSI->isHotCount (Count))
66+ return StaticDataHotness::Hot;
67+ // The constant is not hot, and seen by unprofiled functions. We don't want to
68+ // assign it to unlikely sections, even if the counter says 'cold'. So return
69+ // an empty prefix before checking whether the counter is cold.
70+ if (ConstantWithoutCounts.count (C))
71+ return StaticDataHotness::LukewarmOrUnknown;
72+ // The accummulated counter shows the constant is cold. Return 'unlikely'.
73+ if (PSI->isColdCount (Count))
74+ return StaticDataHotness::Cold;
75+
76+ return StaticDataHotness::LukewarmOrUnknown;
77+ }
78+
79+ StringRef StaticDataProfileInfo::hotnessToStr (
80+ StaticDataProfileInfo::StaticDataHotness Hotness) const {
81+ switch (Hotness) {
82+ case StaticDataProfileInfo::StaticDataHotness::Cold:
83+ return " unlikely" ;
84+ case StaticDataProfileInfo::StaticDataHotness::Hot:
85+ return " hot" ;
86+ default :
87+ return " " ;
88+ }
89+ }
90+
6091std::optional<uint64_t >
6192StaticDataProfileInfo::getConstantProfileCount (const Constant *C) const {
6293 auto I = ConstantProfileCounts.find (C);
@@ -67,23 +98,10 @@ StaticDataProfileInfo::getConstantProfileCount(const Constant *C) const {
6798
6899StringRef StaticDataProfileInfo::getConstantSectionPrefix (
69100 const Constant *C, const ProfileSummaryInfo *PSI) const {
70- auto Count = getConstantProfileCount (C);
101+ std::optional< uint64_t > Count = getConstantProfileCount (C);
71102 if (!Count)
72103 return " " ;
73- // The accummulated counter shows the constant is hot. Return 'hot' whether
74- // this variable is seen by unprofiled functions or not.
75- if (PSI->isHotCount (*Count))
76- return " hot" ;
77- // The constant is not hot, and seen by unprofiled functions. We don't want to
78- // assign it to unlikely sections, even if the counter says 'cold'. So return
79- // an empty prefix before checking whether the counter is cold.
80- if (ConstantWithoutCounts.count (C))
81- return " " ;
82- // The accummulated counter shows the constant is cold. Return 'unlikely'.
83- if (PSI->isColdCount (*Count))
84- return " unlikely" ;
85- // The counter says lukewarm. Return an empty prefix.
86- return " " ;
104+ return hotnessToStr (getSectionHotnessUsingProfileCount (C, PSI, *Count));
87105}
88106
89107bool StaticDataProfileInfoWrapperPass::doInitialization (Module &M) {
0 commit comments