9#ifndef LLVM_TRANSFORMS_IPO_PROFILEDCALLGRAPH_H
10#define LLVM_TRANSFORMS_IPO_PROFILEDCALLGRAPH_H
22struct ProfiledCallGraphNode;
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 if (!ProfiledFunctions.count(
Name)) {
145 Root.
Edges.emplace(&Root, ProfiledFunctions[
Name], 0);
152 assert(ProfiledFunctions.count(CallerName));
153 auto CalleeIt = ProfiledFunctions.find(CalleeName);
154 if (CalleeIt == ProfiledFunctions.end())
157 CalleeIt->second, Weight);
158 auto &Edges = ProfiledFunctions[CallerName]->Edges;
159 auto EdgeIt = Edges.find(Edge);
160 if (EdgeIt == Edges.end()) {
164 Edge.Weight += EdgeIt->Weight;
170 void addProfiledCalls(
const FunctionSamples &Samples) {
173 for (
const auto &Sample : Samples.getBodySamples()) {
174 for (
const auto &[Target, Frequency] : Sample.second.getCallTargets()) {
176 addProfiledCall(Samples.getFunction(), Target, Frequency);
180 for (
const auto &CallsiteSamples : Samples.getCallsiteSamples()) {
181 for (
const auto &InlinedSamples : CallsiteSamples.second) {
183 addProfiledCall(Samples.getFunction(), InlinedSamples.first,
184 InlinedSamples.second.getHeadSamplesEstimate());
185 addProfiledCalls(InlinedSamples.second);
192 void trimColdEges(
uint64_t Threshold = 0) {
196 for (
auto &
Node : ProfiledFunctions) {
197 auto &Edges =
Node.second->Edges;
198 auto I = Edges.begin();
199 while (
I != Edges.end()) {
200 if (
I->Weight <= Threshold)
208 ProfiledCallGraphNode Root;
210 std::list<ProfiledCallGraphNode> ProfiledCallGraphNodeList;
211 HashKeyMap<llvm::DenseMap, FunctionId, ProfiledCallGraphNode*>
This file defines the little GraphTraits<X> template class that should be specialized by classes that...
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
This file provides the interface for context-sensitive profile tracker used by CSSPGO.
std::map< uint64_t, ContextTrieNode > & getAllChildContext()
ContextTrieNode & getRootContext()
Target - Wrapper for Target specific information.
This class represents a function that is read from a sample profile.
Representation of the samples collected for a function.
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,...
This is an optimization pass for GlobalISel generic memory operations.
static ChildIteratorType child_end(NodeRef N)
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)
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
edges::const_iterator const_iterator
ProfiledCallGraphNode(FunctionId FName=FunctionId())
std::set< edge, ProfiledCallGraphEdgeComparer > edges