9#ifndef LLVM_TRANSFORMS_IPO_PROFILEDCALLGRAPH_H
10#define LLVM_TRANSFORMS_IPO_PROFILEDCALLGRAPH_H
45 return L.Target->Name < R.Target->Name;
50 using edges = std::set<edge, ProfiledCallGraphEdgeComparer>;
67 uint64_t IgnoreColdCallThreshold = 0) {
69 "CS flat profile is not handled here");
70 for (
const auto &Samples : ProfileMap) {
71 addProfiledCalls(Samples.second);
76 trimColdEges(IgnoreColdCallThreshold);
81 uint64_t IgnoreColdCallThreshold = 0) {
84 std::queue<ContextTrieNode *> Queue;
91 while (!Queue.empty()) {
102 for (
auto &Child : Caller->getAllChildContext()) {
110 if (!CalleeSamples || !CallerSamples) {
117 auto It = CallTargets->find(CalleeSamples->
getFunction());
118 if (It != CallTargets->end())
119 CallsiteCount = It->second;
121 Weight = std::max(CallsiteCount, CalleeEntryCount);
124 addProfiledCall(Caller->getFuncName(), Callee->getFuncName(), Weight);
130 trimColdEges(IgnoreColdCallThreshold);
138 auto [It, Inserted] = ProfiledFunctions.try_emplace(Name);
146 Root.Edges.emplace(&Root, It->second, 0);
153 auto CalleeIt = ProfiledFunctions.find(CalleeName);
154 if (CalleeIt == ProfiledFunctions.end())
156 auto CallerIt = ProfiledFunctions.find(CallerName);
157 assert(CallerIt != ProfiledFunctions.end());
159 auto &Edges = CallerIt->second->Edges;
160 auto [EdgeIt, Inserted] = Edges.insert(Edge);
163 Edge.Weight += EdgeIt->Weight;
169 void addProfiledCalls(
const FunctionSamples &Samples) {
172 for (
const auto &Sample : Samples.getBodySamples()) {
173 for (
const auto &[Target, Frequency] : Sample.second.getCallTargets()) {
175 addProfiledCall(Samples.getFunction(), Target, Frequency);
179 for (
const auto &CallsiteSamples : Samples.getCallsiteSamples()) {
180 for (
const auto &InlinedSamples : CallsiteSamples.second) {
182 addProfiledCall(Samples.getFunction(), InlinedSamples.first,
183 InlinedSamples.second.getHeadSamplesEstimate());
184 addProfiledCalls(InlinedSamples.second);
191 void trimColdEges(uint64_t Threshold = 0) {
195 for (
auto &Node : ProfiledFunctions) {
196 auto &Edges =
Node.second->Edges;
197 auto I = Edges.begin();
198 while (
I != Edges.end()) {
199 if (
I->Weight <= Threshold)
207 ProfiledCallGraphNode Root;
209 std::list<ProfiledCallGraphNode> ProfiledCallGraphNodeList;
210 HashKeyMap<llvm::DenseMap, FunctionId, ProfiledCallGraphNode*>
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
This file defines the little GraphTraits<X> template class that should be specialized by classes that...
std::pair< BasicBlock *, BasicBlock * > Edge
This file provides the interface for context-sensitive profile tracker used by CSSPGO.
LLVM_ABI std::map< uint64_t, ContextTrieNode > & getAllChildContext()
LLVM_ABI ContextTrieNode & getRootContext()
This class represents a function that is read from a sample profile.
Representation of the samples collected for a function.
static LLVM_ABI bool ProfileIsCS
FunctionId getFunction() const
Return the function name.
ErrorOr< const SampleRecord::CallTargetMap & > findCallTargetMapAt(uint32_t LineOffset, uint32_t Discriminator) const
Returns the call target map collected at a given location.
uint64_t getHeadSamplesEstimate() const
Return an estimate of the sample count of the function entry basic block.
ProfiledCallGraphNode * getEntryNode()
ProfiledCallGraphNode::iterator iterator
void addProfiledFunction(FunctionId Name)
ProfiledCallGraph(SampleContextTracker &ContextTracker, uint64_t IgnoreColdCallThreshold=0)
ProfiledCallGraph(SampleProfileMap &ProfileMap, uint64_t IgnoreColdCallThreshold=0)
This class provides operator overloads to the map container using MD5 as the key type,...
NodeAddr< NodeBase * > Node
This is an optimization pass for GlobalISel generic memory operations.
ProfiledCallGraphNode NodeType
static ChildIteratorType child_end(NodeRef N)
ProfiledCallGraphNode * NodeRef
static NodeRef getEntryNode(NodeRef PCGN)
NodeType::const_iterator ChildIteratorType
static ChildIteratorType child_begin(NodeRef N)
static NodeRef getEntryNode(ProfiledCallGraph *PCG)
static ChildIteratorType nodes_end(ProfiledCallGraph *PCG)
static ChildIteratorType nodes_begin(ProfiledCallGraph *PCG)
typename ProfiledCallGraph *::UnknownGraphTypeError NodeRef
Represents the relative location of an instruction.
ProfiledCallGraphNode * Target
ProfiledCallGraphEdge(ProfiledCallGraphNode *Source, ProfiledCallGraphNode *Target, uint64_t Weight)
ProfiledCallGraphNode * Source
bool operator()(const ProfiledCallGraphEdge &L, const ProfiledCallGraphEdge &R) const
ProfiledCallGraphEdge edge
edges::const_iterator const_iterator
ProfiledCallGraphNode(FunctionId FName=FunctionId())
std::set< edge, ProfiledCallGraphEdgeComparer > edges