llvm.org GIT mirror llvm / 85aede4
[ProfileSummary] Standardize methods and fix comment Every Analysis pass has a get method that returns a reference of the Result of the Analysis, for example, BlockFrequencyInfo &BlockFrequencyInfoWrapperPass::getBFI(). I believe that ProfileSummaryInfo::getPSI() is the only exception to that, as it was returning a pointer. Another change is renaming isHotBB and isColdBB to isHotBlock and isColdBlock, respectively. Most methods use BB as the argument of variable names while methods usually refer to Basic Blocks as Blocks, instead of BB. For example, Function::getEntryBlock, Loop:getExitBlock, etc. I also fixed one of the comments. Patch by Rodrigo Caetano Rocha! Differential Revision: https://reviews.llvm.org/D54669 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@347182 91177308-0d34-0410-b5e6-96231b3b80d8 Vedant Kumar 9 months ago
11 changed file(s) with 34 addition(s) and 35 deletion(s). Raw diff Collapse all Expand all
9797 bool isFunctionEntryCold(const Function *F);
9898 /// Returns true if \p F contains only cold code.
9999 bool isFunctionColdInCallGraph(const Function *F, BlockFrequencyInfo &BFI);
100 /// Returns true if \p F is a hot function.
100 /// Returns true if count \p C is considered hot.
101101 bool isHotCount(uint64_t C);
102102 /// Returns true if count \p C is considered cold.
103103 bool isColdCount(uint64_t C);
104 /// Returns true if BasicBlock \p B is considered hot.
105 bool isHotBB(const BasicBlock *B, BlockFrequencyInfo *BFI);
106 /// Returns true if BasicBlock \p B is considered cold.
107 bool isColdBB(const BasicBlock *B, BlockFrequencyInfo *BFI);
104 /// Returns true if BasicBlock \p BB is considered hot.
105 bool isHotBlock(const BasicBlock *BB, BlockFrequencyInfo *BFI);
106 /// Returns true if BasicBlock \p BB is considered cold.
107 bool isColdBlock(const BasicBlock *BB, BlockFrequencyInfo *BFI);
108108 /// Returns true if CallSite \p CS is considered hot.
109109 bool isHotCallSite(const CallSite &CS, BlockFrequencyInfo *BFI);
110110 /// Returns true if Callsite \p CS is considered cold.
133133 static char ID;
134134 ProfileSummaryInfoWrapperPass();
135135
136 ProfileSummaryInfo *getPSI() {
137 return &*PSI;
138 }
136 ProfileSummaryInfo &getPSI() { return *PSI; }
137 const ProfileSummaryInfo &getPSI() const { return *PSI; }
139138
140139 bool doInitialization(Module &M) override;
141140 bool doFinalization(Module &M) override;
664664 }
665665
666666 bool ModuleSummaryIndexWrapperPass::runOnModule(Module &M) {
667 auto &PSI = *getAnalysis().getPSI();
667 auto *PSI = &getAnalysis().getPSI();
668668 Index.emplace(buildModuleSummaryIndex(
669669 M,
670670 [this](const Function &F) {
672672 *const_cast(&F))
673673 .getBFI());
674674 },
675 &PSI));
675 PSI));
676676 return false;
677677 }
678678
150150 return true;
151151 }
152152 for (const auto &BB : *F)
153 if (isHotBB(&BB, &BFI))
153 if (isHotBlock(&BB, &BFI))
154154 return true;
155155 return false;
156156 }
179179 return false;
180180 }
181181 for (const auto &BB : *F)
182 if (!isColdBB(&BB, &BFI))
182 if (!isColdBlock(&BB, &BFI))
183183 return false;
184184 return true;
185185 }
252252 return ColdCountThreshold ? ColdCountThreshold.getValue() : 0;
253253 }
254254
255 bool ProfileSummaryInfo::isHotBB(const BasicBlock *B, BlockFrequencyInfo *BFI) {
256 auto Count = BFI->getBlockProfileCount(B);
255 bool ProfileSummaryInfo::isHotBlock(const BasicBlock *BB, BlockFrequencyInfo *BFI) {
256 auto Count = BFI->getBlockProfileCount(BB);
257257 return Count && isHotCount(*Count);
258258 }
259259
260 bool ProfileSummaryInfo::isColdBB(const BasicBlock *B,
260 bool ProfileSummaryInfo::isColdBlock(const BasicBlock *BB,
261261 BlockFrequencyInfo *BFI) {
262 auto Count = BFI->getBlockProfileCount(B);
262 auto Count = BFI->getBlockProfileCount(BB);
263263 return Count && isColdCount(*Count);
264264 }
265265
415415 OptSize = F.optForSize();
416416
417417 ProfileSummaryInfo *PSI =
418 getAnalysis().getPSI();
418 &getAnalysis().getPSI();
419419 if (ProfileGuidedSectionPrefix) {
420420 if (PSI->isFunctionHotInCallGraph(&F, *BFI))
421421 F.setSectionPrefix(".hot");
265265 if (!mayExtractBlock(BB))
266266 continue;
267267 bool Cold =
268 PSI.isColdBB(&BB, BFI) || (EnableStaticAnalyis && unlikelyExecuted(BB));
268 PSI.isColdBlock(&BB, BFI) || (EnableStaticAnalyis && unlikelyExecuted(BB));
269269 if (!Cold)
270270 continue;
271271
464464 if (skipModule(M))
465465 return false;
466466 ProfileSummaryInfo *PSI =
467 getAnalysis().getPSI();
467 &getAnalysis().getPSI();
468468 auto GTTI = [this](Function &F) -> TargetTransformInfo & {
469469 return this->getAnalysis().getTTI(F);
470470 };
745745 bool LegacyInlinerBase::inlineCalls(CallGraphSCC &SCC) {
746746 CallGraph &CG = getAnalysis().getCallGraph();
747747 ACT = &getAnalysis();
748 PSI = getAnalysis().getPSI();
748 PSI = &getAnalysis().getPSI();
749749 auto &TLI = getAnalysis().getTLI();
750750 auto GetAssumptionCache = [&](Function &F) -> AssumptionCache & {
751751 return ACT->getAssumptionCache(F);
358358 TargetTransformInfoWrapperPass *TTIWP =
359359 &getAnalysis();
360360 ProfileSummaryInfo *PSI =
361 getAnalysis().getPSI();
361 &getAnalysis().getPSI();
362362
363363 std::function GetAssumptionCache =
364364 [&ACT](Function &F) -> AssumptionCache & {
467467 // Only consider regions with predecessor blocks that are considered
468468 // not-cold (default: part of the top 99.99% of all block counters)
469469 // AND greater than our minimum block execution count (default: 100).
470 if (PSI->isColdBB(thisBB, BFI) ||
470 if (PSI->isColdBlock(thisBB, BFI) ||
471471 BBProfileCount(thisBB) < MinBlockCounterExecution)
472472 continue;
473473 for (auto SI = succ_begin(thisBB); SI != succ_end(thisBB); ++SI) {
15981598 ACT = &getAnalysis();
15991599 TTIWP = &getAnalysis();
16001600 ProfileSummaryInfo *PSI =
1601 getAnalysis().getPSI();
1601 &getAnalysis().getPSI();
16021602 return SampleLoader.runOnModule(M, nullptr, PSI);
16031603 }
16041604
20392039 getAnalysis().getBFI();
20402040 DominatorTree &DT = getAnalysis().getDomTree();
20412041 ProfileSummaryInfo &PSI =
2042 *getAnalysis().getPSI();
2042 getAnalysis().getPSI();
20432043 RegionInfo &RI = getAnalysis().getRegionInfo();
20442044 std::unique_ptr OwnedORE =
20452045 llvm::make_unique(&F);
426426
427427 bool PGOIndirectCallPromotionLegacyPass::runOnModule(Module &M) {
428428 ProfileSummaryInfo *PSI =
429 getAnalysis().getPSI();
429 &getAnalysis().getPSI();
430430
431431 // Command-line option has the priority for InLTO.
432432 return promoteIndirectCalls(M, PSI, InLTO | ICPLTOMode,
117117 BasicBlock *BB1 = BB0.getTerminator()->getSuccessor(0);
118118
119119 BlockFrequencyInfo BFI = buildBFI(*F);
120 EXPECT_FALSE(PSI.isHotBB(&BB0, &BFI));
121 EXPECT_FALSE(PSI.isColdBB(&BB0, &BFI));
120 EXPECT_FALSE(PSI.isHotBlock(&BB0, &BFI));
121 EXPECT_FALSE(PSI.isColdBlock(&BB0, &BFI));
122122
123123 CallSite CS1(BB1->getFirstNonPHI());
124124 EXPECT_FALSE(PSI.isHotCallSite(CS1, &BFI));
155155 BasicBlock *BB3 = BB1->getSingleSuccessor();
156156
157157 BlockFrequencyInfo BFI = buildBFI(*F);
158 EXPECT_TRUE(PSI.isHotBB(&BB0, &BFI));
159 EXPECT_TRUE(PSI.isHotBB(BB1, &BFI));
160 EXPECT_FALSE(PSI.isHotBB(BB2, &BFI));
161 EXPECT_TRUE(PSI.isHotBB(BB3, &BFI));
158 EXPECT_TRUE(PSI.isHotBlock(&BB0, &BFI));
159 EXPECT_TRUE(PSI.isHotBlock(BB1, &BFI));
160 EXPECT_FALSE(PSI.isHotBlock(BB2, &BFI));
161 EXPECT_TRUE(PSI.isHotBlock(BB3, &BFI));
162162
163163 CallSite CS1(BB1->getFirstNonPHI());
164164 auto *CI2 = BB2->getFirstNonPHI();
187187 BasicBlock *BB3 = BB1->getSingleSuccessor();
188188
189189 BlockFrequencyInfo BFI = buildBFI(*F);
190 EXPECT_TRUE(PSI.isHotBB(&BB0, &BFI));
191 EXPECT_TRUE(PSI.isHotBB(BB1, &BFI));
192 EXPECT_FALSE(PSI.isHotBB(BB2, &BFI));
193 EXPECT_TRUE(PSI.isHotBB(BB3, &BFI));
190 EXPECT_TRUE(PSI.isHotBlock(&BB0, &BFI));
191 EXPECT_TRUE(PSI.isHotBlock(BB1, &BFI));
192 EXPECT_FALSE(PSI.isHotBlock(BB2, &BFI));
193 EXPECT_TRUE(PSI.isHotBlock(BB3, &BFI));
194194
195195 CallSite CS1(BB1->getFirstNonPHI());
196196 auto *CI2 = BB2->getFirstNonPHI();