9 #ifndef LLVM_TRANSFORMS_IPO_PROFILEDCALLGRAPH_H
10 #define LLVM_TRANSFORMS_IPO_PROFILEDCALLGRAPH_H
22 namespace sampleprof {
24 struct ProfiledCallGraphNode;
52 using edges = std::set<edge, ProfiledCallGraphEdgeComparer>;
69 "CS flat profile is not handled here");
70 for (
const auto &Samples : ProfileMap) {
71 addProfiledCalls(Samples.second);
79 std::queue<ContextTrieNode *> Queue;
86 while (!Queue.empty()) {
97 for (
auto &Child : Caller->getAllChildContext()) {
105 if (!CalleeSamples || !CallerSamples) {
113 auto It = TargetCounts.
find(CalleeSamples->
getName());
114 if (It != TargetCounts.
end())
115 CallsiteCount = It->second;
117 Weight =
std::max(CallsiteCount, CalleeEntryCount);
130 if (!ProfiledFunctions.count(
Name)) {
134 Root.
Edges.emplace(&Root, &ProfiledFunctions[
Name], 0);
141 assert(ProfiledFunctions.count(CallerName));
142 auto CalleeIt = ProfiledFunctions.find(CalleeName);
143 if (CalleeIt == ProfiledFunctions.end())
146 &CalleeIt->second, Weight);
147 auto &Edges = ProfiledFunctions[CallerName].Edges;
148 auto EdgeIt = Edges.find(Edge);
149 if (EdgeIt == Edges.end()) {
151 }
else if (EdgeIt->Weight < Edge.Weight) {
158 void addProfiledCalls(
const FunctionSamples &Samples) {
161 for (
const auto &Sample : Samples.getBodySamples()) {
162 for (
const auto &Target : Sample.second.getCallTargets()) {
164 addProfiledCall(Samples.getFuncName(),
Target.first(),
Target.second);
168 for (
const auto &CallsiteSamples : Samples.getCallsiteSamples()) {
169 for (
const auto &InlinedSamples : CallsiteSamples.second) {
171 addProfiledCall(Samples.getFuncName(), InlinedSamples.first,
172 InlinedSamples.second.getHeadSamplesEstimate());
173 addProfiledCalls(InlinedSamples.second);
178 ProfiledCallGraphNode Root;
179 StringMap<ProfiledCallGraphNode> ProfiledFunctions;