xref: /freebsd/contrib/llvm-project/llvm/lib/Analysis/ProfileSummaryInfo.cpp (revision 0b57cec536236d46e3dba9bd041533462f33dbb7)
1*0b57cec5SDimitry Andric //===- ProfileSummaryInfo.cpp - Global profile summary information --------===//
2*0b57cec5SDimitry Andric //
3*0b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4*0b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
5*0b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6*0b57cec5SDimitry Andric //
7*0b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
8*0b57cec5SDimitry Andric //
9*0b57cec5SDimitry Andric // This file contains a pass that provides access to the global profile summary
10*0b57cec5SDimitry Andric // information.
11*0b57cec5SDimitry Andric //
12*0b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
13*0b57cec5SDimitry Andric 
14*0b57cec5SDimitry Andric #include "llvm/Analysis/ProfileSummaryInfo.h"
15*0b57cec5SDimitry Andric #include "llvm/Analysis/BlockFrequencyInfo.h"
16*0b57cec5SDimitry Andric #include "llvm/IR/BasicBlock.h"
17*0b57cec5SDimitry Andric #include "llvm/IR/CallSite.h"
18*0b57cec5SDimitry Andric #include "llvm/IR/Metadata.h"
19*0b57cec5SDimitry Andric #include "llvm/IR/Module.h"
20*0b57cec5SDimitry Andric #include "llvm/IR/ProfileSummary.h"
21*0b57cec5SDimitry Andric using namespace llvm;
22*0b57cec5SDimitry Andric 
23*0b57cec5SDimitry Andric // The following two parameters determine the threshold for a count to be
24*0b57cec5SDimitry Andric // considered hot/cold. These two parameters are percentile values (multiplied
25*0b57cec5SDimitry Andric // by 10000). If the counts are sorted in descending order, the minimum count to
26*0b57cec5SDimitry Andric // reach ProfileSummaryCutoffHot gives the threshold to determine a hot count.
27*0b57cec5SDimitry Andric // Similarly, the minimum count to reach ProfileSummaryCutoffCold gives the
28*0b57cec5SDimitry Andric // threshold for determining cold count (everything <= this threshold is
29*0b57cec5SDimitry Andric // considered cold).
30*0b57cec5SDimitry Andric 
31*0b57cec5SDimitry Andric static cl::opt<int> ProfileSummaryCutoffHot(
32*0b57cec5SDimitry Andric     "profile-summary-cutoff-hot", cl::Hidden, cl::init(990000), cl::ZeroOrMore,
33*0b57cec5SDimitry Andric     cl::desc("A count is hot if it exceeds the minimum count to"
34*0b57cec5SDimitry Andric              " reach this percentile of total counts."));
35*0b57cec5SDimitry Andric 
36*0b57cec5SDimitry Andric static cl::opt<int> ProfileSummaryCutoffCold(
37*0b57cec5SDimitry Andric     "profile-summary-cutoff-cold", cl::Hidden, cl::init(999999), cl::ZeroOrMore,
38*0b57cec5SDimitry Andric     cl::desc("A count is cold if it is below the minimum count"
39*0b57cec5SDimitry Andric              " to reach this percentile of total counts."));
40*0b57cec5SDimitry Andric 
41*0b57cec5SDimitry Andric static cl::opt<unsigned> ProfileSummaryHugeWorkingSetSizeThreshold(
42*0b57cec5SDimitry Andric     "profile-summary-huge-working-set-size-threshold", cl::Hidden,
43*0b57cec5SDimitry Andric     cl::init(15000), cl::ZeroOrMore,
44*0b57cec5SDimitry Andric     cl::desc("The code working set size is considered huge if the number of"
45*0b57cec5SDimitry Andric              " blocks required to reach the -profile-summary-cutoff-hot"
46*0b57cec5SDimitry Andric              " percentile exceeds this count."));
47*0b57cec5SDimitry Andric 
48*0b57cec5SDimitry Andric // The next two options override the counts derived from summary computation and
49*0b57cec5SDimitry Andric // are useful for debugging purposes.
50*0b57cec5SDimitry Andric static cl::opt<int> ProfileSummaryHotCount(
51*0b57cec5SDimitry Andric     "profile-summary-hot-count", cl::ReallyHidden, cl::ZeroOrMore,
52*0b57cec5SDimitry Andric     cl::desc("A fixed hot count that overrides the count derived from"
53*0b57cec5SDimitry Andric              " profile-summary-cutoff-hot"));
54*0b57cec5SDimitry Andric 
55*0b57cec5SDimitry Andric static cl::opt<int> ProfileSummaryColdCount(
56*0b57cec5SDimitry Andric     "profile-summary-cold-count", cl::ReallyHidden, cl::ZeroOrMore,
57*0b57cec5SDimitry Andric     cl::desc("A fixed cold count that overrides the count derived from"
58*0b57cec5SDimitry Andric              " profile-summary-cutoff-cold"));
59*0b57cec5SDimitry Andric 
60*0b57cec5SDimitry Andric // Find the summary entry for a desired percentile of counts.
61*0b57cec5SDimitry Andric static const ProfileSummaryEntry &getEntryForPercentile(SummaryEntryVector &DS,
62*0b57cec5SDimitry Andric                                                         uint64_t Percentile) {
63*0b57cec5SDimitry Andric   auto It = partition_point(DS, [=](const ProfileSummaryEntry &Entry) {
64*0b57cec5SDimitry Andric     return Entry.Cutoff < Percentile;
65*0b57cec5SDimitry Andric   });
66*0b57cec5SDimitry Andric   // The required percentile has to be <= one of the percentiles in the
67*0b57cec5SDimitry Andric   // detailed summary.
68*0b57cec5SDimitry Andric   if (It == DS.end())
69*0b57cec5SDimitry Andric     report_fatal_error("Desired percentile exceeds the maximum cutoff");
70*0b57cec5SDimitry Andric   return *It;
71*0b57cec5SDimitry Andric }
72*0b57cec5SDimitry Andric 
73*0b57cec5SDimitry Andric // The profile summary metadata may be attached either by the frontend or by
74*0b57cec5SDimitry Andric // any backend passes (IR level instrumentation, for example). This method
75*0b57cec5SDimitry Andric // checks if the Summary is null and if so checks if the summary metadata is now
76*0b57cec5SDimitry Andric // available in the module and parses it to get the Summary object. Returns true
77*0b57cec5SDimitry Andric // if a valid Summary is available.
78*0b57cec5SDimitry Andric bool ProfileSummaryInfo::computeSummary() {
79*0b57cec5SDimitry Andric   if (Summary)
80*0b57cec5SDimitry Andric     return true;
81*0b57cec5SDimitry Andric   // First try to get context sensitive ProfileSummary.
82*0b57cec5SDimitry Andric   auto *SummaryMD = M.getProfileSummary(/* IsCS */ true);
83*0b57cec5SDimitry Andric   if (SummaryMD) {
84*0b57cec5SDimitry Andric     Summary.reset(ProfileSummary::getFromMD(SummaryMD));
85*0b57cec5SDimitry Andric     return true;
86*0b57cec5SDimitry Andric   }
87*0b57cec5SDimitry Andric   // This will actually return PSK_Instr or PSK_Sample summary.
88*0b57cec5SDimitry Andric   SummaryMD = M.getProfileSummary(/* IsCS */ false);
89*0b57cec5SDimitry Andric   if (!SummaryMD)
90*0b57cec5SDimitry Andric     return false;
91*0b57cec5SDimitry Andric   Summary.reset(ProfileSummary::getFromMD(SummaryMD));
92*0b57cec5SDimitry Andric   return true;
93*0b57cec5SDimitry Andric }
94*0b57cec5SDimitry Andric 
95*0b57cec5SDimitry Andric Optional<uint64_t>
96*0b57cec5SDimitry Andric ProfileSummaryInfo::getProfileCount(const Instruction *Inst,
97*0b57cec5SDimitry Andric                                     BlockFrequencyInfo *BFI,
98*0b57cec5SDimitry Andric                                     bool AllowSynthetic) {
99*0b57cec5SDimitry Andric   if (!Inst)
100*0b57cec5SDimitry Andric     return None;
101*0b57cec5SDimitry Andric   assert((isa<CallInst>(Inst) || isa<InvokeInst>(Inst)) &&
102*0b57cec5SDimitry Andric          "We can only get profile count for call/invoke instruction.");
103*0b57cec5SDimitry Andric   if (hasSampleProfile()) {
104*0b57cec5SDimitry Andric     // In sample PGO mode, check if there is a profile metadata on the
105*0b57cec5SDimitry Andric     // instruction. If it is present, determine hotness solely based on that,
106*0b57cec5SDimitry Andric     // since the sampled entry count may not be accurate. If there is no
107*0b57cec5SDimitry Andric     // annotated on the instruction, return None.
108*0b57cec5SDimitry Andric     uint64_t TotalCount;
109*0b57cec5SDimitry Andric     if (Inst->extractProfTotalWeight(TotalCount))
110*0b57cec5SDimitry Andric       return TotalCount;
111*0b57cec5SDimitry Andric     return None;
112*0b57cec5SDimitry Andric   }
113*0b57cec5SDimitry Andric   if (BFI)
114*0b57cec5SDimitry Andric     return BFI->getBlockProfileCount(Inst->getParent(), AllowSynthetic);
115*0b57cec5SDimitry Andric   return None;
116*0b57cec5SDimitry Andric }
117*0b57cec5SDimitry Andric 
118*0b57cec5SDimitry Andric /// Returns true if the function's entry is hot. If it returns false, it
119*0b57cec5SDimitry Andric /// either means it is not hot or it is unknown whether it is hot or not (for
120*0b57cec5SDimitry Andric /// example, no profile data is available).
121*0b57cec5SDimitry Andric bool ProfileSummaryInfo::isFunctionEntryHot(const Function *F) {
122*0b57cec5SDimitry Andric   if (!F || !computeSummary())
123*0b57cec5SDimitry Andric     return false;
124*0b57cec5SDimitry Andric   auto FunctionCount = F->getEntryCount();
125*0b57cec5SDimitry Andric   // FIXME: The heuristic used below for determining hotness is based on
126*0b57cec5SDimitry Andric   // preliminary SPEC tuning for inliner. This will eventually be a
127*0b57cec5SDimitry Andric   // convenience method that calls isHotCount.
128*0b57cec5SDimitry Andric   return FunctionCount && isHotCount(FunctionCount.getCount());
129*0b57cec5SDimitry Andric }
130*0b57cec5SDimitry Andric 
131*0b57cec5SDimitry Andric /// Returns true if the function contains hot code. This can include a hot
132*0b57cec5SDimitry Andric /// function entry count, hot basic block, or (in the case of Sample PGO)
133*0b57cec5SDimitry Andric /// hot total call edge count.
134*0b57cec5SDimitry Andric /// If it returns false, it either means it is not hot or it is unknown
135*0b57cec5SDimitry Andric /// (for example, no profile data is available).
136*0b57cec5SDimitry Andric bool ProfileSummaryInfo::isFunctionHotInCallGraph(const Function *F,
137*0b57cec5SDimitry Andric                                                   BlockFrequencyInfo &BFI) {
138*0b57cec5SDimitry Andric   if (!F || !computeSummary())
139*0b57cec5SDimitry Andric     return false;
140*0b57cec5SDimitry Andric   if (auto FunctionCount = F->getEntryCount())
141*0b57cec5SDimitry Andric     if (isHotCount(FunctionCount.getCount()))
142*0b57cec5SDimitry Andric       return true;
143*0b57cec5SDimitry Andric 
144*0b57cec5SDimitry Andric   if (hasSampleProfile()) {
145*0b57cec5SDimitry Andric     uint64_t TotalCallCount = 0;
146*0b57cec5SDimitry Andric     for (const auto &BB : *F)
147*0b57cec5SDimitry Andric       for (const auto &I : BB)
148*0b57cec5SDimitry Andric         if (isa<CallInst>(I) || isa<InvokeInst>(I))
149*0b57cec5SDimitry Andric           if (auto CallCount = getProfileCount(&I, nullptr))
150*0b57cec5SDimitry Andric             TotalCallCount += CallCount.getValue();
151*0b57cec5SDimitry Andric     if (isHotCount(TotalCallCount))
152*0b57cec5SDimitry Andric       return true;
153*0b57cec5SDimitry Andric   }
154*0b57cec5SDimitry Andric   for (const auto &BB : *F)
155*0b57cec5SDimitry Andric     if (isHotBlock(&BB, &BFI))
156*0b57cec5SDimitry Andric       return true;
157*0b57cec5SDimitry Andric   return false;
158*0b57cec5SDimitry Andric }
159*0b57cec5SDimitry Andric 
160*0b57cec5SDimitry Andric /// Returns true if the function only contains cold code. This means that
161*0b57cec5SDimitry Andric /// the function entry and blocks are all cold, and (in the case of Sample PGO)
162*0b57cec5SDimitry Andric /// the total call edge count is cold.
163*0b57cec5SDimitry Andric /// If it returns false, it either means it is not cold or it is unknown
164*0b57cec5SDimitry Andric /// (for example, no profile data is available).
165*0b57cec5SDimitry Andric bool ProfileSummaryInfo::isFunctionColdInCallGraph(const Function *F,
166*0b57cec5SDimitry Andric                                                    BlockFrequencyInfo &BFI) {
167*0b57cec5SDimitry Andric   if (!F || !computeSummary())
168*0b57cec5SDimitry Andric     return false;
169*0b57cec5SDimitry Andric   if (auto FunctionCount = F->getEntryCount())
170*0b57cec5SDimitry Andric     if (!isColdCount(FunctionCount.getCount()))
171*0b57cec5SDimitry Andric       return false;
172*0b57cec5SDimitry Andric 
173*0b57cec5SDimitry Andric   if (hasSampleProfile()) {
174*0b57cec5SDimitry Andric     uint64_t TotalCallCount = 0;
175*0b57cec5SDimitry Andric     for (const auto &BB : *F)
176*0b57cec5SDimitry Andric       for (const auto &I : BB)
177*0b57cec5SDimitry Andric         if (isa<CallInst>(I) || isa<InvokeInst>(I))
178*0b57cec5SDimitry Andric           if (auto CallCount = getProfileCount(&I, nullptr))
179*0b57cec5SDimitry Andric             TotalCallCount += CallCount.getValue();
180*0b57cec5SDimitry Andric     if (!isColdCount(TotalCallCount))
181*0b57cec5SDimitry Andric       return false;
182*0b57cec5SDimitry Andric   }
183*0b57cec5SDimitry Andric   for (const auto &BB : *F)
184*0b57cec5SDimitry Andric     if (!isColdBlock(&BB, &BFI))
185*0b57cec5SDimitry Andric       return false;
186*0b57cec5SDimitry Andric   return true;
187*0b57cec5SDimitry Andric }
188*0b57cec5SDimitry Andric 
189*0b57cec5SDimitry Andric /// Returns true if the function's entry is a cold. If it returns false, it
190*0b57cec5SDimitry Andric /// either means it is not cold or it is unknown whether it is cold or not (for
191*0b57cec5SDimitry Andric /// example, no profile data is available).
192*0b57cec5SDimitry Andric bool ProfileSummaryInfo::isFunctionEntryCold(const Function *F) {
193*0b57cec5SDimitry Andric   if (!F)
194*0b57cec5SDimitry Andric     return false;
195*0b57cec5SDimitry Andric   if (F->hasFnAttribute(Attribute::Cold))
196*0b57cec5SDimitry Andric     return true;
197*0b57cec5SDimitry Andric   if (!computeSummary())
198*0b57cec5SDimitry Andric     return false;
199*0b57cec5SDimitry Andric   auto FunctionCount = F->getEntryCount();
200*0b57cec5SDimitry Andric   // FIXME: The heuristic used below for determining coldness is based on
201*0b57cec5SDimitry Andric   // preliminary SPEC tuning for inliner. This will eventually be a
202*0b57cec5SDimitry Andric   // convenience method that calls isHotCount.
203*0b57cec5SDimitry Andric   return FunctionCount && isColdCount(FunctionCount.getCount());
204*0b57cec5SDimitry Andric }
205*0b57cec5SDimitry Andric 
206*0b57cec5SDimitry Andric /// Compute the hot and cold thresholds.
207*0b57cec5SDimitry Andric void ProfileSummaryInfo::computeThresholds() {
208*0b57cec5SDimitry Andric   if (!computeSummary())
209*0b57cec5SDimitry Andric     return;
210*0b57cec5SDimitry Andric   auto &DetailedSummary = Summary->getDetailedSummary();
211*0b57cec5SDimitry Andric   auto &HotEntry =
212*0b57cec5SDimitry Andric       getEntryForPercentile(DetailedSummary, ProfileSummaryCutoffHot);
213*0b57cec5SDimitry Andric   HotCountThreshold = HotEntry.MinCount;
214*0b57cec5SDimitry Andric   if (ProfileSummaryHotCount.getNumOccurrences() > 0)
215*0b57cec5SDimitry Andric     HotCountThreshold = ProfileSummaryHotCount;
216*0b57cec5SDimitry Andric   auto &ColdEntry =
217*0b57cec5SDimitry Andric       getEntryForPercentile(DetailedSummary, ProfileSummaryCutoffCold);
218*0b57cec5SDimitry Andric   ColdCountThreshold = ColdEntry.MinCount;
219*0b57cec5SDimitry Andric   if (ProfileSummaryColdCount.getNumOccurrences() > 0)
220*0b57cec5SDimitry Andric     ColdCountThreshold = ProfileSummaryColdCount;
221*0b57cec5SDimitry Andric   assert(ColdCountThreshold <= HotCountThreshold &&
222*0b57cec5SDimitry Andric          "Cold count threshold cannot exceed hot count threshold!");
223*0b57cec5SDimitry Andric   HasHugeWorkingSetSize =
224*0b57cec5SDimitry Andric       HotEntry.NumCounts > ProfileSummaryHugeWorkingSetSizeThreshold;
225*0b57cec5SDimitry Andric }
226*0b57cec5SDimitry Andric 
227*0b57cec5SDimitry Andric bool ProfileSummaryInfo::hasHugeWorkingSetSize() {
228*0b57cec5SDimitry Andric   if (!HasHugeWorkingSetSize)
229*0b57cec5SDimitry Andric     computeThresholds();
230*0b57cec5SDimitry Andric   return HasHugeWorkingSetSize && HasHugeWorkingSetSize.getValue();
231*0b57cec5SDimitry Andric }
232*0b57cec5SDimitry Andric 
233*0b57cec5SDimitry Andric bool ProfileSummaryInfo::isHotCount(uint64_t C) {
234*0b57cec5SDimitry Andric   if (!HotCountThreshold)
235*0b57cec5SDimitry Andric     computeThresholds();
236*0b57cec5SDimitry Andric   return HotCountThreshold && C >= HotCountThreshold.getValue();
237*0b57cec5SDimitry Andric }
238*0b57cec5SDimitry Andric 
239*0b57cec5SDimitry Andric bool ProfileSummaryInfo::isColdCount(uint64_t C) {
240*0b57cec5SDimitry Andric   if (!ColdCountThreshold)
241*0b57cec5SDimitry Andric     computeThresholds();
242*0b57cec5SDimitry Andric   return ColdCountThreshold && C <= ColdCountThreshold.getValue();
243*0b57cec5SDimitry Andric }
244*0b57cec5SDimitry Andric 
245*0b57cec5SDimitry Andric uint64_t ProfileSummaryInfo::getOrCompHotCountThreshold() {
246*0b57cec5SDimitry Andric   if (!HotCountThreshold)
247*0b57cec5SDimitry Andric     computeThresholds();
248*0b57cec5SDimitry Andric   return HotCountThreshold ? HotCountThreshold.getValue() : UINT64_MAX;
249*0b57cec5SDimitry Andric }
250*0b57cec5SDimitry Andric 
251*0b57cec5SDimitry Andric uint64_t ProfileSummaryInfo::getOrCompColdCountThreshold() {
252*0b57cec5SDimitry Andric   if (!ColdCountThreshold)
253*0b57cec5SDimitry Andric     computeThresholds();
254*0b57cec5SDimitry Andric   return ColdCountThreshold ? ColdCountThreshold.getValue() : 0;
255*0b57cec5SDimitry Andric }
256*0b57cec5SDimitry Andric 
257*0b57cec5SDimitry Andric bool ProfileSummaryInfo::isHotBlock(const BasicBlock *BB, BlockFrequencyInfo *BFI) {
258*0b57cec5SDimitry Andric   auto Count = BFI->getBlockProfileCount(BB);
259*0b57cec5SDimitry Andric   return Count && isHotCount(*Count);
260*0b57cec5SDimitry Andric }
261*0b57cec5SDimitry Andric 
262*0b57cec5SDimitry Andric bool ProfileSummaryInfo::isColdBlock(const BasicBlock *BB,
263*0b57cec5SDimitry Andric                                   BlockFrequencyInfo *BFI) {
264*0b57cec5SDimitry Andric   auto Count = BFI->getBlockProfileCount(BB);
265*0b57cec5SDimitry Andric   return Count && isColdCount(*Count);
266*0b57cec5SDimitry Andric }
267*0b57cec5SDimitry Andric 
268*0b57cec5SDimitry Andric bool ProfileSummaryInfo::isHotCallSite(const CallSite &CS,
269*0b57cec5SDimitry Andric                                        BlockFrequencyInfo *BFI) {
270*0b57cec5SDimitry Andric   auto C = getProfileCount(CS.getInstruction(), BFI);
271*0b57cec5SDimitry Andric   return C && isHotCount(*C);
272*0b57cec5SDimitry Andric }
273*0b57cec5SDimitry Andric 
274*0b57cec5SDimitry Andric bool ProfileSummaryInfo::isColdCallSite(const CallSite &CS,
275*0b57cec5SDimitry Andric                                         BlockFrequencyInfo *BFI) {
276*0b57cec5SDimitry Andric   auto C = getProfileCount(CS.getInstruction(), BFI);
277*0b57cec5SDimitry Andric   if (C)
278*0b57cec5SDimitry Andric     return isColdCount(*C);
279*0b57cec5SDimitry Andric 
280*0b57cec5SDimitry Andric   // In SamplePGO, if the caller has been sampled, and there is no profile
281*0b57cec5SDimitry Andric   // annotated on the callsite, we consider the callsite as cold.
282*0b57cec5SDimitry Andric   return hasSampleProfile() && CS.getCaller()->hasProfileData();
283*0b57cec5SDimitry Andric }
284*0b57cec5SDimitry Andric 
285*0b57cec5SDimitry Andric INITIALIZE_PASS(ProfileSummaryInfoWrapperPass, "profile-summary-info",
286*0b57cec5SDimitry Andric                 "Profile summary info", false, true)
287*0b57cec5SDimitry Andric 
288*0b57cec5SDimitry Andric ProfileSummaryInfoWrapperPass::ProfileSummaryInfoWrapperPass()
289*0b57cec5SDimitry Andric     : ImmutablePass(ID) {
290*0b57cec5SDimitry Andric   initializeProfileSummaryInfoWrapperPassPass(*PassRegistry::getPassRegistry());
291*0b57cec5SDimitry Andric }
292*0b57cec5SDimitry Andric 
293*0b57cec5SDimitry Andric bool ProfileSummaryInfoWrapperPass::doInitialization(Module &M) {
294*0b57cec5SDimitry Andric   PSI.reset(new ProfileSummaryInfo(M));
295*0b57cec5SDimitry Andric   return false;
296*0b57cec5SDimitry Andric }
297*0b57cec5SDimitry Andric 
298*0b57cec5SDimitry Andric bool ProfileSummaryInfoWrapperPass::doFinalization(Module &M) {
299*0b57cec5SDimitry Andric   PSI.reset();
300*0b57cec5SDimitry Andric   return false;
301*0b57cec5SDimitry Andric }
302*0b57cec5SDimitry Andric 
303*0b57cec5SDimitry Andric AnalysisKey ProfileSummaryAnalysis::Key;
304*0b57cec5SDimitry Andric ProfileSummaryInfo ProfileSummaryAnalysis::run(Module &M,
305*0b57cec5SDimitry Andric                                                ModuleAnalysisManager &) {
306*0b57cec5SDimitry Andric   return ProfileSummaryInfo(M);
307*0b57cec5SDimitry Andric }
308*0b57cec5SDimitry Andric 
309*0b57cec5SDimitry Andric PreservedAnalyses ProfileSummaryPrinterPass::run(Module &M,
310*0b57cec5SDimitry Andric                                                  ModuleAnalysisManager &AM) {
311*0b57cec5SDimitry Andric   ProfileSummaryInfo &PSI = AM.getResult<ProfileSummaryAnalysis>(M);
312*0b57cec5SDimitry Andric 
313*0b57cec5SDimitry Andric   OS << "Functions in " << M.getName() << " with hot/cold annotations: \n";
314*0b57cec5SDimitry Andric   for (auto &F : M) {
315*0b57cec5SDimitry Andric     OS << F.getName();
316*0b57cec5SDimitry Andric     if (PSI.isFunctionEntryHot(&F))
317*0b57cec5SDimitry Andric       OS << " :hot entry ";
318*0b57cec5SDimitry Andric     else if (PSI.isFunctionEntryCold(&F))
319*0b57cec5SDimitry Andric       OS << " :cold entry ";
320*0b57cec5SDimitry Andric     OS << "\n";
321*0b57cec5SDimitry Andric   }
322*0b57cec5SDimitry Andric   return PreservedAnalyses::all();
323*0b57cec5SDimitry Andric }
324*0b57cec5SDimitry Andric 
325*0b57cec5SDimitry Andric char ProfileSummaryInfoWrapperPass::ID = 0;
326