@@ -86,23 +86,24 @@ static const ProfileSummaryEntry &getEntryForPercentile(SummaryEntryVector &DS,
86
86
// The profile summary metadata may be attached either by the frontend or by
87
87
// any backend passes (IR level instrumentation, for example). This method
88
88
// checks if the Summary is null and if so checks if the summary metadata is now
89
- // available in the module and parses it to get the Summary object. Returns true
90
- // if a valid Summary is available.
91
- bool ProfileSummaryInfo::computeSummary () {
92
- if (Summary)
93
- return true ;
89
+ // available in the module and parses it to get the Summary object.
90
+ void ProfileSummaryInfo::refresh () {
91
+ if (hasProfileSummary ())
92
+ return ;
94
93
// First try to get context sensitive ProfileSummary.
95
94
auto *SummaryMD = M.getProfileSummary (/* IsCS */ true );
96
- if (SummaryMD) {
95
+ if (SummaryMD)
97
96
Summary.reset (ProfileSummary::getFromMD (SummaryMD));
98
- return true ;
97
+
98
+ if (!hasProfileSummary ()) {
99
+ // This will actually return PSK_Instr or PSK_Sample summary.
100
+ SummaryMD = M.getProfileSummary (/* IsCS */ false );
101
+ if (SummaryMD)
102
+ Summary.reset (ProfileSummary::getFromMD (SummaryMD));
99
103
}
100
- // This will actually return PSK_Instr or PSK_Sample summary.
101
- SummaryMD = M.getProfileSummary (/* IsCS */ false );
102
- if (!SummaryMD)
103
- return false ;
104
- Summary.reset (ProfileSummary::getFromMD (SummaryMD));
105
- return true ;
104
+ if (!hasProfileSummary ())
105
+ return ;
106
+ computeThresholds ();
106
107
}
107
108
108
109
Optional<uint64_t > ProfileSummaryInfo::getProfileCount (const CallBase &Call,
@@ -129,7 +130,7 @@ Optional<uint64_t> ProfileSummaryInfo::getProfileCount(const CallBase &Call,
129
130
// / either means it is not hot or it is unknown whether it is hot or not (for
130
131
// / example, no profile data is available).
131
132
bool ProfileSummaryInfo::isFunctionEntryHot (const Function *F) {
132
- if (!F || !computeSummary ())
133
+ if (!F || !hasProfileSummary ())
133
134
return false ;
134
135
auto FunctionCount = F->getEntryCount ();
135
136
// FIXME: The heuristic used below for determining hotness is based on
@@ -145,7 +146,7 @@ bool ProfileSummaryInfo::isFunctionEntryHot(const Function *F) {
145
146
// / (for example, no profile data is available).
146
147
bool ProfileSummaryInfo::isFunctionHotInCallGraph (const Function *F,
147
148
BlockFrequencyInfo &BFI) {
148
- if (!F || !computeSummary ())
149
+ if (!F || !hasProfileSummary ())
149
150
return false ;
150
151
if (auto FunctionCount = F->getEntryCount ())
151
152
if (isHotCount (FunctionCount.getCount ()))
@@ -174,7 +175,7 @@ bool ProfileSummaryInfo::isFunctionHotInCallGraph(const Function *F,
174
175
// / (for example, no profile data is available).
175
176
bool ProfileSummaryInfo::isFunctionColdInCallGraph (const Function *F,
176
177
BlockFrequencyInfo &BFI) {
177
- if (!F || !computeSummary ())
178
+ if (!F || !hasProfileSummary ())
178
179
return false ;
179
180
if (auto FunctionCount = F->getEntryCount ())
180
181
if (!isColdCount (FunctionCount.getCount ()))
@@ -204,7 +205,7 @@ bool ProfileSummaryInfo::isFunctionHotnessUnknown(const Function &F) {
204
205
template <bool isHot>
205
206
bool ProfileSummaryInfo::isFunctionHotOrColdInCallGraphNthPercentile (
206
207
int PercentileCutoff, const Function *F, BlockFrequencyInfo &BFI) {
207
- if (!F || !computeSummary ())
208
+ if (!F || !hasProfileSummary ())
208
209
return false ;
209
210
if (auto FunctionCount = F->getEntryCount ()) {
210
211
if (isHot &&
@@ -256,7 +257,7 @@ bool ProfileSummaryInfo::isFunctionEntryCold(const Function *F) {
256
257
return false ;
257
258
if (F->hasFnAttribute (Attribute::Cold))
258
259
return true ;
259
- if (!computeSummary ())
260
+ if (!hasProfileSummary ())
260
261
return false ;
261
262
auto FunctionCount = F->getEntryCount ();
262
263
// FIXME: The heuristic used below for determining coldness is based on
@@ -267,8 +268,6 @@ bool ProfileSummaryInfo::isFunctionEntryCold(const Function *F) {
267
268
268
269
// / Compute the hot and cold thresholds.
269
270
void ProfileSummaryInfo::computeThresholds () {
270
- if (!computeSummary ())
271
- return ;
272
271
auto &DetailedSummary = Summary->getDetailedSummary ();
273
272
auto &HotEntry =
274
273
getEntryForPercentile (DetailedSummary, ProfileSummaryCutoffHot);
@@ -289,7 +288,7 @@ void ProfileSummaryInfo::computeThresholds() {
289
288
}
290
289
291
290
Optional<uint64_t > ProfileSummaryInfo::computeThreshold (int PercentileCutoff) {
292
- if (!computeSummary ())
291
+ if (!hasProfileSummary ())
293
292
return None;
294
293
auto iter = ThresholdCache.find (PercentileCutoff);
295
294
if (iter != ThresholdCache.end ()) {
@@ -304,26 +303,18 @@ Optional<uint64_t> ProfileSummaryInfo::computeThreshold(int PercentileCutoff) {
304
303
}
305
304
306
305
bool ProfileSummaryInfo::hasHugeWorkingSetSize () {
307
- if (!HasHugeWorkingSetSize)
308
- computeThresholds ();
309
306
return HasHugeWorkingSetSize && HasHugeWorkingSetSize.getValue ();
310
307
}
311
308
312
309
bool ProfileSummaryInfo::hasLargeWorkingSetSize () {
313
- if (!HasLargeWorkingSetSize)
314
- computeThresholds ();
315
310
return HasLargeWorkingSetSize && HasLargeWorkingSetSize.getValue ();
316
311
}
317
312
318
313
bool ProfileSummaryInfo::isHotCount (uint64_t C) {
319
- if (!HotCountThreshold)
320
- computeThresholds ();
321
314
return HotCountThreshold && C >= HotCountThreshold.getValue ();
322
315
}
323
316
324
317
bool ProfileSummaryInfo::isColdCount (uint64_t C) {
325
- if (!ColdCountThreshold)
326
- computeThresholds ();
327
318
return ColdCountThreshold && C <= ColdCountThreshold.getValue ();
328
319
}
329
320
@@ -346,14 +337,10 @@ bool ProfileSummaryInfo::isColdCountNthPercentile(int PercentileCutoff, uint64_t
346
337
}
347
338
348
339
uint64_t ProfileSummaryInfo::getOrCompHotCountThreshold () {
349
- if (!HotCountThreshold)
350
- computeThresholds ();
351
340
return HotCountThreshold ? HotCountThreshold.getValue () : UINT64_MAX;
352
341
}
353
342
354
343
uint64_t ProfileSummaryInfo::getOrCompColdCountThreshold () {
355
- if (!ColdCountThreshold)
356
- computeThresholds ();
357
344
return ColdCountThreshold ? ColdCountThreshold.getValue () : 0 ;
358
345
}
359
346
0 commit comments