40#define DEBUG_TYPE "synthetic-counts-propagation"
45 cl::desc(
"Initial value of synthetic entry count"));
51 cl::desc(
"Initial synthetic entry count for inline functions."));
56 cl::desc(
"Initial synthetic entry count for cold functions."));
61 auto MayHaveIndirectCalls = [](
Function &
F) {
62 for (
auto *U :
F.users()) {
63 if (!isa<CallInst>(U) && !isa<InvokeInst>(U))
71 if (
F.isDeclaration())
73 if (
F.hasFnAttribute(Attribute::AlwaysInline) ||
74 F.hasFnAttribute(Attribute::InlineHint)) {
78 }
else if (
F.hasLocalLinkage() && !MayHaveIndirectCalls(
F)) {
82 }
else if (
F.hasFnAttribute(Attribute::Cold) ||
83 F.hasFnAttribute(Attribute::NoInline)) {
87 SetCount(&
F, InitialCount);
104 std::optional<Scaled64> Res;
107 CallBase &CB = *cast<CallBase>(*Edge.first);
114 Scaled64 EntryFreq(BFI.getEntryFreq().getFrequency(), 0);
115 Scaled64 BBCount(BFI.getBlockFreq(CSBB).getFrequency(), 0);
116 BBCount /= EntryFreq;
117 BBCount *= Counts[Caller];
118 return std::optional<Scaled64>(BBCount);
125 auto F =
N->getFunction();
126 if (!
F ||
F->isDeclaration())
133 for (
auto Entry : Counts) {
This file provides interfaces used to build and manipulate a call graph, which is a very useful tool ...
Module.h This file contains the declarations for the Module class.
FunctionAnalysisManager FAM
ModuleAnalysisManager MAM
static void initializeCounts(ModuleSummaryIndex &Index)
ScaledNumber< uint64_t > Scaled64
static void initializeCounts(Module &M, function_ref< void(Function *, uint64_t)> SetCount)
static cl::opt< int > ColdSyntheticCount("cold-synthetic-count", cl::Hidden, cl::init(5), cl::desc("Initial synthetic entry count for cold functions."))
Initial synthetic count assigned to cold functions.
static cl::opt< int > InlineSyntheticCount("inline-synthetic-count", cl::Hidden, cl::init(15), cl::desc("Initial synthetic entry count for inline functions."))
Initial synthetic count assigned to inline functions.
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.
Analysis pass which computes BlockFrequencyInfo.
Base class for all callable instructions (InvokeInst and CallInst) Holds everything related to callin...
Function * getCaller()
Helper to get the caller (the parent function).
A node in the call graph for a module.
std::pair< std::optional< WeakTrackingVH >, CallGraphNode * > CallRecord
A pair of the calling instruction (a call or invoke) and the call graph node being called.
The basic data container for the call graph of a Module of IR.
Class to represent profile counts.
An analysis over an "outer" IR unit that provides access to an analysis manager over an "inner" IR un...
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.
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
PreservedAnalyses run(Module &M, ModuleAnalysisManager &MAM)
static void propagate(const CallGraphType &CG, GetProfCountTy GetProfCount, AddCountTy AddCount)
Propgate synthetic entry counts on a callgraph CG.
An efficient, type-erasing, non-owning reference to a callable.
const ParentTy * getParent() const
initializer< Ty > init(const Ty &Val)
This is an optimization pass for GlobalISel generic memory operations.
Function::ProfileCount ProfileCount
cl::opt< int > InitialSyntheticCount