14#ifndef LLVM_ANALYSIS_PROFILESUMMARYINFO_H
15#define LLVM_ANALYSIS_PROFILESUMMARYINFO_H
29struct AnalysisOptions;
45 const AnalysisOptions &Opts;
47 std::unique_ptr<ProfileSummary> Summary;
48 void computeThresholds();
50 std::optional<uint64_t> HotCountThreshold, ColdCountThreshold;
54 std::optional<bool> HasHugeWorkingSetSize;
58 std::optional<bool> HasLargeWorkingSetSize;
101 ModuleAnalysisManager::Invalidator &) {
127 std::optional<uint64_t> FunctionCount = getEntryCount(
F);
131 return FunctionCount &&
isHotCount(*FunctionCount);
135 template <
typename FuncT,
typename BFIT>
146 if (
auto FunctionCount = getEntryCount(
F))
150 if (
auto TotalCallCount = getTotalCallCount(
F))
154 for (
const auto &BB : *
F)
162 template <
typename FuncT,
typename BFIT>
173 if (
auto FunctionCount = getEntryCount(
F))
177 if (
auto TotalCallCount = getTotalCallCount(
F))
181 for (
const auto &BB : *
F)
190 template <
typename FuncT,
typename BFIT>
192 const FuncT *
F, BFIT &BFI)
const {
193 return isFunctionHotOrColdInCallGraphNthPercentile<true, FuncT, BFIT>(
198 template <
typename FuncT,
typename BFIT>
200 const FuncT *
F, BFIT &BFI)
const {
201 return isFunctionHotOrColdInCallGraphNthPercentile<false, FuncT, BFIT>(
221 template <
typename BBType,
typename BFIT>
223 auto Count = BFI->getBlockProfileCount(BB);
228 template <
typename BBType,
typename BFIT>
230 auto Count = BFI->getBlockProfileCount(BB);
234 template <
typename BFIT>
236 auto Count = BFI->getProfileCountFromFreq(BlockFreq);
240 template <
typename BBType,
typename BFIT>
247 template <
typename BFIT>
258 template <
typename BBType,
typename BFIT>
264 template <
typename BFIT>
284 return HotCountThreshold.value_or(0);
288 return ColdCountThreshold.value_or(0);
292 template <
typename FuncT>
293 std::optional<uint64_t> getTotalCallCount(
const FuncT *
F)
const {
297 template <
bool isHot,
typename FuncT,
typename BFIT>
303 if (
auto FunctionCount = getEntryCount(
F)) {
309 if (
auto TotalCallCount = getTotalCallCount(
F)) {
316 for (
const auto &BB : *
F) {
325 template <
bool isHot>
328 template <
bool isHot,
typename BBType,
typename BFIT>
331 auto Count = BFI->getBlockProfileCount(BB);
338 template <
bool isHot,
typename BFIT>
340 BlockFrequency BlockFreq,
342 auto Count = BFI->getProfileCountFromFreq(BlockFreq);
349 template <
typename FuncT>
350 std::optional<uint64_t> getEntryCount(
const FuncT *
F)
const {
351 return F->getEntryCount();
356 template <
typename FuncT>
bool hasHotAttr(
const FuncT *
F)
const {
357 return F->hasFnAttribute(Attribute::Hot);
362inline std::optional<uint64_t>
363ProfileSummaryInfo::getTotalCallCount<Function>(
const Function *
F)
const {
367 for (
const auto &BB : *
F)
368 for (
const auto &
I : BB)
371 TotalCallCount += *CallCount;
372 return TotalCallCount;
379std::optional<uint64_t> ProfileSummaryInfo::getEntryCount<MachineFunction>(
383bool ProfileSummaryInfo::hasHotAttr<MachineFunction>(
388 std::unique_ptr<ProfileSummaryInfo> PSI;
397 bool doInitialization(
Module &M)
override;
398 bool doFinalization(
Module &M)
override;
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)
static GCRegistry::Add< ShadowStackGC > C("shadow-stack", "Very portable GC for uncooperative code generators")
This file defines the DenseMap class.
This header defines various interfaces for pass management in LLVM.
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.
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
LLVM_ABI Result run(Module &M, ModuleAnalysisManager &)
ProfileSummaryInfoWrapperPass()
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - This function should be overriden by passes that need analysis information to do t...
ProfileSummaryInfo & getPSI()
const ProfileSummaryInfo & getPSI() const
Analysis providing profile information.
bool hasCSInstrumentationProfile() const
Returns true if module M has context sensitive instrumentation profile.
LLVM_ABI 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.
LLVM_ABI 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.
LLVM_ABI ProfileSummaryInfo(const Module &M)
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.
LLVM_ABI 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.
LLVM_ABI 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.
LLVM_ABI void refresh(std::unique_ptr< ProfileSummary > &&Other=nullptr)
If a summary is provided as argument, use that.
LLVM_ABI 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
LLVM_ABI bool hasPartialSampleProfile() const
Returns true if module M has partial-profile sample profile.
LLVM_ABI bool hasLargeWorkingSetSize() const
Returns true if the working set size of the code is considered large.
LLVM_ABI bool isColdCallSite(const CallBase &CB, BlockFrequencyInfo *BFI) const
Returns true if call site CB is considered cold.
ProfileSummaryInfo(ProfileSummaryInfo &&Arg)=default
LLVM_ABI bool isHotCallSite(const CallBase &CB, BlockFrequencyInfo *BFI) const
Returns true if the call site CB is considered hot.
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
LLVM_ABI bool isHotCount(uint64_t C) const
Returns true if count C is considered hot.
LLVM_ABI 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.
LLVM_ABI 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.
LLVM_ABI std::optional< uint64_t > getProfileCount(const CallBase &CallInst, BlockFrequencyInfo *BFI) const
Returns the profile count for CallInst.
LLVM_ABI bool isFunctionEntryCold(const Function *F) const
Returns true if F has cold function entry.
ProfileSummaryPrinterPass(raw_ostream &OS)
LLVM_ABI PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM)
This class implements an extremely fast bulk output stream that can only output to a stream.
This is an optimization pass for GlobalISel generic memory operations.
bool isa(const From &Val)
isa<X> - Return true if the parameter to the template is an instance of one of the template type argu...
RelativeUniformCounterPtr ValuesPtrExpr VTableAddr Count
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
AnalysisManager< Module > ModuleAnalysisManager
Convenience typedef for the Module analysis manager.
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 for passes that should not be skipped.