1 //===- ProfileSummaryInfoTest.cpp - ProfileSummaryInfo unit tests ---------===//
3 // 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
7 //===----------------------------------------------------------------------===//
9 #include "llvm/Analysis/ProfileSummaryInfo.h"
10 #include "llvm/Analysis/BlockFrequencyInfo.h"
11 #include "llvm/Analysis/BranchProbabilityInfo.h"
12 #include "llvm/Analysis/LoopInfo.h"
13 #include "llvm/AsmParser/Parser.h"
14 #include "llvm/IR/BasicBlock.h"
15 #include "llvm/IR/Dominators.h"
16 #include "llvm/IR/Function.h"
17 #include "llvm/IR/LLVMContext.h"
18 #include "llvm/IR/MDBuilder.h"
19 #include "llvm/IR/Module.h"
20 #include "llvm/Support/CommandLine.h"
21 #include "llvm/Support/DataTypes.h"
22 #include "llvm/Support/FormatVariadic.h"
23 #include "llvm/Support/SourceMgr.h"
24 #include "llvm/Support/raw_ostream.h"
25 #include "gtest/gtest.h"
27 extern llvm::cl::opt
<bool> ScalePartialSampleProfileWorkingSetSize
;
32 class ProfileSummaryInfoTest
: public testing::Test
{
35 std::unique_ptr
<BranchProbabilityInfo
> BPI
;
36 std::unique_ptr
<DominatorTree
> DT
;
37 std::unique_ptr
<LoopInfo
> LI
;
39 ProfileSummaryInfo
buildPSI(Module
*M
) {
40 return ProfileSummaryInfo(*M
);
42 BlockFrequencyInfo
buildBFI(Function
&F
) {
43 DT
.reset(new DominatorTree(F
));
44 LI
.reset(new LoopInfo(*DT
));
45 BPI
.reset(new BranchProbabilityInfo(F
, *LI
));
46 return BlockFrequencyInfo(F
, *BPI
, *LI
);
48 std::unique_ptr
<Module
> makeLLVMModule(const char *ProfKind
= nullptr,
49 uint64_t NumCounts
= 3,
50 uint64_t IsPartialProfile
= 0,
51 double PartialProfileRatio
= 0.0,
52 uint64_t HotNumCounts
= 3,
53 uint64_t ColdNumCounts
= 10) {
54 const char *ModuleString
=
55 "define i32 @g(i32 %x) !prof !21 {{\n"
58 "define i32 @h(i32 %x) !prof !22 {{\n"
61 "define i32 @f(i32 %x) !prof !20 {{\n"
63 " %y1 = icmp eq i32 %x, 0 \n"
64 " br i1 %y1, label %bb1, label %bb2, !prof !23 \n"
66 " %z1 = call i32 @g(i32 %x)\n"
69 " %z2 = call i32 @h(i32 %x)\n"
72 " %y2 = phi i32 [0, %bb1], [1, %bb2] \n"
75 "define i32 @l(i32 %x) {{\n"
77 " %y1 = icmp eq i32 %x, 0 \n"
78 " br i1 %y1, label %bb1, label %bb2, !prof !23 \n"
80 " %z1 = call i32 @g(i32 %x)\n"
83 " %z2 = call i32 @h(i32 %x)\n"
86 " %y2 = phi i32 [0, %bb1], [1, %bb2] \n"
89 "!20 = !{{!\"function_entry_count\", i64 400}\n"
90 "!21 = !{{!\"function_entry_count\", i64 1}\n"
91 "!22 = !{{!\"function_entry_count\", i64 100}\n"
92 "!23 = !{{!\"branch_weights\", i32 64, i32 4}\n"
94 const char *SummaryString
=
95 "!llvm.module.flags = !{{!1}\n"
96 "!1 = !{{i32 1, !\"ProfileSummary\", !2}\n"
97 "!2 = !{{!3, !4, !5, !6, !7, !8, !9, !10, !11, !12}\n"
98 "!3 = !{{!\"ProfileFormat\", !\"{0}\"}\n"
99 "!4 = !{{!\"TotalCount\", i64 10000}\n"
100 "!5 = !{{!\"MaxCount\", i64 10}\n"
101 "!6 = !{{!\"MaxInternalCount\", i64 1}\n"
102 "!7 = !{{!\"MaxFunctionCount\", i64 1000}\n"
103 "!8 = !{{!\"NumCounts\", i64 {1}}\n"
104 "!9 = !{{!\"NumFunctions\", i64 3}\n"
105 "!10 = !{{!\"IsPartialProfile\", i64 {2}}\n"
106 "!11 = !{{!\"PartialProfileRatio\", double {3}}\n"
107 "!12 = !{{!\"DetailedSummary\", !13}\n"
108 "!13 = !{{!14, !15, !16}\n"
109 "!14 = !{{i32 10000, i64 1000, i32 1}\n"
110 "!15 = !{{i32 990000, i64 300, i32 {4}}\n"
111 "!16 = !{{i32 999999, i64 5, i32 {5}}\n";
115 formatv(SummaryString
, ProfKind
, NumCounts
, IsPartialProfile
,
116 PartialProfileRatio
, HotNumCounts
, ColdNumCounts
)
118 return parseAssemblyString(formatv(ModuleString
, Summary
).str(), Err
, C
);
120 return parseAssemblyString(formatv(ModuleString
, "").str(), Err
, C
);
124 TEST_F(ProfileSummaryInfoTest
, TestNoProfile
) {
125 auto M
= makeLLVMModule(/*ProfKind=*/nullptr);
126 Function
*F
= M
->getFunction("f");
128 ProfileSummaryInfo PSI
= buildPSI(M
.get());
129 EXPECT_FALSE(PSI
.hasProfileSummary());
130 EXPECT_FALSE(PSI
.hasSampleProfile());
131 EXPECT_FALSE(PSI
.hasInstrumentationProfile());
132 // In the absence of profiles, is{Hot|Cold}X methods should always return
134 EXPECT_FALSE(PSI
.isHotCount(1000));
135 EXPECT_FALSE(PSI
.isHotCount(0));
136 EXPECT_FALSE(PSI
.isColdCount(1000));
137 EXPECT_FALSE(PSI
.isColdCount(0));
139 EXPECT_FALSE(PSI
.isFunctionEntryHot(F
));
140 EXPECT_FALSE(PSI
.isFunctionEntryCold(F
));
142 BasicBlock
&BB0
= F
->getEntryBlock();
143 BasicBlock
*BB1
= BB0
.getTerminator()->getSuccessor(0);
145 BlockFrequencyInfo BFI
= buildBFI(*F
);
146 EXPECT_FALSE(PSI
.isHotBlock(&BB0
, &BFI
));
147 EXPECT_FALSE(PSI
.isColdBlock(&BB0
, &BFI
));
149 CallBase
&CS1
= cast
<CallBase
>(*BB1
->getFirstNonPHI());
150 EXPECT_FALSE(PSI
.isHotCallSite(CS1
, &BFI
));
151 EXPECT_FALSE(PSI
.isColdCallSite(CS1
, &BFI
));
153 TEST_F(ProfileSummaryInfoTest
, TestCommon
) {
154 auto M
= makeLLVMModule("InstrProf");
155 Function
*F
= M
->getFunction("f");
156 Function
*G
= M
->getFunction("g");
157 Function
*H
= M
->getFunction("h");
159 ProfileSummaryInfo PSI
= buildPSI(M
.get());
160 EXPECT_TRUE(PSI
.hasProfileSummary());
161 EXPECT_TRUE(PSI
.isHotCount(400));
162 EXPECT_TRUE(PSI
.isColdCount(2));
163 EXPECT_FALSE(PSI
.isColdCount(100));
164 EXPECT_FALSE(PSI
.isHotCount(100));
166 EXPECT_TRUE(PSI
.isHotCountNthPercentile(990000, 400));
167 EXPECT_FALSE(PSI
.isHotCountNthPercentile(990000, 100));
168 EXPECT_FALSE(PSI
.isHotCountNthPercentile(990000, 2));
170 EXPECT_FALSE(PSI
.isColdCountNthPercentile(990000, 400));
171 EXPECT_TRUE(PSI
.isColdCountNthPercentile(990000, 100));
172 EXPECT_TRUE(PSI
.isColdCountNthPercentile(990000, 2));
174 EXPECT_TRUE(PSI
.isHotCountNthPercentile(999999, 400));
175 EXPECT_TRUE(PSI
.isHotCountNthPercentile(999999, 100));
176 EXPECT_FALSE(PSI
.isHotCountNthPercentile(999999, 2));
178 EXPECT_FALSE(PSI
.isColdCountNthPercentile(999999, 400));
179 EXPECT_FALSE(PSI
.isColdCountNthPercentile(999999, 100));
180 EXPECT_TRUE(PSI
.isColdCountNthPercentile(999999, 2));
182 EXPECT_FALSE(PSI
.isHotCountNthPercentile(10000, 400));
183 EXPECT_FALSE(PSI
.isHotCountNthPercentile(10000, 100));
184 EXPECT_FALSE(PSI
.isHotCountNthPercentile(10000, 2));
186 EXPECT_TRUE(PSI
.isColdCountNthPercentile(10000, 400));
187 EXPECT_TRUE(PSI
.isColdCountNthPercentile(10000, 100));
188 EXPECT_TRUE(PSI
.isColdCountNthPercentile(10000, 2));
190 EXPECT_TRUE(PSI
.isFunctionEntryHot(F
));
191 EXPECT_FALSE(PSI
.isFunctionEntryHot(G
));
192 EXPECT_FALSE(PSI
.isFunctionEntryHot(H
));
195 TEST_F(ProfileSummaryInfoTest
, InstrProf
) {
196 auto M
= makeLLVMModule("InstrProf");
197 Function
*F
= M
->getFunction("f");
198 ProfileSummaryInfo PSI
= buildPSI(M
.get());
199 EXPECT_TRUE(PSI
.hasProfileSummary());
200 EXPECT_TRUE(PSI
.hasInstrumentationProfile());
202 BasicBlock
&BB0
= F
->getEntryBlock();
203 BasicBlock
*BB1
= BB0
.getTerminator()->getSuccessor(0);
204 BasicBlock
*BB2
= BB0
.getTerminator()->getSuccessor(1);
205 BasicBlock
*BB3
= BB1
->getSingleSuccessor();
207 BlockFrequencyInfo BFI
= buildBFI(*F
);
208 EXPECT_TRUE(PSI
.isHotBlock(&BB0
, &BFI
));
209 EXPECT_TRUE(PSI
.isHotBlock(BB1
, &BFI
));
210 EXPECT_FALSE(PSI
.isHotBlock(BB2
, &BFI
));
211 EXPECT_TRUE(PSI
.isHotBlock(BB3
, &BFI
));
213 EXPECT_TRUE(PSI
.isHotBlockNthPercentile(990000, &BB0
, &BFI
));
214 EXPECT_TRUE(PSI
.isHotBlockNthPercentile(990000, BB1
, &BFI
));
215 EXPECT_FALSE(PSI
.isHotBlockNthPercentile(990000, BB2
, &BFI
));
216 EXPECT_TRUE(PSI
.isHotBlockNthPercentile(990000, BB3
, &BFI
));
218 EXPECT_FALSE(PSI
.isColdBlockNthPercentile(990000, &BB0
, &BFI
));
219 EXPECT_FALSE(PSI
.isColdBlockNthPercentile(990000, BB1
, &BFI
));
220 EXPECT_TRUE(PSI
.isColdBlockNthPercentile(990000, BB2
, &BFI
));
221 EXPECT_FALSE(PSI
.isColdBlockNthPercentile(990000, BB3
, &BFI
));
223 EXPECT_TRUE(PSI
.isHotBlockNthPercentile(999900, &BB0
, &BFI
));
224 EXPECT_TRUE(PSI
.isHotBlockNthPercentile(999900, BB1
, &BFI
));
225 EXPECT_TRUE(PSI
.isHotBlockNthPercentile(999900, BB2
, &BFI
));
226 EXPECT_TRUE(PSI
.isHotBlockNthPercentile(999900, BB3
, &BFI
));
228 EXPECT_FALSE(PSI
.isColdBlockNthPercentile(999900, &BB0
, &BFI
));
229 EXPECT_FALSE(PSI
.isColdBlockNthPercentile(999900, BB1
, &BFI
));
230 EXPECT_FALSE(PSI
.isColdBlockNthPercentile(999900, BB2
, &BFI
));
231 EXPECT_FALSE(PSI
.isColdBlockNthPercentile(999900, BB3
, &BFI
));
233 EXPECT_FALSE(PSI
.isHotBlockNthPercentile(10000, &BB0
, &BFI
));
234 EXPECT_FALSE(PSI
.isHotBlockNthPercentile(10000, BB1
, &BFI
));
235 EXPECT_FALSE(PSI
.isHotBlockNthPercentile(10000, BB2
, &BFI
));
236 EXPECT_FALSE(PSI
.isHotBlockNthPercentile(10000, BB3
, &BFI
));
238 EXPECT_TRUE(PSI
.isColdBlockNthPercentile(10000, &BB0
, &BFI
));
239 EXPECT_TRUE(PSI
.isColdBlockNthPercentile(10000, BB1
, &BFI
));
240 EXPECT_TRUE(PSI
.isColdBlockNthPercentile(10000, BB2
, &BFI
));
241 EXPECT_TRUE(PSI
.isColdBlockNthPercentile(10000, BB3
, &BFI
));
243 CallBase
&CS1
= cast
<CallBase
>(*BB1
->getFirstNonPHI());
244 auto *CI2
= BB2
->getFirstNonPHI();
245 CallBase
&CS2
= cast
<CallBase
>(*CI2
);
247 EXPECT_TRUE(PSI
.isHotCallSite(CS1
, &BFI
));
248 EXPECT_FALSE(PSI
.isHotCallSite(CS2
, &BFI
));
250 // Test that adding an MD_prof metadata with a hot count on CS2 does not
251 // change its hotness as it has no effect in instrumented profiling.
252 MDBuilder
MDB(M
->getContext());
253 CI2
->setMetadata(llvm::LLVMContext::MD_prof
, MDB
.createBranchWeights({400}));
254 EXPECT_FALSE(PSI
.isHotCallSite(CS2
, &BFI
));
256 EXPECT_TRUE(PSI
.isFunctionHotInCallGraphNthPercentile(990000, F
, BFI
));
257 EXPECT_FALSE(PSI
.isFunctionColdInCallGraphNthPercentile(990000, F
, BFI
));
258 EXPECT_FALSE(PSI
.isFunctionHotInCallGraphNthPercentile(10000, F
, BFI
));
259 EXPECT_TRUE(PSI
.isFunctionColdInCallGraphNthPercentile(10000, F
, BFI
));
262 TEST_F(ProfileSummaryInfoTest
, InstrProfNoFuncEntryCount
) {
263 auto M
= makeLLVMModule("InstrProf");
264 Function
*F
= M
->getFunction("l");
265 ProfileSummaryInfo PSI
= buildPSI(M
.get());
266 EXPECT_TRUE(PSI
.hasProfileSummary());
267 EXPECT_TRUE(PSI
.hasInstrumentationProfile());
269 BasicBlock
&BB0
= F
->getEntryBlock();
270 BasicBlock
*BB1
= BB0
.getTerminator()->getSuccessor(0);
271 BasicBlock
*BB2
= BB0
.getTerminator()->getSuccessor(1);
272 BasicBlock
*BB3
= BB1
->getSingleSuccessor();
274 BlockFrequencyInfo BFI
= buildBFI(*F
);
276 // Without the entry count, all should return false.
277 EXPECT_FALSE(PSI
.isHotBlockNthPercentile(990000, &BB0
, &BFI
));
278 EXPECT_FALSE(PSI
.isHotBlockNthPercentile(990000, BB1
, &BFI
));
279 EXPECT_FALSE(PSI
.isHotBlockNthPercentile(990000, BB2
, &BFI
));
280 EXPECT_FALSE(PSI
.isHotBlockNthPercentile(990000, BB3
, &BFI
));
281 EXPECT_FALSE(PSI
.isColdBlockNthPercentile(990000, &BB0
, &BFI
));
282 EXPECT_FALSE(PSI
.isColdBlockNthPercentile(990000, BB1
, &BFI
));
283 EXPECT_FALSE(PSI
.isColdBlockNthPercentile(990000, BB2
, &BFI
));
284 EXPECT_FALSE(PSI
.isColdBlockNthPercentile(990000, BB3
, &BFI
));
286 EXPECT_FALSE(PSI
.isFunctionHotInCallGraphNthPercentile(990000, F
, BFI
));
287 EXPECT_FALSE(PSI
.isFunctionColdInCallGraphNthPercentile(990000, F
, BFI
));
290 TEST_F(ProfileSummaryInfoTest
, SampleProf
) {
291 auto M
= makeLLVMModule("SampleProfile");
292 Function
*F
= M
->getFunction("f");
293 ProfileSummaryInfo PSI
= buildPSI(M
.get());
294 EXPECT_TRUE(PSI
.hasProfileSummary());
295 EXPECT_TRUE(PSI
.hasSampleProfile());
296 EXPECT_FALSE(PSI
.hasPartialSampleProfile());
298 BasicBlock
&BB0
= F
->getEntryBlock();
299 BasicBlock
*BB1
= BB0
.getTerminator()->getSuccessor(0);
300 BasicBlock
*BB2
= BB0
.getTerminator()->getSuccessor(1);
301 BasicBlock
*BB3
= BB1
->getSingleSuccessor();
303 BlockFrequencyInfo BFI
= buildBFI(*F
);
304 EXPECT_TRUE(PSI
.isHotBlock(&BB0
, &BFI
));
305 EXPECT_TRUE(PSI
.isHotBlock(BB1
, &BFI
));
306 EXPECT_FALSE(PSI
.isHotBlock(BB2
, &BFI
));
307 EXPECT_TRUE(PSI
.isHotBlock(BB3
, &BFI
));
309 EXPECT_TRUE(PSI
.isHotBlockNthPercentile(990000, &BB0
, &BFI
));
310 EXPECT_TRUE(PSI
.isHotBlockNthPercentile(990000, BB1
, &BFI
));
311 EXPECT_FALSE(PSI
.isHotBlockNthPercentile(990000, BB2
, &BFI
));
312 EXPECT_TRUE(PSI
.isHotBlockNthPercentile(990000, BB3
, &BFI
));
314 EXPECT_FALSE(PSI
.isColdBlockNthPercentile(990000, &BB0
, &BFI
));
315 EXPECT_FALSE(PSI
.isColdBlockNthPercentile(990000, BB1
, &BFI
));
316 EXPECT_TRUE(PSI
.isColdBlockNthPercentile(990000, BB2
, &BFI
));
317 EXPECT_FALSE(PSI
.isColdBlockNthPercentile(990000, BB3
, &BFI
));
319 EXPECT_TRUE(PSI
.isHotBlockNthPercentile(999900, &BB0
, &BFI
));
320 EXPECT_TRUE(PSI
.isHotBlockNthPercentile(999900, BB1
, &BFI
));
321 EXPECT_TRUE(PSI
.isHotBlockNthPercentile(999900, BB2
, &BFI
));
322 EXPECT_TRUE(PSI
.isHotBlockNthPercentile(999900, BB3
, &BFI
));
324 EXPECT_FALSE(PSI
.isColdBlockNthPercentile(999900, &BB0
, &BFI
));
325 EXPECT_FALSE(PSI
.isColdBlockNthPercentile(999900, BB1
, &BFI
));
326 EXPECT_FALSE(PSI
.isColdBlockNthPercentile(999900, BB2
, &BFI
));
327 EXPECT_FALSE(PSI
.isColdBlockNthPercentile(999900, BB3
, &BFI
));
329 EXPECT_FALSE(PSI
.isHotBlockNthPercentile(10000, &BB0
, &BFI
));
330 EXPECT_FALSE(PSI
.isHotBlockNthPercentile(10000, BB1
, &BFI
));
331 EXPECT_FALSE(PSI
.isHotBlockNthPercentile(10000, BB2
, &BFI
));
332 EXPECT_FALSE(PSI
.isHotBlockNthPercentile(10000, BB3
, &BFI
));
334 EXPECT_TRUE(PSI
.isColdBlockNthPercentile(10000, &BB0
, &BFI
));
335 EXPECT_TRUE(PSI
.isColdBlockNthPercentile(10000, BB1
, &BFI
));
336 EXPECT_TRUE(PSI
.isColdBlockNthPercentile(10000, BB2
, &BFI
));
337 EXPECT_TRUE(PSI
.isColdBlockNthPercentile(10000, BB3
, &BFI
));
339 CallBase
&CS1
= cast
<CallBase
>(*BB1
->getFirstNonPHI());
340 auto *CI2
= BB2
->getFirstNonPHI();
341 // Manually attach branch weights metadata to the call instruction.
342 SmallVector
<uint32_t, 1> Weights
;
343 Weights
.push_back(1000);
344 MDBuilder
MDB(M
->getContext());
345 CI2
->setMetadata(LLVMContext::MD_prof
, MDB
.createBranchWeights(Weights
));
346 CallBase
&CS2
= cast
<CallBase
>(*CI2
);
348 EXPECT_FALSE(PSI
.isHotCallSite(CS1
, &BFI
));
349 EXPECT_TRUE(PSI
.isHotCallSite(CS2
, &BFI
));
351 // Test that CS2 is considered hot when it gets an MD_prof metadata with
352 // weights that exceed the hot count threshold.
353 CI2
->setMetadata(llvm::LLVMContext::MD_prof
, MDB
.createBranchWeights({400}));
354 EXPECT_TRUE(PSI
.isHotCallSite(CS2
, &BFI
));
356 EXPECT_TRUE(PSI
.isFunctionHotInCallGraphNthPercentile(990000, F
, BFI
));
357 EXPECT_FALSE(PSI
.isFunctionColdInCallGraphNthPercentile(990000, F
, BFI
));
358 EXPECT_FALSE(PSI
.isFunctionHotInCallGraphNthPercentile(10000, F
, BFI
));
359 EXPECT_TRUE(PSI
.isFunctionColdInCallGraphNthPercentile(10000, F
, BFI
));
362 TEST_F(ProfileSummaryInfoTest
, SampleProfNoFuncEntryCount
) {
363 auto M
= makeLLVMModule("SampleProfile");
364 Function
*F
= M
->getFunction("l");
365 ProfileSummaryInfo PSI
= buildPSI(M
.get());
366 EXPECT_TRUE(PSI
.hasProfileSummary());
367 EXPECT_TRUE(PSI
.hasSampleProfile());
369 BasicBlock
&BB0
= F
->getEntryBlock();
370 BasicBlock
*BB1
= BB0
.getTerminator()->getSuccessor(0);
371 BasicBlock
*BB2
= BB0
.getTerminator()->getSuccessor(1);
372 BasicBlock
*BB3
= BB1
->getSingleSuccessor();
374 BlockFrequencyInfo BFI
= buildBFI(*F
);
376 // Without the entry count, all should return false.
377 EXPECT_FALSE(PSI
.isHotBlockNthPercentile(990000, &BB0
, &BFI
));
378 EXPECT_FALSE(PSI
.isHotBlockNthPercentile(990000, BB1
, &BFI
));
379 EXPECT_FALSE(PSI
.isHotBlockNthPercentile(990000, BB2
, &BFI
));
380 EXPECT_FALSE(PSI
.isHotBlockNthPercentile(990000, BB3
, &BFI
));
381 EXPECT_FALSE(PSI
.isColdBlockNthPercentile(990000, &BB0
, &BFI
));
382 EXPECT_FALSE(PSI
.isColdBlockNthPercentile(990000, BB1
, &BFI
));
383 EXPECT_FALSE(PSI
.isColdBlockNthPercentile(990000, BB2
, &BFI
));
384 EXPECT_FALSE(PSI
.isColdBlockNthPercentile(990000, BB3
, &BFI
));
386 EXPECT_FALSE(PSI
.isFunctionHotInCallGraphNthPercentile(990000, F
, BFI
));
387 EXPECT_FALSE(PSI
.isFunctionColdInCallGraphNthPercentile(990000, F
, BFI
));
390 TEST_F(ProfileSummaryInfoTest
, PartialSampleProfWorkingSetSize
) {
391 ScalePartialSampleProfileWorkingSetSize
.setValue(true);
393 // With PartialProfileRatio unset (zero.)
394 auto M1
= makeLLVMModule("SampleProfile", /*NumCounts*/ 3,
395 /*IsPartialProfile*/ 1,
396 /*PartialProfileRatio*/ 0.0,
397 /*HotNumCounts*/ 3, /*ColdNumCounts*/ 10);
398 ProfileSummaryInfo PSI1
= buildPSI(M1
.get());
399 EXPECT_TRUE(PSI1
.hasProfileSummary());
400 EXPECT_TRUE(PSI1
.hasSampleProfile());
401 EXPECT_TRUE(PSI1
.hasPartialSampleProfile());
402 EXPECT_FALSE(PSI1
.hasHugeWorkingSetSize());
403 EXPECT_FALSE(PSI1
.hasLargeWorkingSetSize());
405 // With PartialProfileRatio set (non-zero) and a small working set size.
406 auto M2
= makeLLVMModule("SampleProfile", /*NumCounts*/ 27493235,
407 /*IsPartialProfile*/ 1,
408 /*PartialProfileRatio*/ 0.00000012,
409 /*HotNumCounts*/ 3102082,
410 /*ColdNumCounts*/ 18306149);
411 ProfileSummaryInfo PSI2
= buildPSI(M2
.get());
412 EXPECT_TRUE(PSI2
.hasProfileSummary());
413 EXPECT_TRUE(PSI2
.hasSampleProfile());
414 EXPECT_TRUE(PSI2
.hasPartialSampleProfile());
415 EXPECT_FALSE(PSI2
.hasHugeWorkingSetSize());
416 EXPECT_FALSE(PSI2
.hasLargeWorkingSetSize());
418 // With PartialProfileRatio is set (non-zero) and a large working set size.
419 auto M3
= makeLLVMModule("SampleProfile", /*NumCounts*/ 27493235,
420 /*IsPartialProfile*/ 1,
421 /*PartialProfileRatio*/ 0.9,
422 /*HotNumCounts*/ 3102082,
423 /*ColdNumCounts*/ 18306149);
424 ProfileSummaryInfo PSI3
= buildPSI(M3
.get());
425 EXPECT_TRUE(PSI3
.hasProfileSummary());
426 EXPECT_TRUE(PSI3
.hasSampleProfile());
427 EXPECT_TRUE(PSI3
.hasPartialSampleProfile());
428 EXPECT_TRUE(PSI3
.hasHugeWorkingSetSize());
429 EXPECT_TRUE(PSI3
.hasLargeWorkingSetSize());
432 } // end anonymous namespace
433 } // end namespace llvm