34 cl::desc(
"A count is hot if it exceeds the minimum count to" 35 " reach this percentile of total counts."));
39 cl::desc(
"A count is cold if it is below the minimum count" 40 " to reach this percentile of total counts."));
43 "profile-summary-huge-working-set-size-threshold",
cl::Hidden,
45 cl::desc(
"The code working set size is considered huge if the number of" 46 " blocks required to reach the -profile-summary-cutoff-hot" 47 " percentile exceeds this count."));
53 cl::desc(
"A fixed hot count that overrides the count derived from" 54 " profile-summary-cutoff-hot"));
58 cl::desc(
"A fixed cold count that overrides the count derived from" 59 " profile-summary-cutoff-cold"));
63 uint64_t Percentile) {
65 return Entry.
Cutoff < Percentile;
80 bool ProfileSummaryInfo::computeSummary() {
95 assert((isa<CallInst>(Inst) || isa<InvokeInst>(Inst)) &&
96 "We can only get profile count for call/invoke instruction.");
116 if (!F || !computeSummary())
122 return FunctionCount &&
isHotCount(FunctionCount.getCount());
132 if (!F || !computeSummary())
139 uint64_t TotalCallCount = 0;
140 for (
const auto &BB : *F)
141 for (
const auto &
I : BB)
142 if (isa<CallInst>(
I) || isa<InvokeInst>(
I))
144 TotalCallCount += CallCount.getValue();
148 for (
const auto &BB : *F)
161 if (!F || !computeSummary())
168 uint64_t TotalCallCount = 0;
169 for (
const auto &BB : *F)
170 for (
const auto &
I : BB)
171 if (isa<CallInst>(
I) || isa<InvokeInst>(
I))
173 TotalCallCount += CallCount.getValue();
177 for (
const auto &BB : *F)
191 if (!computeSummary())
197 return FunctionCount &&
isColdCount(FunctionCount.getCount());
201 void ProfileSummaryInfo::computeThresholds() {
202 if (!computeSummary())
204 auto &DetailedSummary = Summary->getDetailedSummary();
207 HotCountThreshold = HotEntry.MinCount;
212 ColdCountThreshold = ColdEntry.MinCount;
215 assert(ColdCountThreshold <= HotCountThreshold &&
216 "Cold count threshold cannot exceed hot count threshold!");
217 HasHugeWorkingSetSize =
222 if (!HasHugeWorkingSetSize)
224 return HasHugeWorkingSetSize && HasHugeWorkingSetSize.
getValue();
228 if (!HotCountThreshold)
230 return HotCountThreshold && C >= HotCountThreshold.
getValue();
234 if (!ColdCountThreshold)
236 return ColdCountThreshold && C <= ColdCountThreshold.
getValue();
240 if (!HotCountThreshold)
246 if (!ColdCountThreshold)
248 return ColdCountThreshold ? ColdCountThreshold.
getValue() : 0;
280 "Profile summary info",
false,
true)
307 OS <<
"Functions in " << M.
getName() <<
" with hot/cold annotations: \n";
311 OS <<
" :hot entry ";
313 OS <<
" :cold entry ";
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
uint32_t Cutoff
The required percentile of counts.
PassT::Result & getResult(IRUnitT &IR, ExtraArgTs... ExtraArgs)
Get the result of an analysis pass for a given IR unit.
LLVM_ATTRIBUTE_NORETURN void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
This class represents lattice values for constants.
A Module instance is used to store all the information related to an LLVM module. ...
bool isColdCount(uint64_t C)
Returns true if count C is considered cold.
Analysis providing profile information.
bool hasFnAttribute(Attribute::AttrKind Kind) const
Return true if the function has the attribute.
Optional< uint64_t > getProfileCount(const Instruction *CallInst, BlockFrequencyInfo *BFI)
Returns the profile count for CallInst.
StringRef getName() const
Get a short "name" for the module.
uint64_t getOrCompHotCountThreshold()
Returns HotCountThreshold if set.
static cl::opt< unsigned > ProfileSummaryHugeWorkingSetSizeThreshold("profile-summary-huge-working-set-size-threshold", cl::Hidden, cl::init(15000), cl::ZeroOrMore, cl::desc("The code working set size is considered huge if the number of" " blocks required to reach the -profile-summary-cutoff-hot" " percentile exceeds this count."))
bool isHotCount(uint64_t C)
Returns true if count C is considered hot.
bool isFunctionEntryCold(const Function *F)
Returns true if F has cold function entry.
bool isHotCallSite(const CallSite &CS, BlockFrequencyInfo *BFI)
Returns true if CallSite CS is considered hot.
static cl::opt< int > ProfileSummaryHotCount("profile-summary-hot-count", cl::ReallyHidden, cl::ZeroOrMore, cl::desc("A fixed hot count that overrides the count derived from" " profile-summary-cutoff-hot"))
uint64_t getOrCompColdCountThreshold()
Returns ColdCountThreshold if set.
Result run(Module &M, ModuleAnalysisManager &)
bool isFunctionHotInCallGraph(const Function *F, BlockFrequencyInfo &BFI)
Returns true if F contains hot code.
ProfileCount getEntryCount() const
Get the entry count for this function.
An analysis pass based on legacy pass manager to deliver ProfileSummaryInfo.
InstrTy * getInstruction() const
Metadata * getProfileSummary()
Returns profile summary metadata.
bool isColdBlock(const BasicBlock *BB, BlockFrequencyInfo *BFI)
Returns true if BasicBlock BB is considered cold.
ProfileSummaryInfo(Module &M)
const T & getValue() const LLVM_LVALUE_FUNCTION
auto lower_bound(R &&Range, ForwardIt I) -> decltype(adl_begin(Range))
Provide wrappers to std::lower_bound which take ranges instead of having to pass begin/end explicitly...
bool extractProfTotalWeight(uint64_t &TotalVal) const
Retrieve total raw weight values of a branch.
bool doInitialization(Module &M) override
doInitialization - Virtual method overridden by subclasses to do any necessary initialization before ...
BlockFrequencyInfo pass uses BlockFrequencyInfoImpl implementation to estimate IR basic block frequen...
initializer< Ty > init(const Ty &Val)
A set of analyses that are preserved following a run of a transformation pass.
LLVM Basic Block Representation.
bool hasSampleProfile()
Returns true if module M has sample profile.
An analysis pass based on the new PM to deliver ProfileSummaryInfo.
INITIALIZE_PASS(ProfileSummaryInfoWrapperPass, "profile-summary-info", "Profile summary info", false, true) ProfileSummaryInfoWrapperPass
bool doFinalization(Module &M) override
doFinalization - Virtual method overriden by subclasses to do any necessary clean up after all passes...
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM)
ImmutablePass class - This class is used to provide information that does not need to be run...
Module.h This file contains the declarations for the Module class.
void initializeProfileSummaryInfoWrapperPassPass(PassRegistry &)
bool isFunctionColdInCallGraph(const Function *F, BlockFrequencyInfo &BFI)
Returns true if F contains only cold code.
static ProfileSummary * getFromMD(Metadata *MD)
Construct profile summary from metdata.
static cl::opt< int > ProfileSummaryCutoffHot("profile-summary-cutoff-hot", cl::Hidden, cl::init(990000), cl::ZeroOrMore, cl::desc("A count is hot if it exceeds the minimum count to" " reach this percentile of total counts."))
FunTy * getCaller() const
Return the caller function for this call site.
bool isFunctionEntryHot(const Function *F)
Returns true if F has hot function entry.
bool isHotBlock(const BasicBlock *BB, BlockFrequencyInfo *BFI)
Returns true if BasicBlock BB is considered hot.
bool isColdCallSite(const CallSite &CS, BlockFrequencyInfo *BFI)
Returns true if Callsite CS is considered cold.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
bool hasHugeWorkingSetSize()
Returns true if the working set size of the code is considered huge.
static cl::opt< int > ProfileSummaryCutoffCold("profile-summary-cutoff-cold", cl::Hidden, cl::init(999999), cl::ZeroOrMore, cl::desc("A count is cold if it is below the minimum count" " to reach this percentile of total counts."))
A container for analyses that lazily runs them and caches their results.
std::vector< ProfileSummaryEntry > SummaryEntryVector
static cl::opt< int > ProfileSummaryColdCount("profile-summary-cold-count", cl::ReallyHidden, cl::ZeroOrMore, cl::desc("A fixed cold count that overrides the count derived from" " profile-summary-cutoff-cold"))
bool hasProfileData() const
Return true if the function is annotated with profile data.
A special type used by analysis passes to provide an address that identifies that particular analysis...
Optional< uint64_t > getBlockProfileCount(const BasicBlock *BB) const
Returns the estimated profile count of BB.
static const ProfileSummaryEntry & getEntryForPercentile(SummaryEntryVector &DS, uint64_t Percentile)
const BasicBlock * getParent() const