blob: b99b75715025be9213c99313a881bee3da1089af [file] [log] [blame]
Easwaran Raman019e0bf2016-06-03 22:54:26 +00001//===- ProfileSummaryInfo.cpp - Global profile summary information --------===//
2//
Chandler Carruth2946cd72019-01-19 08:50:56 +00003// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
Easwaran Raman019e0bf2016-06-03 22:54:26 +00006//
7//===----------------------------------------------------------------------===//
8//
9// This file contains a pass that provides access to the global profile summary
10// information.
11//
12//===----------------------------------------------------------------------===//
13
14#include "llvm/Analysis/ProfileSummaryInfo.h"
Easwaran Ramanb035f912017-01-13 01:34:00 +000015#include "llvm/Analysis/BlockFrequencyInfo.h"
Dehao Chen38a666d2016-11-09 23:36:02 +000016#include "llvm/IR/BasicBlock.h"
Easwaran Ramanb035f912017-01-13 01:34:00 +000017#include "llvm/IR/CallSite.h"
Easwaran Raman019e0bf2016-06-03 22:54:26 +000018#include "llvm/IR/Metadata.h"
19#include "llvm/IR/Module.h"
20#include "llvm/IR/ProfileSummary.h"
21using namespace llvm;
22
23// The following two parameters determine the threshold for a count to be
24// considered hot/cold. These two parameters are percentile values (multiplied
25// by 10000). If the counts are sorted in descending order, the minimum count to
26// reach ProfileSummaryCutoffHot gives the threshold to determine a hot count.
27// Similarly, the minimum count to reach ProfileSummaryCutoffCold gives the
28// threshold for determining cold count (everything <= this threshold is
29// considered cold).
30
31static cl::opt<int> ProfileSummaryCutoffHot(
Dehao Chen63799512017-08-04 16:20:54 +000032 "profile-summary-cutoff-hot", cl::Hidden, cl::init(990000), cl::ZeroOrMore,
Easwaran Raman019e0bf2016-06-03 22:54:26 +000033 cl::desc("A count is hot if it exceeds the minimum count to"
34 " reach this percentile of total counts."));
35
36static cl::opt<int> ProfileSummaryCutoffCold(
37 "profile-summary-cutoff-cold", cl::Hidden, cl::init(999999), cl::ZeroOrMore,
38 cl::desc("A count is cold if it is below the minimum count"
39 " to reach this percentile of total counts."));
40
Teresa Johnson8482e562017-08-03 23:42:58 +000041static cl::opt<unsigned> ProfileSummaryHugeWorkingSetSizeThreshold(
42 "profile-summary-huge-working-set-size-threshold", cl::Hidden,
43 cl::init(15000), cl::ZeroOrMore,
44 cl::desc("The code working set size is considered huge if the number of"
45 " blocks required to reach the -profile-summary-cutoff-hot"
46 " percentile exceeds this count."));
Dehao Chenf58df392017-08-03 17:11:41 +000047
Hiroshi Yamauchi857424d2019-09-24 22:17:51 +000048static cl::opt<unsigned> ProfileSummaryLargeWorkingSetSizeThreshold(
49 "profile-summary-large-working-set-size-threshold", cl::Hidden,
50 cl::init(12500), cl::ZeroOrMore,
51 cl::desc("The code working set size is considered large if the number of"
52 " blocks required to reach the -profile-summary-cutoff-hot"
53 " percentile exceeds this count."));
54
Easwaran Ramanc5e15062018-11-02 17:39:31 +000055// The next two options override the counts derived from summary computation and
56// are useful for debugging purposes.
57static cl::opt<int> ProfileSummaryHotCount(
58 "profile-summary-hot-count", cl::ReallyHidden, cl::ZeroOrMore,
59 cl::desc("A fixed hot count that overrides the count derived from"
60 " profile-summary-cutoff-hot"));
61
62static cl::opt<int> ProfileSummaryColdCount(
63 "profile-summary-cold-count", cl::ReallyHidden, cl::ZeroOrMore,
64 cl::desc("A fixed cold count that overrides the count derived from"
65 " profile-summary-cutoff-cold"));
66
Teresa Johnson8482e562017-08-03 23:42:58 +000067// Find the summary entry for a desired percentile of counts.
68static const ProfileSummaryEntry &getEntryForPercentile(SummaryEntryVector &DS,
69 uint64_t Percentile) {
Fangrui Song78ee2fb2019-06-30 11:19:56 +000070 auto It = partition_point(DS, [=](const ProfileSummaryEntry &Entry) {
71 return Entry.Cutoff < Percentile;
Fangrui Songdc8de602019-06-21 05:40:31 +000072 });
Easwaran Raman019e0bf2016-06-03 22:54:26 +000073 // The required percentile has to be <= one of the percentiles in the
74 // detailed summary.
75 if (It == DS.end())
76 report_fatal_error("Desired percentile exceeds the maximum cutoff");
Teresa Johnson8482e562017-08-03 23:42:58 +000077 return *It;
Easwaran Raman019e0bf2016-06-03 22:54:26 +000078}
79
80// The profile summary metadata may be attached either by the frontend or by
81// any backend passes (IR level instrumentation, for example). This method
82// checks if the Summary is null and if so checks if the summary metadata is now
Easwaran Ramana7bdb8a2017-01-14 00:32:37 +000083// available in the module and parses it to get the Summary object. Returns true
84// if a valid Summary is available.
85bool ProfileSummaryInfo::computeSummary() {
Easwaran Raman019e0bf2016-06-03 22:54:26 +000086 if (Summary)
Easwaran Ramana7bdb8a2017-01-14 00:32:37 +000087 return true;
Rong Xua6ff69f2019-02-28 19:55:07 +000088 // First try to get context sensitive ProfileSummary.
89 auto *SummaryMD = M.getProfileSummary(/* IsCS */ true);
90 if (SummaryMD) {
91 Summary.reset(ProfileSummary::getFromMD(SummaryMD));
92 return true;
93 }
94 // This will actually return PSK_Instr or PSK_Sample summary.
95 SummaryMD = M.getProfileSummary(/* IsCS */ false);
Easwaran Raman019e0bf2016-06-03 22:54:26 +000096 if (!SummaryMD)
Easwaran Ramana7bdb8a2017-01-14 00:32:37 +000097 return false;
Easwaran Raman019e0bf2016-06-03 22:54:26 +000098 Summary.reset(ProfileSummary::getFromMD(SummaryMD));
Easwaran Ramana7bdb8a2017-01-14 00:32:37 +000099 return true;
Easwaran Raman019e0bf2016-06-03 22:54:26 +0000100}
101
Dehao Chenc2048152017-03-10 19:45:16 +0000102Optional<uint64_t>
103ProfileSummaryInfo::getProfileCount(const Instruction *Inst,
Xinliang David Li499c80b2019-04-24 19:51:16 +0000104 BlockFrequencyInfo *BFI,
105 bool AllowSynthetic) {
Dehao Chenc2048152017-03-10 19:45:16 +0000106 if (!Inst)
107 return None;
108 assert((isa<CallInst>(Inst) || isa<InvokeInst>(Inst)) &&
109 "We can only get profile count for call/invoke instruction.");
Easwaran Ramandadc0f12017-05-16 20:14:39 +0000110 if (hasSampleProfile()) {
Teresa Johnson2a6b7992017-05-11 23:18:05 +0000111 // In sample PGO mode, check if there is a profile metadata on the
112 // instruction. If it is present, determine hotness solely based on that,
Dehao Chenf58df392017-08-03 17:11:41 +0000113 // since the sampled entry count may not be accurate. If there is no
114 // annotated on the instruction, return None.
Teresa Johnson2a6b7992017-05-11 23:18:05 +0000115 uint64_t TotalCount;
116 if (Inst->extractProfTotalWeight(TotalCount))
117 return TotalCount;
Dehao Chenf58df392017-08-03 17:11:41 +0000118 return None;
Teresa Johnson2a6b7992017-05-11 23:18:05 +0000119 }
Dehao Chenc2048152017-03-10 19:45:16 +0000120 if (BFI)
Xinliang David Li499c80b2019-04-24 19:51:16 +0000121 return BFI->getBlockProfileCount(Inst->getParent(), AllowSynthetic);
Dehao Chenc2048152017-03-10 19:45:16 +0000122 return None;
123}
124
Dehao Chen84287ab2016-10-10 21:47:28 +0000125/// Returns true if the function's entry is hot. If it returns false, it
126/// either means it is not hot or it is unknown whether it is hot or not (for
Piotr Padlewskif3d122c2016-09-30 21:05:49 +0000127/// example, no profile data is available).
Dehao Chen84287ab2016-10-10 21:47:28 +0000128bool ProfileSummaryInfo::isFunctionEntryHot(const Function *F) {
Easwaran Ramana7bdb8a2017-01-14 00:32:37 +0000129 if (!F || !computeSummary())
Easwaran Raman019e0bf2016-06-03 22:54:26 +0000130 return false;
131 auto FunctionCount = F->getEntryCount();
132 // FIXME: The heuristic used below for determining hotness is based on
133 // preliminary SPEC tuning for inliner. This will eventually be a
134 // convenience method that calls isHotCount.
Easwaran Ramane5b8de22018-01-17 22:24:23 +0000135 return FunctionCount && isHotCount(FunctionCount.getCount());
Easwaran Raman019e0bf2016-06-03 22:54:26 +0000136}
137
Teresa Johnsona4ce3bf2017-12-20 17:53:10 +0000138/// Returns true if the function contains hot code. This can include a hot
139/// function entry count, hot basic block, or (in the case of Sample PGO)
140/// hot total call edge count.
Dehao Chen775341a2017-03-23 23:14:11 +0000141/// If it returns false, it either means it is not hot or it is unknown
Teresa Johnsona4ce3bf2017-12-20 17:53:10 +0000142/// (for example, no profile data is available).
143bool ProfileSummaryInfo::isFunctionHotInCallGraph(const Function *F,
144 BlockFrequencyInfo &BFI) {
Dehao Chen775341a2017-03-23 23:14:11 +0000145 if (!F || !computeSummary())
146 return false;
147 if (auto FunctionCount = F->getEntryCount())
Easwaran Ramane5b8de22018-01-17 22:24:23 +0000148 if (isHotCount(FunctionCount.getCount()))
Dehao Chen775341a2017-03-23 23:14:11 +0000149 return true;
150
Teresa Johnsona4ce3bf2017-12-20 17:53:10 +0000151 if (hasSampleProfile()) {
152 uint64_t TotalCallCount = 0;
153 for (const auto &BB : *F)
154 for (const auto &I : BB)
155 if (isa<CallInst>(I) || isa<InvokeInst>(I))
156 if (auto CallCount = getProfileCount(&I, nullptr))
157 TotalCallCount += CallCount.getValue();
158 if (isHotCount(TotalCallCount))
159 return true;
160 }
Dehao Chen775341a2017-03-23 23:14:11 +0000161 for (const auto &BB : *F)
Vedant Kumare7b789b2018-11-19 05:23:16 +0000162 if (isHotBlock(&BB, &BFI))
Teresa Johnsona4ce3bf2017-12-20 17:53:10 +0000163 return true;
164 return false;
Dehao Chen775341a2017-03-23 23:14:11 +0000165}
166
Teresa Johnsona4ce3bf2017-12-20 17:53:10 +0000167/// Returns true if the function only contains cold code. This means that
168/// the function entry and blocks are all cold, and (in the case of Sample PGO)
169/// the total call edge count is cold.
Dehao Chen775341a2017-03-23 23:14:11 +0000170/// If it returns false, it either means it is not cold or it is unknown
Teresa Johnsona4ce3bf2017-12-20 17:53:10 +0000171/// (for example, no profile data is available).
172bool ProfileSummaryInfo::isFunctionColdInCallGraph(const Function *F,
173 BlockFrequencyInfo &BFI) {
Dehao Chen775341a2017-03-23 23:14:11 +0000174 if (!F || !computeSummary())
175 return false;
176 if (auto FunctionCount = F->getEntryCount())
Easwaran Ramane5b8de22018-01-17 22:24:23 +0000177 if (!isColdCount(FunctionCount.getCount()))
Dehao Chen775341a2017-03-23 23:14:11 +0000178 return false;
Teresa Johnsona4ce3bf2017-12-20 17:53:10 +0000179
180 if (hasSampleProfile()) {
181 uint64_t TotalCallCount = 0;
182 for (const auto &BB : *F)
183 for (const auto &I : BB)
184 if (isa<CallInst>(I) || isa<InvokeInst>(I))
185 if (auto CallCount = getProfileCount(&I, nullptr))
186 TotalCallCount += CallCount.getValue();
187 if (!isColdCount(TotalCallCount))
188 return false;
189 }
Dehao Chen775341a2017-03-23 23:14:11 +0000190 for (const auto &BB : *F)
Vedant Kumare7b789b2018-11-19 05:23:16 +0000191 if (!isColdBlock(&BB, &BFI))
Teresa Johnsona4ce3bf2017-12-20 17:53:10 +0000192 return false;
193 return true;
Dehao Chen775341a2017-03-23 23:14:11 +0000194}
195
Hiroshi Yamauchi857424d2019-09-24 22:17:51 +0000196// Like isFunctionHotInCallGraph but for a given cutoff.
197bool ProfileSummaryInfo::isFunctionHotInCallGraphNthPercentile(
198 int PercentileCutoff, const Function *F, BlockFrequencyInfo &BFI) {
199 if (!F || !computeSummary())
200 return false;
201 if (auto FunctionCount = F->getEntryCount())
202 if (isHotCountNthPercentile(PercentileCutoff, FunctionCount.getCount()))
203 return true;
204
205 if (hasSampleProfile()) {
206 uint64_t TotalCallCount = 0;
207 for (const auto &BB : *F)
208 for (const auto &I : BB)
209 if (isa<CallInst>(I) || isa<InvokeInst>(I))
210 if (auto CallCount = getProfileCount(&I, nullptr))
211 TotalCallCount += CallCount.getValue();
212 if (isHotCountNthPercentile(PercentileCutoff, TotalCallCount))
213 return true;
214 }
215 for (const auto &BB : *F)
216 if (isHotBlockNthPercentile(PercentileCutoff, &BB, &BFI))
217 return true;
218 return false;
219}
220
Dehao Chen84287ab2016-10-10 21:47:28 +0000221/// Returns true if the function's entry is a cold. If it returns false, it
222/// either means it is not cold or it is unknown whether it is cold or not (for
Piotr Padlewskif3d122c2016-09-30 21:05:49 +0000223/// example, no profile data is available).
Dehao Chen84287ab2016-10-10 21:47:28 +0000224bool ProfileSummaryInfo::isFunctionEntryCold(const Function *F) {
Richard Trieufae70b62016-06-10 01:42:05 +0000225 if (!F)
226 return false;
Davide Italiano574e5972017-03-10 20:50:51 +0000227 if (F->hasFnAttribute(Attribute::Cold))
Easwaran Raman019e0bf2016-06-03 22:54:26 +0000228 return true;
Easwaran Ramana7bdb8a2017-01-14 00:32:37 +0000229 if (!computeSummary())
Richard Trieufae70b62016-06-10 01:42:05 +0000230 return false;
Easwaran Raman019e0bf2016-06-03 22:54:26 +0000231 auto FunctionCount = F->getEntryCount();
232 // FIXME: The heuristic used below for determining coldness is based on
233 // preliminary SPEC tuning for inliner. This will eventually be a
234 // convenience method that calls isHotCount.
Easwaran Ramane5b8de22018-01-17 22:24:23 +0000235 return FunctionCount && isColdCount(FunctionCount.getCount());
Easwaran Raman019e0bf2016-06-03 22:54:26 +0000236}
237
Piotr Padlewskif3d122c2016-09-30 21:05:49 +0000238/// Compute the hot and cold thresholds.
Easwaran Raman019e0bf2016-06-03 22:54:26 +0000239void ProfileSummaryInfo::computeThresholds() {
Easwaran Ramana7bdb8a2017-01-14 00:32:37 +0000240 if (!computeSummary())
Easwaran Raman019e0bf2016-06-03 22:54:26 +0000241 return;
242 auto &DetailedSummary = Summary->getDetailedSummary();
Teresa Johnson8482e562017-08-03 23:42:58 +0000243 auto &HotEntry =
244 getEntryForPercentile(DetailedSummary, ProfileSummaryCutoffHot);
245 HotCountThreshold = HotEntry.MinCount;
Easwaran Ramanc5e15062018-11-02 17:39:31 +0000246 if (ProfileSummaryHotCount.getNumOccurrences() > 0)
247 HotCountThreshold = ProfileSummaryHotCount;
Teresa Johnson8482e562017-08-03 23:42:58 +0000248 auto &ColdEntry =
249 getEntryForPercentile(DetailedSummary, ProfileSummaryCutoffCold);
250 ColdCountThreshold = ColdEntry.MinCount;
Easwaran Ramanc5e15062018-11-02 17:39:31 +0000251 if (ProfileSummaryColdCount.getNumOccurrences() > 0)
252 ColdCountThreshold = ProfileSummaryColdCount;
253 assert(ColdCountThreshold <= HotCountThreshold &&
254 "Cold count threshold cannot exceed hot count threshold!");
Teresa Johnson8482e562017-08-03 23:42:58 +0000255 HasHugeWorkingSetSize =
256 HotEntry.NumCounts > ProfileSummaryHugeWorkingSetSizeThreshold;
Hiroshi Yamauchi857424d2019-09-24 22:17:51 +0000257 HasLargeWorkingSetSize =
258 HotEntry.NumCounts > ProfileSummaryLargeWorkingSetSizeThreshold;
259}
260
261Optional<uint64_t> ProfileSummaryInfo::computeThreshold(int PercentileCutoff) {
262 if (!computeSummary())
263 return None;
264 auto iter = ThresholdCache.find(PercentileCutoff);
265 if (iter != ThresholdCache.end()) {
266 return iter->second;
267 }
268 auto &DetailedSummary = Summary->getDetailedSummary();
269 auto &Entry =
270 getEntryForPercentile(DetailedSummary, PercentileCutoff);
271 uint64_t CountThreshold = Entry.MinCount;
272 ThresholdCache[PercentileCutoff] = CountThreshold;
273 return CountThreshold;
Teresa Johnson8482e562017-08-03 23:42:58 +0000274}
275
276bool ProfileSummaryInfo::hasHugeWorkingSetSize() {
277 if (!HasHugeWorkingSetSize)
278 computeThresholds();
279 return HasHugeWorkingSetSize && HasHugeWorkingSetSize.getValue();
Easwaran Raman019e0bf2016-06-03 22:54:26 +0000280}
281
Hiroshi Yamauchi857424d2019-09-24 22:17:51 +0000282bool ProfileSummaryInfo::hasLargeWorkingSetSize() {
283 if (!HasLargeWorkingSetSize)
284 computeThresholds();
285 return HasLargeWorkingSetSize && HasLargeWorkingSetSize.getValue();
286}
287
Easwaran Raman019e0bf2016-06-03 22:54:26 +0000288bool ProfileSummaryInfo::isHotCount(uint64_t C) {
289 if (!HotCountThreshold)
290 computeThresholds();
291 return HotCountThreshold && C >= HotCountThreshold.getValue();
292}
293
294bool ProfileSummaryInfo::isColdCount(uint64_t C) {
295 if (!ColdCountThreshold)
296 computeThresholds();
297 return ColdCountThreshold && C <= ColdCountThreshold.getValue();
298}
299
Hiroshi Yamauchi857424d2019-09-24 22:17:51 +0000300bool ProfileSummaryInfo::isHotCountNthPercentile(int PercentileCutoff, uint64_t C) {
301 auto CountThreshold = computeThreshold(PercentileCutoff);
302 return CountThreshold && C >= CountThreshold.getValue();
303}
304
Wei Mi0c2f6be2018-05-10 23:02:27 +0000305uint64_t ProfileSummaryInfo::getOrCompHotCountThreshold() {
306 if (!HotCountThreshold)
307 computeThresholds();
Wei Mib1ef2cc2018-08-07 18:13:10 +0000308 return HotCountThreshold ? HotCountThreshold.getValue() : UINT64_MAX;
Wei Mi0c2f6be2018-05-10 23:02:27 +0000309}
310
311uint64_t ProfileSummaryInfo::getOrCompColdCountThreshold() {
312 if (!ColdCountThreshold)
313 computeThresholds();
Wei Mib1ef2cc2018-08-07 18:13:10 +0000314 return ColdCountThreshold ? ColdCountThreshold.getValue() : 0;
Wei Mi0c2f6be2018-05-10 23:02:27 +0000315}
316
Vedant Kumare7b789b2018-11-19 05:23:16 +0000317bool ProfileSummaryInfo::isHotBlock(const BasicBlock *BB, BlockFrequencyInfo *BFI) {
318 auto Count = BFI->getBlockProfileCount(BB);
Dehao Chen22645ee2017-03-10 01:44:37 +0000319 return Count && isHotCount(*Count);
Easwaran Ramanb035f912017-01-13 01:34:00 +0000320}
321
Vedant Kumare7b789b2018-11-19 05:23:16 +0000322bool ProfileSummaryInfo::isColdBlock(const BasicBlock *BB,
Easwaran Ramanb035f912017-01-13 01:34:00 +0000323 BlockFrequencyInfo *BFI) {
Vedant Kumare7b789b2018-11-19 05:23:16 +0000324 auto Count = BFI->getBlockProfileCount(BB);
Wei Mi66c6c5a2018-12-13 21:51:42 +0000325 return Count && isColdCount(*Count);
Easwaran Ramanb035f912017-01-13 01:34:00 +0000326}
327
Hiroshi Yamauchi857424d2019-09-24 22:17:51 +0000328bool ProfileSummaryInfo::isHotBlockNthPercentile(int PercentileCutoff,
329 const BasicBlock *BB,
330 BlockFrequencyInfo *BFI) {
331 auto Count = BFI->getBlockProfileCount(BB);
332 return Count && isHotCountNthPercentile(PercentileCutoff, *Count);
333}
334
Easwaran Ramanb035f912017-01-13 01:34:00 +0000335bool ProfileSummaryInfo::isHotCallSite(const CallSite &CS,
336 BlockFrequencyInfo *BFI) {
Dehao Chenc2048152017-03-10 19:45:16 +0000337 auto C = getProfileCount(CS.getInstruction(), BFI);
338 return C && isHotCount(*C);
Easwaran Ramanb035f912017-01-13 01:34:00 +0000339}
340
341bool ProfileSummaryInfo::isColdCallSite(const CallSite &CS,
342 BlockFrequencyInfo *BFI) {
Dehao Chenc2048152017-03-10 19:45:16 +0000343 auto C = getProfileCount(CS.getInstruction(), BFI);
Dehao Chenf58df392017-08-03 17:11:41 +0000344 if (C)
345 return isColdCount(*C);
346
347 // In SamplePGO, if the caller has been sampled, and there is no profile
George Burgess IVceecd452018-04-12 18:36:01 +0000348 // annotated on the callsite, we consider the callsite as cold.
Wei Mi66c6c5a2018-12-13 21:51:42 +0000349 return hasSampleProfile() && CS.getCaller()->hasProfileData();
Dehao Chen38a666d2016-11-09 23:36:02 +0000350}
351
Easwaran Raman019e0bf2016-06-03 22:54:26 +0000352INITIALIZE_PASS(ProfileSummaryInfoWrapperPass, "profile-summary-info",
353 "Profile summary info", false, true)
354
355ProfileSummaryInfoWrapperPass::ProfileSummaryInfoWrapperPass()
356 : ImmutablePass(ID) {
357 initializeProfileSummaryInfoWrapperPassPass(*PassRegistry::getPassRegistry());
358}
359
Dehao Chen5461d8b2016-09-28 21:00:58 +0000360bool ProfileSummaryInfoWrapperPass::doInitialization(Module &M) {
361 PSI.reset(new ProfileSummaryInfo(M));
362 return false;
363}
364
365bool ProfileSummaryInfoWrapperPass::doFinalization(Module &M) {
366 PSI.reset();
367 return false;
368}
369
Chandler Carruthdab4eae2016-11-23 17:53:26 +0000370AnalysisKey ProfileSummaryAnalysis::Key;
Chandler Carruth164a2aa62016-06-17 00:11:01 +0000371ProfileSummaryInfo ProfileSummaryAnalysis::run(Module &M,
372 ModuleAnalysisManager &) {
Dehao Chen5461d8b2016-09-28 21:00:58 +0000373 return ProfileSummaryInfo(M);
Easwaran Raman019e0bf2016-06-03 22:54:26 +0000374}
375
Easwaran Raman019e0bf2016-06-03 22:54:26 +0000376PreservedAnalyses ProfileSummaryPrinterPass::run(Module &M,
Sean Silvafd03ac62016-08-09 00:28:38 +0000377 ModuleAnalysisManager &AM) {
Easwaran Raman019e0bf2016-06-03 22:54:26 +0000378 ProfileSummaryInfo &PSI = AM.getResult<ProfileSummaryAnalysis>(M);
379
380 OS << "Functions in " << M.getName() << " with hot/cold annotations: \n";
381 for (auto &F : M) {
382 OS << F.getName();
Dehao Chen84287ab2016-10-10 21:47:28 +0000383 if (PSI.isFunctionEntryHot(&F))
384 OS << " :hot entry ";
385 else if (PSI.isFunctionEntryCold(&F))
386 OS << " :cold entry ";
Easwaran Raman019e0bf2016-06-03 22:54:26 +0000387 OS << "\n";
388 }
389 return PreservedAnalyses::all();
390}
391
392char ProfileSummaryInfoWrapperPass::ID = 0;