From fb601ea161b439a56b2dedd119793232602ac0ee Mon Sep 17 00:00:00 2001 From: Hiroshi Yamauchi Date: Wed, 4 Mar 2020 10:33:23 -0800 Subject: [PATCH] [PSI] Add tests for is(Hot|Cold)FunctionInCallGraphNthPercentile. Summary: Follow up on D75283. Also remove the test code that was moved to another test and was to be removed. Reviewers: davidxl Subscribers: eraman, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D75630 --- unittests/Analysis/ProfileSummaryInfoTest.cpp | 34 ++++++++----------- 1 file changed, 15 insertions(+), 19 deletions(-) diff --git a/unittests/Analysis/ProfileSummaryInfoTest.cpp b/unittests/Analysis/ProfileSummaryInfoTest.cpp index 6c4e42aa7e0..ea354a9ede3 100644 --- a/unittests/Analysis/ProfileSummaryInfoTest.cpp +++ b/unittests/Analysis/ProfileSummaryInfoTest.cpp @@ -240,6 +240,11 @@ TEST_F(ProfileSummaryInfoTest, InstrProf) { MDBuilder MDB(M->getContext()); CI2->setMetadata(llvm::LLVMContext::MD_prof, MDB.createBranchWeights({400})); EXPECT_FALSE(PSI.isHotCallSite(CS2, &BFI)); + + EXPECT_TRUE(PSI.isFunctionHotInCallGraphNthPercentile(990000, F, BFI)); + EXPECT_FALSE(PSI.isFunctionColdInCallGraphNthPercentile(990000, F, BFI)); + EXPECT_FALSE(PSI.isFunctionHotInCallGraphNthPercentile(10000, F, BFI)); + EXPECT_TRUE(PSI.isFunctionColdInCallGraphNthPercentile(10000, F, BFI)); } TEST_F(ProfileSummaryInfoTest, InstrProfNoFuncEntryCount) { @@ -265,6 +270,9 @@ TEST_F(ProfileSummaryInfoTest, InstrProfNoFuncEntryCount) { EXPECT_FALSE(PSI.isColdBlockNthPercentile(990000, BB1, &BFI)); EXPECT_FALSE(PSI.isColdBlockNthPercentile(990000, BB2, &BFI)); EXPECT_FALSE(PSI.isColdBlockNthPercentile(990000, BB3, &BFI)); + + EXPECT_FALSE(PSI.isFunctionHotInCallGraphNthPercentile(990000, F, BFI)); + EXPECT_FALSE(PSI.isFunctionColdInCallGraphNthPercentile(990000, F, BFI)); } TEST_F(ProfileSummaryInfoTest, SampleProf) { @@ -332,25 +340,10 @@ TEST_F(ProfileSummaryInfoTest, SampleProf) { CI2->setMetadata(llvm::LLVMContext::MD_prof, MDB.createBranchWeights({400})); EXPECT_TRUE(PSI.isHotCallSite(CS2, &BFI)); - { - Function *F = M->getFunction("l"); - BlockFrequencyInfo BFI = buildBFI(*F); - BasicBlock &BB0 = F->getEntryBlock(); - BasicBlock *BB1 = BB0.getTerminator()->getSuccessor(0); - BasicBlock *BB2 = BB0.getTerminator()->getSuccessor(1); - BasicBlock *BB3 = BB1->getSingleSuccessor(); - - // Without the entry count, all should return false. - EXPECT_FALSE(PSI.isHotBlockNthPercentile(990000, &BB0, &BFI)); - EXPECT_FALSE(PSI.isHotBlockNthPercentile(990000, BB1, &BFI)); - EXPECT_FALSE(PSI.isHotBlockNthPercentile(990000, BB2, &BFI)); - EXPECT_FALSE(PSI.isHotBlockNthPercentile(990000, BB3, &BFI)); - - EXPECT_FALSE(PSI.isColdBlockNthPercentile(990000, &BB0, &BFI)); - EXPECT_FALSE(PSI.isColdBlockNthPercentile(990000, BB1, &BFI)); - EXPECT_FALSE(PSI.isColdBlockNthPercentile(990000, BB2, &BFI)); - EXPECT_FALSE(PSI.isColdBlockNthPercentile(990000, BB3, &BFI)); - } + EXPECT_TRUE(PSI.isFunctionHotInCallGraphNthPercentile(990000, F, BFI)); + EXPECT_FALSE(PSI.isFunctionColdInCallGraphNthPercentile(990000, F, BFI)); + EXPECT_FALSE(PSI.isFunctionHotInCallGraphNthPercentile(10000, F, BFI)); + EXPECT_TRUE(PSI.isFunctionColdInCallGraphNthPercentile(10000, F, BFI)); } TEST_F(ProfileSummaryInfoTest, SampleProfNoFuncEntryCount) { @@ -376,6 +369,9 @@ TEST_F(ProfileSummaryInfoTest, SampleProfNoFuncEntryCount) { EXPECT_FALSE(PSI.isColdBlockNthPercentile(990000, BB1, &BFI)); EXPECT_FALSE(PSI.isColdBlockNthPercentile(990000, BB2, &BFI)); EXPECT_FALSE(PSI.isColdBlockNthPercentile(990000, BB3, &BFI)); + + EXPECT_FALSE(PSI.isFunctionHotInCallGraphNthPercentile(990000, F, BFI)); + EXPECT_FALSE(PSI.isFunctionColdInCallGraphNthPercentile(990000, F, BFI)); } } // end anonymous namespace