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, Inserted] = Edges.insert(Edge);
162 Edge.Weight += EdgeIt->Weight;
168 void addProfiledCalls(
const FunctionSamples &Samples) {
171 for (
const auto &Sample : Samples.getBodySamples()) {
172 for (
const auto &[Target, Frequency] : Sample.second.getCallTargets()) {
174 addProfiledCall(Samples.getFunction(), Target, Frequency);
178 for (
const auto &CallsiteSamples : Samples.getCallsiteSamples()) {
179 for (
const auto &InlinedSamples : CallsiteSamples.second) {
181 addProfiledCall(Samples.getFunction(), InlinedSamples.first,
182 InlinedSamples.second.getHeadSamplesEstimate());
183 addProfiledCalls(InlinedSamples.second);
190 void trimColdEges(
uint64_t Threshold = 0) {
194 for (
auto &
Node : ProfiledFunctions) {
195 auto &Edges =
Node.second->Edges;
196 auto I = Edges.begin();
197 while (
I != Edges.end()) {
198 if (
I->Weight <= Threshold)
206 ProfiledCallGraphNode Root;
208 std::list<ProfiledCallGraphNode> ProfiledCallGraphNodeList;
209 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