Skip to content

Commit cb56e9b

Browse files
committed
[llvm][NFC] Use CallBase instead of Instruction in ProfileSummaryInfo
Summary: getProfileCount requires the parameter be a valid CallBase, and its uses reflect that. Reviewers: dblaikie, craig.topper, wmi Subscribers: eraman, hiraditya, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D78940
1 parent cbb6183 commit cb56e9b

File tree

4 files changed

+15
-21
lines changed

4 files changed

+15
-21
lines changed

llvm/include/llvm/Analysis/ProfileSummaryInfo.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ namespace llvm {
2525
class BasicBlock;
2626
class BlockFrequencyInfo;
2727
class CallBase;
28-
class Instruction;
2928
class ProfileSummary;
3029
/// Analysis providing profile information.
3130
///
@@ -97,7 +96,7 @@ class ProfileSummaryInfo {
9796
}
9897

9998
/// Returns the profile count for \p CallInst.
100-
Optional<uint64_t> getProfileCount(const Instruction *CallInst,
99+
Optional<uint64_t> getProfileCount(const CallBase &CallInst,
101100
BlockFrequencyInfo *BFI,
102101
bool AllowSynthetic = false);
103102
/// Returns true if the working set size of the code is considered huge.

llvm/lib/Analysis/ModuleSummaryAnalysis.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ static void computeFunctionSummary(ModuleSummaryIndex &Index, const Module &M,
340340
}
341341
// We should have named any anonymous globals
342342
assert(CalledFunction->hasName());
343-
auto ScaledCount = PSI->getProfileCount(&I, BFI);
343+
auto ScaledCount = PSI->getProfileCount(*CB, BFI);
344344
auto Hotness = ScaledCount ? getHotness(ScaledCount.getValue(), PSI)
345345
: CalleeInfo::HotnessType::Unknown;
346346
if (ForceSummaryEdgesCold != FunctionSummary::FSHT_None)

llvm/lib/Analysis/ProfileSummaryInfo.cpp

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -101,27 +101,23 @@ bool ProfileSummaryInfo::computeSummary() {
101101
return true;
102102
}
103103

104-
// FIXME(CallSite): the parameter should be a CallBase.
105-
Optional<uint64_t>
106-
ProfileSummaryInfo::getProfileCount(const Instruction *Inst,
107-
BlockFrequencyInfo *BFI,
108-
bool AllowSynthetic) {
109-
if (!Inst)
110-
return None;
111-
assert((isa<CallInst>(Inst) || isa<InvokeInst>(Inst)) &&
104+
Optional<uint64_t> ProfileSummaryInfo::getProfileCount(const CallBase &Call,
105+
BlockFrequencyInfo *BFI,
106+
bool AllowSynthetic) {
107+
assert((isa<CallInst>(Call) || isa<InvokeInst>(Call)) &&
112108
"We can only get profile count for call/invoke instruction.");
113109
if (hasSampleProfile()) {
114110
// In sample PGO mode, check if there is a profile metadata on the
115111
// instruction. If it is present, determine hotness solely based on that,
116112
// since the sampled entry count may not be accurate. If there is no
117113
// annotated on the instruction, return None.
118114
uint64_t TotalCount;
119-
if (Inst->extractProfTotalWeight(TotalCount))
115+
if (Call.extractProfTotalWeight(TotalCount))
120116
return TotalCount;
121117
return None;
122118
}
123119
if (BFI)
124-
return BFI->getBlockProfileCount(Inst->getParent(), AllowSynthetic);
120+
return BFI->getBlockProfileCount(Call.getParent(), AllowSynthetic);
125121
return None;
126122
}
127123

@@ -156,7 +152,7 @@ bool ProfileSummaryInfo::isFunctionHotInCallGraph(const Function *F,
156152
for (const auto &BB : *F)
157153
for (const auto &I : BB)
158154
if (isa<CallInst>(I) || isa<InvokeInst>(I))
159-
if (auto CallCount = getProfileCount(&I, nullptr))
155+
if (auto CallCount = getProfileCount(cast<CallBase>(I), nullptr))
160156
TotalCallCount += CallCount.getValue();
161157
if (isHotCount(TotalCallCount))
162158
return true;
@@ -185,7 +181,7 @@ bool ProfileSummaryInfo::isFunctionColdInCallGraph(const Function *F,
185181
for (const auto &BB : *F)
186182
for (const auto &I : BB)
187183
if (isa<CallInst>(I) || isa<InvokeInst>(I))
188-
if (auto CallCount = getProfileCount(&I, nullptr))
184+
if (auto CallCount = getProfileCount(cast<CallBase>(I), nullptr))
189185
TotalCallCount += CallCount.getValue();
190186
if (!isColdCount(TotalCallCount))
191187
return false;
@@ -214,7 +210,7 @@ bool ProfileSummaryInfo::isFunctionHotOrColdInCallGraphNthPercentile(
214210
for (const auto &BB : *F)
215211
for (const auto &I : BB)
216212
if (isa<CallInst>(I) || isa<InvokeInst>(I))
217-
if (auto CallCount = getProfileCount(&I, nullptr))
213+
if (auto CallCount = getProfileCount(cast<CallBase>(I), nullptr))
218214
TotalCallCount += CallCount.getValue();
219215
if (isHot && isHotCountNthPercentile(PercentileCutoff, TotalCallCount))
220216
return true;
@@ -388,13 +384,13 @@ bool ProfileSummaryInfo::isColdBlockNthPercentile(int PercentileCutoff,
388384

389385
bool ProfileSummaryInfo::isHotCallSite(const CallBase &CB,
390386
BlockFrequencyInfo *BFI) {
391-
auto C = getProfileCount(&CB, BFI);
387+
auto C = getProfileCount(CB, BFI);
392388
return C && isHotCount(*C);
393389
}
394390

395391
bool ProfileSummaryInfo::isColdCallSite(const CallBase &CB,
396392
BlockFrequencyInfo *BFI) {
397-
auto C = getProfileCount(&CB, BFI);
393+
auto C = getProfileCount(CB, BFI);
398394
if (C)
399395
return isColdCount(*C);
400396

llvm/lib/Transforms/Utils/InlineFunction.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1559,8 +1559,7 @@ static void updateCallerBFI(BasicBlock *CallSiteBlock,
15591559
/// Update the branch metadata for cloned call instructions.
15601560
static void updateCallProfile(Function *Callee, const ValueToValueMapTy &VMap,
15611561
const ProfileCount &CalleeEntryCount,
1562-
const Instruction *TheCall,
1563-
ProfileSummaryInfo *PSI,
1562+
const CallBase &TheCall, ProfileSummaryInfo *PSI,
15641563
BlockFrequencyInfo *CallerBFI) {
15651564
if (!CalleeEntryCount.hasValue() || CalleeEntryCount.isSynthetic() ||
15661565
CalleeEntryCount.getCount() < 1)
@@ -1810,7 +1809,7 @@ llvm::InlineResult llvm::InlineFunction(CallBase &CB, InlineFunctionInfo &IFI,
18101809
updateCallerBFI(OrigBB, VMap, IFI.CallerBFI, IFI.CalleeBFI,
18111810
CalledFunc->front());
18121811

1813-
updateCallProfile(CalledFunc, VMap, CalledFunc->getEntryCount(), &CB,
1812+
updateCallProfile(CalledFunc, VMap, CalledFunc->getEntryCount(), CB,
18141813
IFI.PSI, IFI.CallerBFI);
18151814

18161815
// Inject byval arguments initialization.

0 commit comments

Comments
 (0)