38 cl::desc(
"Specify the current profile is used as a partial profile."));
45 "scale-partial-sample-profile-working-set-size",
cl::Hidden,
48 "If true, scale the working set size of the partial sample profile "
49 "by the partial profile ratio to reflect the size of the program "
53 "partial-sample-profile-working-set-size-scale-factor",
cl::Hidden,
55 cl::desc(
"The scale factor used to scale the working set size of the "
56 "partial sample profile along with the partial profile ratio. "
57 "This includes the factor of the profile counter per block "
58 "and the factor to scale the working set size to use the same "
59 "shared thresholds as PGO."));
86 assert((isa<CallInst>(Call) || isa<InvokeInst>(Call)) &&
87 "We can only get profile count for call/invoke instruction.");
94 if (Call.extractProfTotalWeight(TotalCount))
99 return BFI->getBlockProfileCount(Call.getParent(), AllowSynthetic);
109 auto FunctionCount =
F->getEntryCount();
113 return FunctionCount &&
isHotCount(FunctionCount->getCount());
125 if (
auto FunctionCount =
F->getEntryCount())
131 for (
const auto &BB : *
F)
132 for (
const auto &
I : BB)
133 if (isa<CallInst>(
I) || isa<InvokeInst>(
I))
135 TotalCallCount += *CallCount;
139 for (
const auto &BB : *
F)
154 if (
auto FunctionCount =
F->getEntryCount())
160 for (
const auto &BB : *
F)
161 for (
const auto &
I : BB)
162 if (isa<CallInst>(
I) || isa<InvokeInst>(
I))
164 TotalCallCount += *CallCount;
168 for (
const auto &BB : *
F)
176 return !
F.getEntryCount();
180bool ProfileSummaryInfo::isFunctionHotOrColdInCallGraphNthPercentile(
184 if (
auto FunctionCount =
F->getEntryCount()) {
194 for (
const auto &BB : *
F)
195 for (
const auto &
I : BB)
196 if (isa<CallInst>(
I) || isa<InvokeInst>(
I))
198 TotalCallCount += *CallCount;
204 for (
const auto &BB : *
F) {
216 return isFunctionHotOrColdInCallGraphNthPercentile<true>(
222 return isFunctionHotOrColdInCallGraphNthPercentile<false>(
232 if (
F->hasFnAttribute(Attribute::Cold))
236 auto FunctionCount =
F->getEntryCount();
240 return FunctionCount &&
isColdCount(FunctionCount->getCount());
244void ProfileSummaryInfo::computeThresholds() {
245 auto &DetailedSummary = Summary->getDetailedSummary();
252 assert(ColdCountThreshold <= HotCountThreshold &&
253 "Cold count threshold cannot exceed hot count threshold!");
255 HasHugeWorkingSetSize =
257 HasLargeWorkingSetSize =
262 double PartialProfileRatio = Summary->getPartialProfileRatio();
264 static_cast<uint64_t>(HotEntry.NumCounts * PartialProfileRatio *
266 HasHugeWorkingSetSize =
268 HasLargeWorkingSetSize =
273std::optional<uint64_t>
278 if (iter != ThresholdCache.
end()) {
281 auto &DetailedSummary = Summary->getDetailedSummary();
290 return HasHugeWorkingSetSize && *HasHugeWorkingSetSize;
294 return HasLargeWorkingSetSize && *HasLargeWorkingSetSize;
298 return HotCountThreshold &&
C >= *HotCountThreshold;
302 return ColdCountThreshold &&
C <= *ColdCountThreshold;
326 return HotCountThreshold.value_or(
UINT64_MAX);
330 return ColdCountThreshold.value_or(0);
335 auto Count = BFI->getBlockProfileCount(BB);
341 auto Count = BFI->getBlockProfileCount(BB);
346bool ProfileSummaryInfo::isHotOrColdBlockNthPercentile(
348 auto Count = BFI->getBlockProfileCount(BB);
389 "Profile summary info",
false,
true)
416 OS <<
"Functions in " << M.getName() <<
" with hot/cold annotations: \n";
420 OS <<
" :hot entry ";
422 OS <<
" :cold entry ";
static cl::opt< unsigned > CountThreshold("hexagon-cext-threshold", cl::init(3), cl::Hidden, cl::desc("Minimum number of extenders to trigger replacement"))
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)
cl::opt< bool > ScalePartialSampleProfileWorkingSetSize
Module.h This file contains the declarations for the Module class.
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
cl::opt< bool > ScalePartialSampleProfileWorkingSetSize("scale-partial-sample-profile-working-set-size", cl::Hidden, cl::init(false), cl::desc("If true, scale the working set size of the partial sample profile " "by the partial profile ratio to reflect the size of the program " "being compiled."))
static cl::opt< bool > PartialProfile("partial-profile", cl::Hidden, cl::init(false), cl::desc("Specify the current profile is used as a partial profile."))
static cl::opt< double > PartialSampleProfileWorkingSetSizeScaleFactor("partial-sample-profile-working-set-size-scale-factor", cl::Hidden, cl::init(0.008), cl::desc("The scale factor used to scale the working set size of the " "partial sample profile along with the partial profile ratio. " "This includes the factor of the profile counter per block " "and the factor to scale the working set size to use the same " "shared thresholds as PGO."))
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
A container for analyses that lazily runs them and caches their results.
PassT::Result & getResult(IRUnitT &IR, ExtraArgTs... ExtraArgs)
Get the result of an analysis pass for a given IR unit.
LLVM Basic Block Representation.
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...
Function * getCaller()
Helper to get the caller (the parent function).
iterator find(const_arg_type_t< KeyT > Val)
bool hasProfileData(bool IncludeSynthetic=false) const
Return true if the function is annotated with profile data.
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.
Metadata * getProfileSummary(bool IsCS) const
Returns profile summary metadata.
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
A set of analyses that are preserved following a run of a transformation pass.
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
An analysis pass based on the new PM to deliver ProfileSummaryInfo.
Result run(Module &M, ModuleAnalysisManager &)
static const ProfileSummaryEntry & getEntryForPercentile(const SummaryEntryVector &DS, uint64_t Percentile)
Find the summary entry for a desired percentile of counts.
static uint64_t getHotCountThreshold(const SummaryEntryVector &DS)
static uint64_t getColdCountThreshold(const SummaryEntryVector &DS)
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...
bool doInitialization(Module &M) override
doInitialization - Virtual method overridden by subclasses to do any necessary initialization before ...
Analysis providing profile information.
bool isFunctionEntryHot(const Function *F) const
Returns true if F has hot function entry.
bool isHotBlockNthPercentile(int PercentileCutoff, const BasicBlock *BB, BlockFrequencyInfo *BFI) const
Returns true if BasicBlock BB is considered hot with regard to a given hot percentile cutoff value.
uint64_t getOrCompColdCountThreshold() const
Returns ColdCountThreshold if set.
bool hasProfileSummary() const
Returns true if profile summary is available.
bool isHotBlock(const BasicBlock *BB, BlockFrequencyInfo *BFI) const
Returns true if BasicBlock BB is considered hot.
bool isFunctionHotnessUnknown(const Function &F) const
Returns true if the hotness of F is unknown.
void refresh()
If no summary is present, attempt to refresh.
bool isColdBlockNthPercentile(int PercentileCutoff, const BasicBlock *BB, BlockFrequencyInfo *BFI) const
Returns true if BasicBlock BB is considered cold with regard to a given cold percentile cutoff value.
std::optional< uint64_t > getProfileCount(const CallBase &CallInst, BlockFrequencyInfo *BFI, bool AllowSynthetic=false) const
Returns the profile count for CallInst.
bool hasSampleProfile() const
Returns true if module M has sample profile.
bool isColdCount(uint64_t C) const
Returns true if count C is considered cold.
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.
bool isFunctionColdInCallGraphNthPercentile(int PercentileCutoff, const Function *F, BlockFrequencyInfo &BFI) const
Returns true if F contains cold code with regard to a given cold percentile cutoff value.
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.
bool isFunctionHotInCallGraphNthPercentile(int PercentileCutoff, const Function *F, BlockFrequencyInfo &BFI) const
Returns true if F contains hot code with regard to a given hot percentile cutoff value.
bool isFunctionHotInCallGraph(const Function *F, BlockFrequencyInfo &BFI) const
Returns true if F contains hot code.
bool isHotCallSite(const CallBase &CB, BlockFrequencyInfo *BFI) const
Returns true if the call site CB is considered hot.
bool isColdBlock(const BasicBlock *BB, BlockFrequencyInfo *BFI) const
Returns true if BasicBlock BB is considered cold.
bool isFunctionColdInCallGraph(const Function *F, BlockFrequencyInfo &BFI) const
Returns true if F contains only cold code.
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.
uint64_t getOrCompHotCountThreshold() const
Returns HotCountThreshold if set.
bool isFunctionEntryCold(const Function *F) const
Returns true if F has cold function entry.
PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM)
static ProfileSummary * getFromMD(Metadata *MD)
Construct profile summary from metdata.
@ C
The default llvm calling convention, compatible with C.
initializer< Ty > init(const Ty &Val)
This is an optimization pass for GlobalISel generic memory operations.
cl::opt< int > ProfileSummaryHotCount
cl::opt< int > ProfileSummaryColdCount
cl::opt< int > ProfileSummaryCutoffCold
cl::opt< unsigned > ProfileSummaryLargeWorkingSetSizeThreshold
void initializeProfileSummaryInfoWrapperPassPass(PassRegistry &)
cl::opt< int > ProfileSummaryCutoffHot
cl::opt< unsigned > ProfileSummaryHugeWorkingSetSizeThreshold
A special type used by analysis passes to provide an address that identifies that particular analysis...