14#ifndef LLVM_ANALYSIS_PROFILESUMMARYINFO_H
15#define LLVM_ANALYSIS_PROFILESUMMARYINFO_H
28class BlockFrequencyInfo;
44 std::unique_ptr<ProfileSummary> Summary;
45 void computeThresholds();
47 std::optional<uint64_t> HotCountThreshold, ColdCountThreshold;
51 std::optional<bool> HasHugeWorkingSetSize;
55 std::optional<bool> HasLargeWorkingSetSize;
104 bool AllowSynthetic =
false)
const;
117 std::optional<Function::ProfileCount> FunctionCount = getEntryCount(
F);
121 return FunctionCount &&
isHotCount(FunctionCount->getCount());
125 template <
typename FuncT,
typename BFIT>
129 if (
auto FunctionCount = getEntryCount(
F))
133 if (
auto TotalCallCount = getTotalCallCount(
F))
137 for (
const auto &BB : *
F)
145 template <
typename FuncT,
typename BFIT>
149 if (
auto FunctionCount = getEntryCount(
F))
153 if (
auto TotalCallCount = getTotalCallCount(
F))
157 for (
const auto &BB : *
F)
166 template <
typename FuncT,
typename BFIT>
168 const FuncT *
F, BFIT &BFI)
const {
169 return isFunctionHotOrColdInCallGraphNthPercentile<true, FuncT, BFIT>(
174 template <
typename FuncT,
typename BFIT>
176 const FuncT *
F, BFIT &BFI)
const {
177 return isFunctionHotOrColdInCallGraphNthPercentile<false, FuncT, BFIT>(
196 template <
typename BBType,
typename BFIT>
198 auto Count = BFI->getBlockProfileCount(BB);
203 template <
typename BBType,
typename BFIT>
205 auto Count = BFI->getBlockProfileCount(BB);
209 template <
typename BFIT>
211 auto Count = BFI->getProfileCountFromFreq(BlockFreq);
215 template <
typename BBType,
typename BFIT>
222 template <
typename BFIT>
233 template <
typename BBType,
typename BFIT>
239 template <
typename BFIT>
257 return HotCountThreshold.value_or(0);
261 return ColdCountThreshold.value_or(0);
265 template <
typename FuncT>
266 std::optional<uint64_t> getTotalCallCount(
const FuncT *
F)
const {
270 template <
bool isHot,
typename FuncT,
typename BFIT>
276 if (
auto FunctionCount = getEntryCount(
F)) {
281 FunctionCount->getCount()))
284 if (
auto TotalCallCount = getTotalCallCount(
F)) {
291 for (
const auto &BB : *
F) {
300 template <
bool isHot>
303 template <
bool isHot,
typename BBType,
typename BFIT>
306 auto Count =
BFI->getBlockProfileCount(BB);
313 template <
bool isHot,
typename BFIT>
315 BlockFrequency BlockFreq,
317 auto Count =
BFI->getProfileCountFromFreq(BlockFreq);
324 template <
typename FuncT>
325 std::optional<Function::ProfileCount> getEntryCount(
const FuncT *
F)
const {
326 return F->getEntryCount();
331inline std::optional<uint64_t>
332ProfileSummaryInfo::getTotalCallCount<Function>(
const Function *
F)
const {
336 for (
const auto &BB : *
F)
337 for (
const auto &
I : BB)
338 if (isa<CallInst>(
I) || isa<InvokeInst>(
I))
340 TotalCallCount += *CallCount;
341 return TotalCallCount;
348std::optional<Function::ProfileCount>
349ProfileSummaryInfo::getEntryCount<MachineFunction>(
350 const MachineFunction *
F)
const;
354 std::unique_ptr<ProfileSummaryInfo> PSI;
This file defines the DenseMap class.
This header defines various interfaces for pass management in LLVM.
static cl::opt< unsigned > PercentileCutoff("mfs-psi-cutoff", cl::desc("Percentile profile summary cutoff used to " "determine cold blocks. Unused if set to zero."), cl::init(999950), cl::Hidden)
API to communicate dependencies between analyses during invalidation.
A container for analyses that lazily runs them and caches their results.
Represent the analysis usage information of a pass.
void setPreservesAll()
Set by analyses that do not transform their input at all.
BlockFrequencyInfo pass uses BlockFrequencyInfoImpl implementation to estimate IR basic block frequen...
Base class for all callable instructions (InvokeInst and CallInst) Holds everything related to callin...
This class represents a function call, abstracting a target machine's calling convention.
ImmutablePass class - This class is used to provide information that does not need to be run.
A Module instance is used to store all the information related to an LLVM module.
A set of analyses that are preserved following a run of a transformation pass.
An analysis pass based on the new PM to deliver ProfileSummaryInfo.
ProfileSummaryInfo Result
Result run(Module &M, ModuleAnalysisManager &)
An analysis pass based on legacy pass manager to deliver ProfileSummaryInfo.
bool doFinalization(Module &M) override
doFinalization - Virtual method overriden by subclasses to do any necessary clean up after all passes...
ProfileSummaryInfoWrapperPass()
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - This function should be overriden by passes that need analysis information to do t...
ProfileSummaryInfo & getPSI()
bool doInitialization(Module &M) override
doInitialization - Virtual method overridden by subclasses to do any necessary initialization before ...
const ProfileSummaryInfo & getPSI() const
Analysis providing profile information.
bool hasCSInstrumentationProfile() const
Returns true if module M has context sensitive instrumentation profile.
uint64_t getOrCompColdCountThreshold() const
Returns ColdCountThreshold if set.
bool hasProfileSummary() const
Returns true if profile summary is available.
bool isHotBlockNthPercentile(int PercentileCutoff, const BBType *BB, BFIT *BFI) const
bool isFunctionColdInCallGraph(const FuncT *F, BFIT &BFI) const
Returns true if F contains only cold code.
bool isFunctionHotnessUnknown(const Function &F) const
Returns true if the hotness of F is unknown.
bool hasInstrumentationProfile() const
Returns true if module M has instrumentation profile.
void refresh()
If no summary is present, attempt to refresh.
std::optional< uint64_t > getProfileCount(const CallBase &CallInst, BlockFrequencyInfo *BFI, bool AllowSynthetic=false) const
Returns the profile count for CallInst.
bool isFunctionColdInCallGraphNthPercentile(int PercentileCutoff, const FuncT *F, BFIT &BFI) const
Returns true if F contains cold code with regard to a given cold percentile cutoff value.
bool hasSampleProfile() const
Returns true if module M has sample profile.
bool isFunctionEntryHot(const FuncT *F) const
Returns true if F has hot function entry.
bool isColdBlock(const BBType *BB, BFIT *BFI) const
Returns true if BasicBlock BB is considered cold.
bool isColdCount(uint64_t C) const
Returns true if count C is considered cold.
bool isFunctionHotInCallGraphNthPercentile(int PercentileCutoff, const FuncT *F, BFIT &BFI) const
Returns true if F contains hot code with regard to a given hot percentile cutoff value.
bool isColdCountNthPercentile(int PercentileCutoff, uint64_t C) const
Returns true if count C is considered cold with regard to a given cold percentile cutoff value.
bool isHotCountNthPercentile(int PercentileCutoff, uint64_t C) const
Returns true if count C is considered hot with regard to a given hot percentile cutoff value.
uint64_t getColdCountThreshold() const
Returns ColdCountThreshold if set.
bool isFunctionHotInCallGraph(const FuncT *F, BFIT &BFI) const
Returns true if F contains hot code.
bool isColdBlock(BlockFrequency BlockFreq, const BFIT *BFI) const
bool hasPartialSampleProfile() const
Returns true if module M has partial-profile sample profile.
bool hasLargeWorkingSetSize() const
Returns true if the working set size of the code is considered large.
bool isColdCallSite(const CallBase &CB, BlockFrequencyInfo *BFI) const
Returns true if call site CB is considered cold.
ProfileSummaryInfo(ProfileSummaryInfo &&Arg)=default
bool isHotCallSite(const CallBase &CB, BlockFrequencyInfo *BFI) const
Returns true if the call site CB is considered hot.
ProfileSummaryInfo(const Module &M)
uint64_t getHotCountThreshold() const
Returns HotCountThreshold if set.
bool isHotBlock(const BBType *BB, BFIT *BFI) const
Returns true if BasicBlock BB is considered hot.
bool isColdBlockNthPercentile(int PercentileCutoff, BlockFrequency BlockFreq, BFIT *BFI) const
bool isHotCount(uint64_t C) const
Returns true if count C is considered hot.
bool hasHugeWorkingSetSize() const
Returns true if the working set size of the code is considered huge.
bool isColdBlockNthPercentile(int PercentileCutoff, const BBType *BB, BFIT *BFI) const
Returns true if BasicBlock BB is considered cold with regard to a given cold percentile cutoff value.
uint64_t getOrCompHotCountThreshold() const
Returns HotCountThreshold if set.
bool isHotBlockNthPercentile(int PercentileCutoff, BlockFrequency BlockFreq, BFIT *BFI) const
bool invalidate(Module &, const PreservedAnalyses &, ModuleAnalysisManager::Invalidator &)
Handle the invalidation of this information.
bool isFunctionEntryCold(const Function *F) const
Returns true if F has cold function entry.
Printer pass that uses ProfileSummaryAnalysis.
ProfileSummaryPrinterPass(raw_ostream &OS)
PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM)
This class implements an extremely fast bulk output stream that can only output to a stream.
@ C
The default llvm calling convention, compatible with C.
This is an optimization pass for GlobalISel generic memory operations.
A CRTP mix-in that provides informational APIs needed for analysis passes.
A special type used by analysis passes to provide an address that identifies that particular analysis...
A CRTP mix-in to automatically provide informational APIs needed for passes.