Skip to content

Commit 8f7d30a

Browse files
[ProfileData] Sink the length checks (llvm#95604)
The new API getValueArrayForSite returns ArrayRef<InstrProfValueData>, packaging the array length and contents together. This patch sinks the array length checks just before we check the contents. This way, we check both the array length and contents immediately after calling getValueArrayForSite.
1 parent 76b64ae commit 8f7d30a

File tree

1 file changed

+16
-14
lines changed

1 file changed

+16
-14
lines changed

llvm/unittests/ProfileData/InstrProfTest.cpp

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -854,20 +854,15 @@ TEST_P(InstrProfReaderWriterTest, icall_and_vtable_data_read_write) {
854854
// Test the number of instrumented indirect call sites and the number of
855855
// profiled values at each site.
856856
ASSERT_EQ(4U, R->getNumValueSites(IPVK_IndirectCallTarget));
857-
EXPECT_EQ(3U, R->getNumValueDataForSite(IPVK_IndirectCallTarget, 0));
858-
EXPECT_EQ(0U, R->getNumValueDataForSite(IPVK_IndirectCallTarget, 1));
859-
EXPECT_EQ(2U, R->getNumValueDataForSite(IPVK_IndirectCallTarget, 2));
860-
EXPECT_EQ(2U, R->getNumValueDataForSite(IPVK_IndirectCallTarget, 3));
861857

862858
// Test the number of instrumented vtable sites and the number of profiled
863859
// values at each site.
864860
ASSERT_EQ(R->getNumValueSites(IPVK_VTableTarget), 2U);
865-
EXPECT_EQ(R->getNumValueDataForSite(IPVK_VTableTarget, 0), 3U);
866-
EXPECT_EQ(R->getNumValueDataForSite(IPVK_VTableTarget, 1), 2U);
867861

868862
// First indirect site.
869863
{
870864
auto VD = R->getValueArrayForSite(IPVK_IndirectCallTarget, 0);
865+
ASSERT_THAT(VD, SizeIs(3));
871866

872867
EXPECT_EQ(VD[0].Count, 3U * getProfWeight());
873868
EXPECT_EQ(VD[1].Count, 2U * getProfWeight());
@@ -878,9 +873,14 @@ TEST_P(InstrProfReaderWriterTest, icall_and_vtable_data_read_write) {
878873
EXPECT_STREQ((const char *)VD[2].Value, "callee1");
879874
}
880875

876+
EXPECT_THAT(R->getValueArrayForSite(IPVK_IndirectCallTarget, 1), SizeIs(0));
877+
EXPECT_THAT(R->getValueArrayForSite(IPVK_IndirectCallTarget, 2), SizeIs(2));
878+
EXPECT_THAT(R->getValueArrayForSite(IPVK_IndirectCallTarget, 3), SizeIs(2));
879+
881880
// First vtable site.
882881
{
883882
auto VD = R->getValueArrayForSite(IPVK_VTableTarget, 0);
883+
ASSERT_THAT(VD, SizeIs(3));
884884

885885
EXPECT_EQ(VD[0].Count, 3U * getProfWeight());
886886
EXPECT_EQ(VD[1].Count, 2U * getProfWeight());
@@ -894,6 +894,7 @@ TEST_P(InstrProfReaderWriterTest, icall_and_vtable_data_read_write) {
894894
// Second vtable site.
895895
{
896896
auto VD = R->getValueArrayForSite(IPVK_VTableTarget, 1);
897+
ASSERT_THAT(VD, SizeIs(2));
897898

898899
EXPECT_EQ(VD[0].Count, 2U * getProfWeight());
899900
EXPECT_EQ(VD[1].Count, 1U * getProfWeight());
@@ -1108,20 +1109,13 @@ TEST_P(MaybeSparseInstrProfTest, icall_and_vtable_data_merge) {
11081109
EXPECT_THAT_ERROR(R.takeError(), Succeeded());
11091110
// For indirect calls.
11101111
ASSERT_EQ(5U, R->getNumValueSites(IPVK_IndirectCallTarget));
1111-
ASSERT_EQ(4U, R->getNumValueDataForSite(IPVK_IndirectCallTarget, 0));
1112-
ASSERT_EQ(0U, R->getNumValueDataForSite(IPVK_IndirectCallTarget, 1));
1113-
ASSERT_EQ(4U, R->getNumValueDataForSite(IPVK_IndirectCallTarget, 2));
1114-
ASSERT_EQ(2U, R->getNumValueDataForSite(IPVK_IndirectCallTarget, 3));
1115-
ASSERT_EQ(3U, R->getNumValueDataForSite(IPVK_IndirectCallTarget, 4));
11161112
// For vtables.
11171113
ASSERT_EQ(R->getNumValueSites(IPVK_VTableTarget), 3U);
1118-
ASSERT_EQ(R->getNumValueDataForSite(IPVK_VTableTarget, 0), 4U);
1119-
ASSERT_EQ(R->getNumValueDataForSite(IPVK_VTableTarget, 1), 4U);
1120-
ASSERT_EQ(R->getNumValueDataForSite(IPVK_VTableTarget, 2), 3U);
11211114

11221115
// Test the merged values for indirect calls.
11231116
{
11241117
auto VD = R->getValueArrayForSite(IPVK_IndirectCallTarget, 0);
1118+
ASSERT_THAT(VD, SizeIs(4));
11251119
EXPECT_STREQ((const char *)VD[0].Value, "callee2");
11261120
EXPECT_EQ(VD[0].Count, 7U);
11271121
EXPECT_STREQ((const char *)VD[1].Value, "callee3");
@@ -1131,7 +1125,10 @@ TEST_P(MaybeSparseInstrProfTest, icall_and_vtable_data_merge) {
11311125
EXPECT_STREQ((const char *)VD[3].Value, "callee1");
11321126
EXPECT_EQ(VD[3].Count, 1U);
11331127

1128+
ASSERT_THAT(R->getValueArrayForSite(IPVK_IndirectCallTarget, 1), SizeIs(0));
1129+
11341130
auto VD_2 = R->getValueArrayForSite(IPVK_IndirectCallTarget, 2);
1131+
ASSERT_THAT(VD_2, SizeIs(4));
11351132
EXPECT_STREQ((const char *)VD_2[0].Value, "callee3");
11361133
EXPECT_EQ(VD_2[0].Count, 6U);
11371134
EXPECT_STREQ((const char *)VD_2[1].Value, "callee4");
@@ -1142,12 +1139,14 @@ TEST_P(MaybeSparseInstrProfTest, icall_and_vtable_data_merge) {
11421139
EXPECT_EQ(VD_2[3].Count, 1U);
11431140

11441141
auto VD_3 = R->getValueArrayForSite(IPVK_IndirectCallTarget, 3);
1142+
ASSERT_THAT(VD_3, SizeIs(2));
11451143
EXPECT_STREQ((const char *)VD_3[0].Value, "callee8");
11461144
EXPECT_EQ(VD_3[0].Count, 2U);
11471145
EXPECT_STREQ((const char *)VD_3[1].Value, "callee7");
11481146
EXPECT_EQ(VD_3[1].Count, 1U);
11491147

11501148
auto VD_4 = R->getValueArrayForSite(IPVK_IndirectCallTarget, 4);
1149+
ASSERT_THAT(VD_4, SizeIs(3));
11511150
EXPECT_STREQ((const char *)VD_4[0].Value, "callee3");
11521151
EXPECT_EQ(VD_4[0].Count, 6U);
11531152
EXPECT_STREQ((const char *)VD_4[1].Value, "callee2");
@@ -1159,6 +1158,7 @@ TEST_P(MaybeSparseInstrProfTest, icall_and_vtable_data_merge) {
11591158
// Test the merged values for vtables
11601159
{
11611160
auto VD0 = R->getValueArrayForSite(IPVK_VTableTarget, 0);
1161+
ASSERT_THAT(VD0, SizeIs(4));
11621162
EXPECT_EQ(VD0[0].Value, getCalleeAddress(vtable2));
11631163
EXPECT_EQ(VD0[0].Count, 7U);
11641164
EXPECT_EQ(VD0[1].Value, getCalleeAddress(vtable3));
@@ -1169,6 +1169,7 @@ TEST_P(MaybeSparseInstrProfTest, icall_and_vtable_data_merge) {
11691169
EXPECT_EQ(VD0[3].Count, 1U);
11701170

11711171
auto VD1 = R->getValueArrayForSite(IPVK_VTableTarget, 1);
1172+
ASSERT_THAT(VD1, SizeIs(4));
11721173
EXPECT_EQ(VD1[0].Value, getCalleeAddress(vtable3));
11731174
EXPECT_EQ(VD1[0].Count, 6U);
11741175
EXPECT_EQ(VD1[1].Value, getCalleeAddress(vtable4));
@@ -1179,6 +1180,7 @@ TEST_P(MaybeSparseInstrProfTest, icall_and_vtable_data_merge) {
11791180
EXPECT_EQ(VD1[3].Count, 1U);
11801181

11811182
auto VD2 = R->getValueArrayForSite(IPVK_VTableTarget, 2);
1183+
ASSERT_THAT(VD2, SizeIs(3));
11821184
EXPECT_EQ(VD2[0].Value, getCalleeAddress(vtable3));
11831185
EXPECT_EQ(VD2[0].Count, 6U);
11841186
EXPECT_EQ(VD2[1].Value, getCalleeAddress(vtable2));

0 commit comments

Comments
 (0)