9#ifndef LLVM_TRANSFORMS_IPO_PROFILEDCALLGRAPH_H
10#define LLVM_TRANSFORMS_IPO_PROFILEDCALLGRAPH_H
23struct ProfiledCallGraphNode;
46 return L.Target->Name < R.Target->Name;
51 using edges = std::set<edge, ProfiledCallGraphEdgeComparer>;
68 uint64_t IgnoreColdCallThreshold = 0) {
70 "CS flat profile is not handled here");
71 for (
const auto &Samples : ProfileMap) {
72 addProfiledCalls(Samples.second);
77 trimColdEges(IgnoreColdCallThreshold);
82 uint64_t IgnoreColdCallThreshold = 0) {
85 std::queue<ContextTrieNode *> Queue;
92 while (!Queue.empty()) {
103 for (
auto &Child : Caller->getAllChildContext()) {
111 if (!CalleeSamples || !CallerSamples) {
119 auto It = TargetCounts.find(CalleeSamples->
getFunction());
120 if (It != TargetCounts.end())
121 CallsiteCount = It->second;
123 Weight = std::max(CallsiteCount, CalleeEntryCount);
126 addProfiledCall(Caller->getFuncName(), Callee->getFuncName(), Weight);
132 trimColdEges(IgnoreColdCallThreshold);
140 if (!ProfiledFunctions.count(
Name)) {
144 Root.
Edges.emplace(&Root, &ProfiledFunctions[
Name], 0);
151 assert(ProfiledFunctions.count(CallerName));
152 auto CalleeIt = ProfiledFunctions.find(CalleeName);
153 if (CalleeIt == ProfiledFunctions.end())
156 &CalleeIt->second, Weight);
157 auto &Edges = ProfiledFunctions[CallerName].Edges;
158 auto EdgeIt = Edges.find(Edge);
159 if (EdgeIt == Edges.end()) {
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;
208 HashKeyMap<std::unordered_map, 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.
ErrorOr< SampleRecord::CallTargetMap > findCallTargetMapAt(uint32_t LineOffset, uint32_t Discriminator) const
Returns the call target map collected at a given location.
FunctionId getFunction() const
Return the function name.
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,...
std::unordered_map< FunctionId, uint64_t > CallTargetMap
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