Skip to content

[ProfileData] Add getValueArrayForSite #95335

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions llvm/include/llvm/ProfileData/InstrProf.h
Original file line number Diff line number Diff line change
Expand Up @@ -864,6 +864,10 @@ struct InstrProfRecord {
/// Return the total number of ValueData for ValueKind.
inline uint32_t getNumValueData(uint32_t ValueKind) const;

/// Return the array of profiled values at \p Site.
inline ArrayRef<InstrProfValueData> getValueArrayForSite(uint32_t ValueKind,
uint32_t Site) const;

/// Return the number of value data collected for ValueKind at profiling
/// site: Site.
inline uint32_t getNumValueDataForSite(uint32_t ValueKind,
Expand Down Expand Up @@ -1060,6 +1064,11 @@ uint32_t InstrProfRecord::getNumValueDataForSite(uint32_t ValueKind,
return getValueSitesForKind(ValueKind)[Site].ValueData.size();
}

ArrayRef<InstrProfValueData>
InstrProfRecord::getValueArrayForSite(uint32_t ValueKind, uint32_t Site) const {
return getValueSitesForKind(ValueKind)[Site].ValueData;
}

std::unique_ptr<InstrProfValueData[]>
InstrProfRecord::getValueForSite(uint32_t ValueKind, uint32_t Site) const {
uint32_t N = getNumValueDataForSite(ValueKind, Site);
Expand Down
14 changes: 7 additions & 7 deletions llvm/unittests/ProfileData/InstrProfTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -867,7 +867,7 @@ TEST_P(InstrProfReaderWriterTest, icall_and_vtable_data_read_write) {

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

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

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

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

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

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

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

// Test the merged values for vtables
{
auto VD0 = R->getValueForSite(IPVK_VTableTarget, 0);
auto VD0 = R->getValueArrayForSite(IPVK_VTableTarget, 0);
EXPECT_EQ(VD0[0].Value, getCalleeAddress(vtable2));
EXPECT_EQ(VD0[0].Count, 7U);
EXPECT_EQ(VD0[1].Value, getCalleeAddress(vtable3));
Expand All @@ -1172,7 +1172,7 @@ TEST_P(MaybeSparseInstrProfTest, icall_and_vtable_data_merge) {
EXPECT_EQ(VD0[3].Value, getCalleeAddress(vtable1));
EXPECT_EQ(VD0[3].Count, 1U);

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

auto VD2 = R->getValueForSite(IPVK_VTableTarget, 2);
auto VD2 = R->getValueArrayForSite(IPVK_VTableTarget, 2);
EXPECT_EQ(VD2[0].Value, getCalleeAddress(vtable3));
EXPECT_EQ(VD2[0].Count, 6U);
EXPECT_EQ(VD2[1].Value, getCalleeAddress(vtable2));
Expand Down
Loading