Skip to content

Commit 4b493e3

Browse files
[ProfileData] Add getValueArrayForSite (#95335)
Without this patch, a typical traversal over the value data looks like: uint32_t NV = Func.getNumValueDataForSite(VK, S); std::unique_ptr<InstrProfValueData[]> VD = Func.getValueForSite(VK, S); for (uint32_t V = 0; V < NV; V++) Do something with VD[V].Value and/or VD[V].Count; This patch adds getValueArrayForSite, which returns ArrayRef<InstrProfValueData>, so we can do: for (const auto &V : Func.getValueArrayForSite(VK, S)) Do something with V.Value and/or V.Count; I'm planning to migrate the existing uses of getValueForSite to getValueArrayForSite in follow-up patches and remove getValueForSite and getNumValueDataForSite.
1 parent 2414a90 commit 4b493e3

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
lines changed

llvm/include/llvm/ProfileData/InstrProf.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -864,6 +864,10 @@ struct InstrProfRecord {
864864
/// Return the total number of ValueData for ValueKind.
865865
inline uint32_t getNumValueData(uint32_t ValueKind) const;
866866

867+
/// Return the array of profiled values at \p Site.
868+
inline ArrayRef<InstrProfValueData> getValueArrayForSite(uint32_t ValueKind,
869+
uint32_t Site) const;
870+
867871
/// Return the number of value data collected for ValueKind at profiling
868872
/// site: Site.
869873
inline uint32_t getNumValueDataForSite(uint32_t ValueKind,
@@ -1060,6 +1064,11 @@ uint32_t InstrProfRecord::getNumValueDataForSite(uint32_t ValueKind,
10601064
return getValueSitesForKind(ValueKind)[Site].ValueData.size();
10611065
}
10621066

1067+
ArrayRef<InstrProfValueData>
1068+
InstrProfRecord::getValueArrayForSite(uint32_t ValueKind, uint32_t Site) const {
1069+
return getValueSitesForKind(ValueKind)[Site].ValueData;
1070+
}
1071+
10631072
std::unique_ptr<InstrProfValueData[]>
10641073
InstrProfRecord::getValueForSite(uint32_t ValueKind, uint32_t Site) const {
10651074
uint32_t N = getNumValueDataForSite(ValueKind, Site);

llvm/unittests/ProfileData/InstrProfTest.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -867,7 +867,7 @@ TEST_P(InstrProfReaderWriterTest, icall_and_vtable_data_read_write) {
867867

868868
// First indirect site.
869869
{
870-
auto VD = R->getValueForSite(IPVK_IndirectCallTarget, 0);
870+
auto VD = R->getValueArrayForSite(IPVK_IndirectCallTarget, 0);
871871

872872
EXPECT_EQ(VD[0].Count, 3U * getProfWeight());
873873
EXPECT_EQ(VD[1].Count, 2U * getProfWeight());
@@ -880,7 +880,7 @@ TEST_P(InstrProfReaderWriterTest, icall_and_vtable_data_read_write) {
880880

881881
// First vtable site.
882882
{
883-
auto VD = R->getValueForSite(IPVK_VTableTarget, 0);
883+
auto VD = R->getValueArrayForSite(IPVK_VTableTarget, 0);
884884

885885
EXPECT_EQ(VD[0].Count, 3U * getProfWeight());
886886
EXPECT_EQ(VD[1].Count, 2U * getProfWeight());
@@ -893,7 +893,7 @@ TEST_P(InstrProfReaderWriterTest, icall_and_vtable_data_read_write) {
893893

894894
// Second vtable site.
895895
{
896-
auto VD = R->getValueForSite(IPVK_VTableTarget, 1);
896+
auto VD = R->getValueArrayForSite(IPVK_VTableTarget, 1);
897897

898898
EXPECT_EQ(VD[0].Count, 2U * getProfWeight());
899899
EXPECT_EQ(VD[1].Count, 1U * getProfWeight());
@@ -1125,7 +1125,7 @@ TEST_P(MaybeSparseInstrProfTest, icall_and_vtable_data_merge) {
11251125

11261126
// Test the merged values for indirect calls.
11271127
{
1128-
auto VD = R->getValueForSite(IPVK_IndirectCallTarget, 0);
1128+
auto VD = R->getValueArrayForSite(IPVK_IndirectCallTarget, 0);
11291129
EXPECT_STREQ((const char *)VD[0].Value, "callee2");
11301130
EXPECT_EQ(VD[0].Count, 7U);
11311131
EXPECT_STREQ((const char *)VD[1].Value, "callee3");
@@ -1162,7 +1162,7 @@ TEST_P(MaybeSparseInstrProfTest, icall_and_vtable_data_merge) {
11621162

11631163
// Test the merged values for vtables
11641164
{
1165-
auto VD0 = R->getValueForSite(IPVK_VTableTarget, 0);
1165+
auto VD0 = R->getValueArrayForSite(IPVK_VTableTarget, 0);
11661166
EXPECT_EQ(VD0[0].Value, getCalleeAddress(vtable2));
11671167
EXPECT_EQ(VD0[0].Count, 7U);
11681168
EXPECT_EQ(VD0[1].Value, getCalleeAddress(vtable3));
@@ -1172,7 +1172,7 @@ TEST_P(MaybeSparseInstrProfTest, icall_and_vtable_data_merge) {
11721172
EXPECT_EQ(VD0[3].Value, getCalleeAddress(vtable1));
11731173
EXPECT_EQ(VD0[3].Count, 1U);
11741174

1175-
auto VD1 = R->getValueForSite(IPVK_VTableTarget, 1);
1175+
auto VD1 = R->getValueArrayForSite(IPVK_VTableTarget, 1);
11761176
EXPECT_EQ(VD1[0].Value, getCalleeAddress(vtable3));
11771177
EXPECT_EQ(VD1[0].Count, 6U);
11781178
EXPECT_EQ(VD1[1].Value, getCalleeAddress(vtable4));
@@ -1182,7 +1182,7 @@ TEST_P(MaybeSparseInstrProfTest, icall_and_vtable_data_merge) {
11821182
EXPECT_EQ(VD1[3].Value, getCalleeAddress(vtable1));
11831183
EXPECT_EQ(VD1[3].Count, 1U);
11841184

1185-
auto VD2 = R->getValueForSite(IPVK_VTableTarget, 2);
1185+
auto VD2 = R->getValueArrayForSite(IPVK_VTableTarget, 2);
11861186
EXPECT_EQ(VD2[0].Value, getCalleeAddress(vtable3));
11871187
EXPECT_EQ(VD2[0].Count, 6U);
11881188
EXPECT_EQ(VD2[1].Value, getCalleeAddress(vtable2));

0 commit comments

Comments
 (0)