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