9#ifndef LLVM_TRANSFORMS_IPO_PROFILEDCALLGRAPH_H
10#define LLVM_TRANSFORMS_IPO_PROFILEDCALLGRAPH_H
24struct ProfiledCallGraphNode;
47 return L.Target->Name < R.Target->Name;
52 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->
getName());
120 if (It != TargetCounts.
end())
121 CallsiteCount = It->second;
123 Weight = std::max(CallsiteCount, CalleeEntryCount);
133 trimColdEges(IgnoreColdCallThreshold);
141 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.getFuncName(), Target, Frequency);
180 for (
const auto &CallsiteSamples : Samples.getCallsiteSamples()) {
181 for (
const auto &InlinedSamples : CallsiteSamples.second) {
183 addProfiledCall(Samples.getFuncName(), 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;
209 StringMap<ProfiledCallGraphNode> ProfiledFunctions;
This file defines the StringMap class.
amdgpu Simplify well known AMD library false FunctionCallee Callee
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()
StringRef getFuncNameFor(ContextTrieNode *Node) const
ContextTrieNode & getRootContext()
iterator find(StringRef Key)
StringRef - Represent a constant reference to a string, i.e.
Target - Wrapper for Target specific information.
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.
uint64_t getHeadSamplesEstimate() const
Return an estimate of the sample count of the function entry basic block.
StringRef getName() const
Return the function name.
ProfiledCallGraphNode * getEntryNode()
ProfiledCallGraphNode::iterator iterator
ProfiledCallGraph(SampleContextTracker &ContextTracker, uint64_t IgnoreColdCallThreshold=0)
void addProfiledFunction(StringRef Name)
ProfiledCallGraph(SampleProfileMap &ProfileMap, uint64_t IgnoreColdCallThreshold=0)
std::unordered_map< SampleContext, FunctionSamples, SampleContext::Hash > SampleProfileMap
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
ProfiledCallGraphNode(StringRef FName=StringRef())
edges::const_iterator const_iterator
std::set< edge, ProfiledCallGraphEdgeComparer > edges