@@ -68,6 +68,25 @@ struct SparseInstrProfTest : public InstrProfTest {
68
68
void SetUp () override { Writer.setOutputSparse (true ); }
69
69
};
70
70
71
+ struct InstrProfReaderWriterTest
72
+ : public InstrProfTest,
73
+ public ::testing::WithParamInterface<
74
+ std::tuple<bool , uint64_t , llvm::endianness>> {
75
+ void SetUp () override { Writer.setOutputSparse (std::get<0 >(GetParam ())); }
76
+ void TearDown () override {
77
+ // Reset writer value profile data endianness after each test case. Note
78
+ // it's not necessary to reset reader value profile endianness for each test
79
+ // case. Each test case creates a new reader; at reader initialization time,
80
+ // it uses the endianness from hash table object (which is little by
81
+ // default).
82
+ Writer.setValueProfDataEndianness (llvm::endianness::little);
83
+ }
84
+
85
+ uint64_t getProfWeight () const { return std::get<1 >(GetParam ()); }
86
+
87
+ llvm::endianness getEndianness () const { return std::get<2 >(GetParam ()); }
88
+ };
89
+
71
90
struct MaybeSparseInstrProfTest : public InstrProfTest ,
72
91
public ::testing::WithParamInterface<bool > {
73
92
void SetUp () override { Writer.setOutputSparse (GetParam ()); }
@@ -640,7 +659,7 @@ static const char callee4[] = "callee4";
640
659
static const char callee5[] = " callee5" ;
641
660
static const char callee6[] = " callee6" ;
642
661
643
- TEST_P (MaybeSparseInstrProfTest, get_icall_data_read_write ) {
662
+ TEST_P (InstrProfReaderWriterTest, icall_data_read_write ) {
644
663
NamedInstrProfRecord Record1 (" caller" , 0x1234 , {1 , 2 });
645
664
646
665
// 4 value sites.
@@ -655,35 +674,51 @@ TEST_P(MaybeSparseInstrProfTest, get_icall_data_read_write) {
655
674
InstrProfValueData VD3[] = {{(uint64_t )callee1, 1 }};
656
675
Record1.addValueData (IPVK_IndirectCallTarget, 3 , VD3, 1 , nullptr );
657
676
658
- Writer.addRecord (std::move (Record1), Err);
677
+ Writer.addRecord (std::move (Record1), getProfWeight (), Err);
659
678
Writer.addRecord ({" callee1" , 0x1235 , {3 , 4 }}, Err);
660
679
Writer.addRecord ({" callee2" , 0x1235 , {3 , 4 }}, Err);
661
680
Writer.addRecord ({" callee3" , 0x1235 , {3 , 4 }}, Err);
681
+
682
+ // Set writer value prof data endianness.
683
+ Writer.setValueProfDataEndianness (getEndianness ());
684
+
662
685
auto Profile = Writer.writeBuffer ();
663
686
readProfile (std::move (Profile));
664
687
688
+ // Set reader value prof data endianness.
689
+ Reader->setValueProfDataEndianness (getEndianness ());
690
+
665
691
Expected<InstrProfRecord> R = Reader->getInstrProfRecord (" caller" , 0x1234 );
666
- EXPECT_THAT_ERROR (R.takeError (), Succeeded ());
692
+ ASSERT_THAT_ERROR (R.takeError (), Succeeded ());
667
693
ASSERT_EQ (4U , R->getNumValueSites (IPVK_IndirectCallTarget));
668
- ASSERT_EQ (3U , R->getNumValueDataForSite (IPVK_IndirectCallTarget, 0 ));
669
- ASSERT_EQ (0U , R->getNumValueDataForSite (IPVK_IndirectCallTarget, 1 ));
670
- ASSERT_EQ (2U , R->getNumValueDataForSite (IPVK_IndirectCallTarget, 2 ));
671
- ASSERT_EQ (1U , R->getNumValueDataForSite (IPVK_IndirectCallTarget, 3 ));
694
+ EXPECT_EQ (3U , R->getNumValueDataForSite (IPVK_IndirectCallTarget, 0 ));
695
+ EXPECT_EQ (0U , R->getNumValueDataForSite (IPVK_IndirectCallTarget, 1 ));
696
+ EXPECT_EQ (2U , R->getNumValueDataForSite (IPVK_IndirectCallTarget, 2 ));
697
+ EXPECT_EQ (1U , R->getNumValueDataForSite (IPVK_IndirectCallTarget, 3 ));
672
698
673
699
uint64_t TotalC;
674
700
std::unique_ptr<InstrProfValueData[]> VD =
675
701
R->getValueForSite (IPVK_IndirectCallTarget, 0 , &TotalC);
676
702
677
- ASSERT_EQ (3U , VD[0 ].Count );
678
- ASSERT_EQ (2U , VD[1 ].Count );
679
- ASSERT_EQ (1U , VD[2 ].Count );
680
- ASSERT_EQ (6U , TotalC);
703
+ EXPECT_EQ (3U * getProfWeight () , VD[0 ].Count );
704
+ EXPECT_EQ (2U * getProfWeight () , VD[1 ].Count );
705
+ EXPECT_EQ (1U * getProfWeight () , VD[2 ].Count );
706
+ EXPECT_EQ (6U * getProfWeight () , TotalC);
681
707
682
- ASSERT_EQ (StringRef ((const char *)VD[0 ].Value , 7 ), StringRef (" callee3" ));
683
- ASSERT_EQ (StringRef ((const char *)VD[1 ].Value , 7 ), StringRef (" callee2" ));
684
- ASSERT_EQ (StringRef ((const char *)VD[2 ].Value , 7 ), StringRef (" callee1" ));
708
+ EXPECT_EQ (StringRef ((const char *)VD[0 ].Value , 7 ), StringRef (" callee3" ));
709
+ EXPECT_EQ (StringRef ((const char *)VD[1 ].Value , 7 ), StringRef (" callee2" ));
710
+ EXPECT_EQ (StringRef ((const char *)VD[2 ].Value , 7 ), StringRef (" callee1" ));
685
711
}
686
712
713
+ INSTANTIATE_TEST_SUITE_P (
714
+ WeightAndEndiannessTest, InstrProfReaderWriterTest,
715
+ ::testing::Combine (
716
+ ::testing::Bool (), /* Sparse */
717
+ ::testing::Values(1U , 10U ), /* ProfWeight */
718
+ ::testing::Values(llvm::endianness::big,
719
+ llvm::endianness::little) /* Endianness */
720
+ ));
721
+
687
722
TEST_P (MaybeSparseInstrProfTest, annotate_vp_data) {
688
723
NamedInstrProfRecord Record (" caller" , 0x1234 , {1 , 2 });
689
724
Record.reserveSites (IPVK_IndirectCallTarget, 1 );
@@ -780,96 +815,6 @@ TEST_P(MaybeSparseInstrProfTest, annotate_vp_data) {
780
815
ASSERT_EQ (1U , ValueData[3 ].Count );
781
816
}
782
817
783
- TEST_P (MaybeSparseInstrProfTest, get_icall_data_read_write_with_weight) {
784
- NamedInstrProfRecord Record1 (" caller" , 0x1234 , {1 , 2 });
785
-
786
- // 4 value sites.
787
- Record1.reserveSites (IPVK_IndirectCallTarget, 4 );
788
- InstrProfValueData VD0[] = {
789
- {(uint64_t )callee1, 1 }, {(uint64_t )callee2, 2 }, {(uint64_t )callee3, 3 }};
790
- Record1.addValueData (IPVK_IndirectCallTarget, 0 , VD0, 3 , nullptr );
791
- // No value profile data at the second site.
792
- Record1.addValueData (IPVK_IndirectCallTarget, 1 , nullptr , 0 , nullptr );
793
- InstrProfValueData VD2[] = {{(uint64_t )callee1, 1 }, {(uint64_t )callee2, 2 }};
794
- Record1.addValueData (IPVK_IndirectCallTarget, 2 , VD2, 2 , nullptr );
795
- InstrProfValueData VD3[] = {{(uint64_t )callee1, 1 }};
796
- Record1.addValueData (IPVK_IndirectCallTarget, 3 , VD3, 1 , nullptr );
797
-
798
- Writer.addRecord (std::move (Record1), 10 , Err);
799
- Writer.addRecord ({" callee1" , 0x1235 , {3 , 4 }}, Err);
800
- Writer.addRecord ({" callee2" , 0x1235 , {3 , 4 }}, Err);
801
- Writer.addRecord ({" callee3" , 0x1235 , {3 , 4 }}, Err);
802
- auto Profile = Writer.writeBuffer ();
803
- readProfile (std::move (Profile));
804
-
805
- Expected<InstrProfRecord> R = Reader->getInstrProfRecord (" caller" , 0x1234 );
806
- EXPECT_THAT_ERROR (R.takeError (), Succeeded ());
807
- ASSERT_EQ (4U , R->getNumValueSites (IPVK_IndirectCallTarget));
808
- ASSERT_EQ (3U , R->getNumValueDataForSite (IPVK_IndirectCallTarget, 0 ));
809
- ASSERT_EQ (0U , R->getNumValueDataForSite (IPVK_IndirectCallTarget, 1 ));
810
- ASSERT_EQ (2U , R->getNumValueDataForSite (IPVK_IndirectCallTarget, 2 ));
811
- ASSERT_EQ (1U , R->getNumValueDataForSite (IPVK_IndirectCallTarget, 3 ));
812
-
813
- uint64_t TotalC;
814
- std::unique_ptr<InstrProfValueData[]> VD =
815
- R->getValueForSite (IPVK_IndirectCallTarget, 0 , &TotalC);
816
- ASSERT_EQ (30U , VD[0 ].Count );
817
- ASSERT_EQ (20U , VD[1 ].Count );
818
- ASSERT_EQ (10U , VD[2 ].Count );
819
- ASSERT_EQ (60U , TotalC);
820
-
821
- ASSERT_EQ (StringRef ((const char *)VD[0 ].Value , 7 ), StringRef (" callee3" ));
822
- ASSERT_EQ (StringRef ((const char *)VD[1 ].Value , 7 ), StringRef (" callee2" ));
823
- ASSERT_EQ (StringRef ((const char *)VD[2 ].Value , 7 ), StringRef (" callee1" ));
824
- }
825
-
826
- TEST_P (MaybeSparseInstrProfTest, get_icall_data_read_write_big_endian) {
827
- NamedInstrProfRecord Record1 (" caller" , 0x1234 , {1 , 2 });
828
-
829
- // 4 value sites.
830
- Record1.reserveSites (IPVK_IndirectCallTarget, 4 );
831
- InstrProfValueData VD0[] = {
832
- {(uint64_t )callee1, 1 }, {(uint64_t )callee2, 2 }, {(uint64_t )callee3, 3 }};
833
- Record1.addValueData (IPVK_IndirectCallTarget, 0 , VD0, 3 , nullptr );
834
- // No value profile data at the second site.
835
- Record1.addValueData (IPVK_IndirectCallTarget, 1 , nullptr , 0 , nullptr );
836
- InstrProfValueData VD2[] = {{(uint64_t )callee1, 1 }, {(uint64_t )callee2, 2 }};
837
- Record1.addValueData (IPVK_IndirectCallTarget, 2 , VD2, 2 , nullptr );
838
- InstrProfValueData VD3[] = {{(uint64_t )callee1, 1 }};
839
- Record1.addValueData (IPVK_IndirectCallTarget, 3 , VD3, 1 , nullptr );
840
-
841
- Writer.addRecord (std::move (Record1), Err);
842
- Writer.addRecord ({" callee1" , 0x1235 , {3 , 4 }}, Err);
843
- Writer.addRecord ({" callee2" , 0x1235 , {3 , 4 }}, Err);
844
- Writer.addRecord ({" callee3" , 0x1235 , {3 , 4 }}, Err);
845
-
846
- // Set big endian output.
847
- Writer.setValueProfDataEndianness (llvm::endianness::big);
848
-
849
- auto Profile = Writer.writeBuffer ();
850
- readProfile (std::move (Profile));
851
-
852
- // Set big endian input.
853
- Reader->setValueProfDataEndianness (llvm::endianness::big);
854
-
855
- Expected<InstrProfRecord> R = Reader->getInstrProfRecord (" caller" , 0x1234 );
856
- EXPECT_THAT_ERROR (R.takeError (), Succeeded ());
857
- ASSERT_EQ (4U , R->getNumValueSites (IPVK_IndirectCallTarget));
858
- ASSERT_EQ (3U , R->getNumValueDataForSite (IPVK_IndirectCallTarget, 0 ));
859
- ASSERT_EQ (0U , R->getNumValueDataForSite (IPVK_IndirectCallTarget, 1 ));
860
- ASSERT_EQ (2U , R->getNumValueDataForSite (IPVK_IndirectCallTarget, 2 ));
861
- ASSERT_EQ (1U , R->getNumValueDataForSite (IPVK_IndirectCallTarget, 3 ));
862
-
863
- std::unique_ptr<InstrProfValueData[]> VD =
864
- R->getValueForSite (IPVK_IndirectCallTarget, 0 );
865
- ASSERT_EQ (StringRef ((const char *)VD[0 ].Value , 7 ), StringRef (" callee3" ));
866
- ASSERT_EQ (StringRef ((const char *)VD[1 ].Value , 7 ), StringRef (" callee2" ));
867
- ASSERT_EQ (StringRef ((const char *)VD[2 ].Value , 7 ), StringRef (" callee1" ));
868
-
869
- // Restore little endian default:
870
- Writer.setValueProfDataEndianness (llvm::endianness::little);
871
- }
872
-
873
818
TEST_P (MaybeSparseInstrProfTest, get_icall_data_merge1) {
874
819
static const char caller[] = " caller" ;
875
820
NamedInstrProfRecord Record11 (caller, 0x1234 , {1 , 2 });
0 commit comments