llvm.org GIT mirror llvm / 5dcdd41
Add value site truncation unit test git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@257153 91177308-0d34-0410-b5e6-96231b3b80d8 Xinliang David Li 3 years ago
1 changed file(s) with 56 addition(s) and 10 deletion(s). Raw diff Collapse all Expand all
289289 {uint64_t(callee4), 4}};
290290 Record11.addValueData(IPVK_IndirectCallTarget, 0, VD0, 4, nullptr);
291291
292 // No valeu profile data at the second site.
292 // No value profile data at the second site.
293293 Record11.addValueData(IPVK_IndirectCallTarget, 1, nullptr, 0, nullptr);
294294
295 InstrProfValueData VD2[] = {{uint64_t(callee1), 1},
296 {uint64_t(callee2), 2},
297 {uint64_t(callee3), 3}};
295 InstrProfValueData VD2[] = {
296 {uint64_t(callee1), 1}, {uint64_t(callee2), 2}, {uint64_t(callee3), 3}};
298297 Record11.addValueData(IPVK_IndirectCallTarget, 2, VD2, 3, nullptr);
299298
300299 InstrProfValueData VD3[] = {{uint64_t(callee1), 1}};
307306
308307 // A differnt record for the same caller.
309308 Record12.reserveSites(IPVK_IndirectCallTarget, 5);
310 InstrProfValueData VD02[] = {{uint64_t(callee2), 5},
311 {uint64_t(callee3), 3}};
309 InstrProfValueData VD02[] = {{uint64_t(callee2), 5}, {uint64_t(callee3), 3}};
312310 Record12.addValueData(IPVK_IndirectCallTarget, 0, VD02, 2, nullptr);
313311
314 // No valeu profile data at the second site.
312 // No value profile data at the second site.
315313 Record12.addValueData(IPVK_IndirectCallTarget, 1, nullptr, 0, nullptr);
316314
317 InstrProfValueData VD22[] = {{uint64_t(callee2), 1},
318 {uint64_t(callee3), 3},
319 {uint64_t(callee4), 4}};
315 InstrProfValueData VD22[] = {
316 {uint64_t(callee2), 1}, {uint64_t(callee3), 3}, {uint64_t(callee4), 4}};
320317 Record12.addValueData(IPVK_IndirectCallTarget, 2, VD22, 3, nullptr);
321318
322319 Record12.addValueData(IPVK_IndirectCallTarget, 3, nullptr, 0, nullptr);
433430 ReadRecord2.get().getValueForSite(IPVK_IndirectCallTarget, 0);
434431 ASSERT_EQ(StringRef("bar"), StringRef((const char *)VD[0].Value, 3));
435432 ASSERT_EQ(Max, VD[0].Count);
433 }
434
435 // This test tests that when there are too many values
436 // for a given site, the merged results are properly
437 // truncated.
438 TEST_F(InstrProfTest, get_icall_data_merge_site_trunc) {
439 static const char caller[] = "caller";
440
441 InstrProfRecord Record11(caller, 0x1234, {1, 2});
442 InstrProfRecord Record12(caller, 0x1234, {1, 2});
443
444 // 2 value sites.
445 Record11.reserveSites(IPVK_IndirectCallTarget, 2);
446 InstrProfValueData VD0[255];
447 for (int I = 0; I < 255; I++) {
448 VD0[I].Value = 2 * I;
449 VD0[I].Count = 2 * I + 1000;
450 }
451
452 Record11.addValueData(IPVK_IndirectCallTarget, 0, VD0, 255, nullptr);
453 Record11.addValueData(IPVK_IndirectCallTarget, 1, nullptr, 0, nullptr);
454
455 Record12.reserveSites(IPVK_IndirectCallTarget, 2);
456 InstrProfValueData VD1[255];
457 for (int I = 0; I < 255; I++) {
458 VD1[I].Value = 2 * I + 1;
459 VD1[I].Count = 2 * I + 1001;
460 }
461
462 Record12.addValueData(IPVK_IndirectCallTarget, 0, VD1, 255, nullptr);
463 Record12.addValueData(IPVK_IndirectCallTarget, 1, nullptr, 0, nullptr);
464
465 Writer.addRecord(std::move(Record11));
466 // Merge profile data.
467 Writer.addRecord(std::move(Record12));
468
469 auto Profile = Writer.writeBuffer();
470 readProfile(std::move(Profile));
471
472 ErrorOr R = Reader->getInstrProfRecord("caller", 0x1234);
473 ASSERT_TRUE(NoError(R.getError()));
474 std::unique_ptr VD(
475 R.get().getValueForSite(IPVK_IndirectCallTarget, 0));
476 ASSERT_EQ(2U, R.get().getNumValueSites(IPVK_IndirectCallTarget));
477 ASSERT_EQ(255U, R.get().getNumValueDataForSite(IPVK_IndirectCallTarget, 0));
478 for (int I = 0; I < 255; I++) {
479 ASSERT_EQ(VD[I].Value, 509 - I);
480 ASSERT_EQ(VD[I].Count, 1509 - I);
481 }
436482 }
437483
438484 // Synthesize runtime value profile data.