Skip to content
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

[ProfileData] Take ArrayRef<InstrProfValueData> in addValueData (NFC) #97363

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
7 changes: 3 additions & 4 deletions llvm/include/llvm/ProfileData/InstrProf.h
Original file line number Diff line number Diff line change
Expand Up @@ -794,9 +794,8 @@ struct InstrProfValueSiteRecord {
std::vector<InstrProfValueData> ValueData;

InstrProfValueSiteRecord() = default;
template <class InputIterator>
InstrProfValueSiteRecord(InputIterator F, InputIterator L)
: ValueData(F, L) {}
InstrProfValueSiteRecord(std::vector<InstrProfValueData> &&VD)
: ValueData(VD) {}

/// Sort ValueData ascending by Value
void sortByTargetValues() {
Expand Down Expand Up @@ -870,7 +869,7 @@ struct InstrProfRecord {
/// Add ValueData for ValueKind at value Site. We do not support adding sites
/// out of order. Site must go up from 0 one by one.
void addValueData(uint32_t ValueKind, uint32_t Site,
InstrProfValueData *VData, uint32_t N,
ArrayRef<InstrProfValueData> VData,
InstrProfSymtab *SymTab);

/// Merge the counts in \p Other into this one.
Expand Down
21 changes: 13 additions & 8 deletions llvm/lib/ProfileData/InstrProf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -998,18 +998,22 @@ uint64_t InstrProfRecord::remapValue(uint64_t Value, uint32_t ValueKind,
}

void InstrProfRecord::addValueData(uint32_t ValueKind, uint32_t Site,
InstrProfValueData *VData, uint32_t N,
ArrayRef<InstrProfValueData> VData,
InstrProfSymtab *ValueMap) {
for (uint32_t I = 0; I < N; I++) {
VData[I].Value = remapValue(VData[I].Value, ValueKind, ValueMap);
// Remap values.
std::vector<InstrProfValueData> RemappedVD;
RemappedVD.reserve(VData.size());
for (const auto &V : VData) {
uint64_t NewValue = remapValue(V.Value, ValueKind, ValueMap);
RemappedVD.push_back({NewValue, V.Count});
}

std::vector<InstrProfValueSiteRecord> &ValueSites =
getOrCreateValueSitesForKind(ValueKind);
assert(ValueSites.size() == Site);
if (N == 0)
ValueSites.emplace_back();
else
ValueSites.emplace_back(VData, VData + N);

// Add a new value site with remapped value profiling data.
ValueSites.emplace_back(std::move(RemappedVD));
}

void TemporalProfTraceTy::createBPFunctionNodes(
Expand Down Expand Up @@ -1143,7 +1147,8 @@ void ValueProfRecord::deserializeTo(InstrProfRecord &Record,
InstrProfValueData *ValueData = getValueProfRecordValueData(this);
for (uint64_t VSite = 0; VSite < NumValueSites; ++VSite) {
uint8_t ValueDataCount = this->SiteCountArray[VSite];
Record.addValueData(Kind, VSite, ValueData, ValueDataCount, SymTab);
ArrayRef<InstrProfValueData> VDs(ValueData, ValueDataCount);
Record.addValueData(Kind, VSite, VDs, SymTab);
ValueData += ValueDataCount;
}
}
Expand Down
4 changes: 2 additions & 2 deletions llvm/lib/ProfileData/InstrProfReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -378,8 +378,8 @@ TextInstrProfReader::readValueProfileData(InstrProfRecord &Record) {
CurrentValues.push_back({Value, TakenCount});
Line++;
}
Record.addValueData(ValueKind, S, CurrentValues.data(), NumValueData,
nullptr);
assert(CurrentValues.size() == NumValueData);
Record.addValueData(ValueKind, S, CurrentValues, nullptr);
}
}
return success();
Expand Down
78 changes: 39 additions & 39 deletions llvm/unittests/ProfileData/InstrProfTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -808,13 +808,13 @@ TEST_P(InstrProfReaderWriterTest, icall_and_vtable_data_read_write) {
Record1.reserveSites(IPVK_IndirectCallTarget, 4);
InstrProfValueData VD0[] = {
{(uint64_t)callee1, 1}, {(uint64_t)callee2, 2}, {(uint64_t)callee3, 3}};
Record1.addValueData(IPVK_IndirectCallTarget, 0, VD0, 3, nullptr);
Record1.addValueData(IPVK_IndirectCallTarget, 0, VD0, nullptr);
// No value profile data at the second site.
Record1.addValueData(IPVK_IndirectCallTarget, 1, nullptr, 0, nullptr);
Record1.addValueData(IPVK_IndirectCallTarget, 1, std::nullopt, nullptr);
InstrProfValueData VD2[] = {{(uint64_t)callee1, 1}, {(uint64_t)callee2, 2}};
Record1.addValueData(IPVK_IndirectCallTarget, 2, VD2, 2, nullptr);
Record1.addValueData(IPVK_IndirectCallTarget, 2, VD2, nullptr);
InstrProfValueData VD3[] = {{(uint64_t)callee7, 1}, {(uint64_t)callee8, 2}};
Record1.addValueData(IPVK_IndirectCallTarget, 3, VD3, 2, nullptr);
Record1.addValueData(IPVK_IndirectCallTarget, 3, VD3, nullptr);
}

// 2 vtable value sites.
Expand All @@ -828,8 +828,8 @@ TEST_P(InstrProfReaderWriterTest, icall_and_vtable_data_read_write) {
{getCalleeAddress(vtable1), 1},
{getCalleeAddress(vtable2), 2},
};
Record1.addValueData(IPVK_VTableTarget, 0, VD0, 3, nullptr);
Record1.addValueData(IPVK_VTableTarget, 1, VD2, 2, nullptr);
Record1.addValueData(IPVK_VTableTarget, 0, VD0, nullptr);
Record1.addValueData(IPVK_VTableTarget, 1, VD2, nullptr);
}

Writer.addRecord(std::move(Record1), getProfWeight(), Err);
Expand Down Expand Up @@ -918,7 +918,7 @@ TEST_P(MaybeSparseInstrProfTest, annotate_vp_data) {
Record.reserveSites(IPVK_IndirectCallTarget, 1);
InstrProfValueData VD0[] = {{1000, 1}, {2000, 2}, {3000, 3}, {5000, 5},
{4000, 4}, {6000, 6}};
Record.addValueData(IPVK_IndirectCallTarget, 0, VD0, 6, nullptr);
Record.addValueData(IPVK_IndirectCallTarget, 0, VD0, nullptr);
Writer.addRecord(std::move(Record), Err);
auto Profile = Writer.writeBuffer();
readProfile(std::move(Profile));
Expand Down Expand Up @@ -1011,21 +1011,21 @@ TEST_P(MaybeSparseInstrProfTest, icall_and_vtable_data_merge) {
{uint64_t(callee2), 2},
{uint64_t(callee3), 3},
{uint64_t(callee4), 4}};
Record11.addValueData(IPVK_IndirectCallTarget, 0, VD0, 4, nullptr);
Record11.addValueData(IPVK_IndirectCallTarget, 0, VD0, nullptr);

// No value profile data at the second site.
Record11.addValueData(IPVK_IndirectCallTarget, 1, nullptr, 0, nullptr);
Record11.addValueData(IPVK_IndirectCallTarget, 1, std::nullopt, nullptr);

InstrProfValueData VD2[] = {
{uint64_t(callee1), 1}, {uint64_t(callee2), 2}, {uint64_t(callee3), 3}};
Record11.addValueData(IPVK_IndirectCallTarget, 2, VD2, 3, nullptr);
Record11.addValueData(IPVK_IndirectCallTarget, 2, VD2, nullptr);

InstrProfValueData VD3[] = {{uint64_t(callee7), 1}, {uint64_t(callee8), 2}};
Record11.addValueData(IPVK_IndirectCallTarget, 3, VD3, 2, nullptr);
Record11.addValueData(IPVK_IndirectCallTarget, 3, VD3, nullptr);

InstrProfValueData VD4[] = {
{uint64_t(callee1), 1}, {uint64_t(callee2), 2}, {uint64_t(callee3), 3}};
Record11.addValueData(IPVK_IndirectCallTarget, 4, VD4, 3, nullptr);
Record11.addValueData(IPVK_IndirectCallTarget, 4, VD4, nullptr);
}
// 3 value sites for vtables.
{
Expand All @@ -1034,53 +1034,53 @@ TEST_P(MaybeSparseInstrProfTest, icall_and_vtable_data_merge) {
{getCalleeAddress(vtable2), 2},
{getCalleeAddress(vtable3), 3},
{getCalleeAddress(vtable4), 4}};
Record11.addValueData(IPVK_VTableTarget, 0, VD0, 4, nullptr);
Record11.addValueData(IPVK_VTableTarget, 0, VD0, nullptr);

InstrProfValueData VD2[] = {{getCalleeAddress(vtable1), 1},
{getCalleeAddress(vtable2), 2},
{getCalleeAddress(vtable3), 3}};
Record11.addValueData(IPVK_VTableTarget, 1, VD2, 3, nullptr);
Record11.addValueData(IPVK_VTableTarget, 1, VD2, nullptr);

InstrProfValueData VD4[] = {{getCalleeAddress(vtable1), 1},
{getCalleeAddress(vtable2), 2},
{getCalleeAddress(vtable3), 3}};
Record11.addValueData(IPVK_VTableTarget, 2, VD4, 3, nullptr);
Record11.addValueData(IPVK_VTableTarget, 2, VD4, nullptr);
}

// A different record for the same caller.
Record12.reserveSites(IPVK_IndirectCallTarget, 5);
InstrProfValueData VD02[] = {{uint64_t(callee2), 5}, {uint64_t(callee3), 3}};
Record12.addValueData(IPVK_IndirectCallTarget, 0, VD02, 2, nullptr);
Record12.addValueData(IPVK_IndirectCallTarget, 0, VD02, nullptr);

// No value profile data at the second site.
Record12.addValueData(IPVK_IndirectCallTarget, 1, nullptr, 0, nullptr);
Record12.addValueData(IPVK_IndirectCallTarget, 1, std::nullopt, nullptr);

InstrProfValueData VD22[] = {
{uint64_t(callee2), 1}, {uint64_t(callee3), 3}, {uint64_t(callee4), 4}};
Record12.addValueData(IPVK_IndirectCallTarget, 2, VD22, 3, nullptr);
Record12.addValueData(IPVK_IndirectCallTarget, 2, VD22, nullptr);

Record12.addValueData(IPVK_IndirectCallTarget, 3, nullptr, 0, nullptr);
Record12.addValueData(IPVK_IndirectCallTarget, 3, std::nullopt, nullptr);

InstrProfValueData VD42[] = {
{uint64_t(callee1), 1}, {uint64_t(callee2), 2}, {uint64_t(callee3), 3}};
Record12.addValueData(IPVK_IndirectCallTarget, 4, VD42, 3, nullptr);
Record12.addValueData(IPVK_IndirectCallTarget, 4, VD42, nullptr);

// 3 value sites for vtables.
{
Record12.reserveSites(IPVK_VTableTarget, 3);
InstrProfValueData VD0[] = {{getCalleeAddress(vtable2), 5},
{getCalleeAddress(vtable3), 3}};
Record12.addValueData(IPVK_VTableTarget, 0, VD0, 2, nullptr);
Record12.addValueData(IPVK_VTableTarget, 0, VD0, nullptr);

InstrProfValueData VD2[] = {{getCalleeAddress(vtable2), 1},
{getCalleeAddress(vtable3), 3},
{getCalleeAddress(vtable4), 4}};
Record12.addValueData(IPVK_VTableTarget, 1, VD2, 3, nullptr);
Record12.addValueData(IPVK_VTableTarget, 1, VD2, nullptr);

InstrProfValueData VD4[] = {{getCalleeAddress(vtable1), 1},
{getCalleeAddress(vtable2), 2},
{getCalleeAddress(vtable3), 3}};
Record12.addValueData(IPVK_VTableTarget, 2, VD4, 3, nullptr);
Record12.addValueData(IPVK_VTableTarget, 2, VD4, nullptr);
}

Writer.addRecord(std::move(Record11), Err);
Expand Down Expand Up @@ -1220,7 +1220,7 @@ TEST_P(ValueProfileMergeEdgeCaseTest, value_profile_data_merge_saturation) {
NamedInstrProfRecord Record4("baz", 0x5678, {3, 4});
Record4.reserveSites(ValueKind, 1);
InstrProfValueData VD4[] = {{ProfiledValue, 1}};
Record4.addValueData(ValueKind, 0, VD4, 1, nullptr);
Record4.addValueData(ValueKind, 0, VD4, nullptr);
Result = instrprof_error::success;
Writer.addRecord(std::move(Record4), Err);
ASSERT_EQ(Result, instrprof_error::success);
Expand All @@ -1229,7 +1229,7 @@ TEST_P(ValueProfileMergeEdgeCaseTest, value_profile_data_merge_saturation) {
NamedInstrProfRecord Record5("baz", 0x5678, {5, 6});
Record5.reserveSites(ValueKind, 1);
InstrProfValueData VD5[] = {{ProfiledValue, MaxValCount}};
Record5.addValueData(ValueKind, 0, VD5, 1, nullptr);
Record5.addValueData(ValueKind, 0, VD5, nullptr);
Result = instrprof_error::success;
Writer.addRecord(std::move(Record5), Err);
ASSERT_EQ(Result, instrprof_error::counter_overflow);
Expand Down Expand Up @@ -1269,8 +1269,8 @@ TEST_P(ValueProfileMergeEdgeCaseTest, value_profile_data_merge_site_trunc) {
VD0[I].Count = 2 * I + 1000;
}

Record11.addValueData(ValueKind, 0, VD0, 255, nullptr);
Record11.addValueData(ValueKind, 1, nullptr, 0, nullptr);
Record11.addValueData(ValueKind, 0, VD0, nullptr);
Record11.addValueData(ValueKind, 1, std::nullopt, nullptr);

Record12.reserveSites(ValueKind, 2);
InstrProfValueData VD1[255];
Expand All @@ -1279,8 +1279,8 @@ TEST_P(ValueProfileMergeEdgeCaseTest, value_profile_data_merge_site_trunc) {
VD1[I].Count = 2 * I + 1001;
}

Record12.addValueData(ValueKind, 0, VD1, 255, nullptr);
Record12.addValueData(ValueKind, 1, nullptr, 0, nullptr);
Record12.addValueData(ValueKind, 0, VD1, nullptr);
Record12.addValueData(ValueKind, 1, std::nullopt, nullptr);

Writer.addRecord(std::move(Record11), Err);
// Merge profile data.
Expand Down Expand Up @@ -1317,23 +1317,23 @@ static void addValueProfData(InstrProfRecord &Record) {
{uint64_t(callee3), 500},
{uint64_t(callee4), 300},
{uint64_t(callee5), 100}};
Record.addValueData(IPVK_IndirectCallTarget, 0, VD0, 5, nullptr);
Record.addValueData(IPVK_IndirectCallTarget, 0, VD0, nullptr);
InstrProfValueData VD1[] = {{uint64_t(callee5), 800},
{uint64_t(callee3), 1000},
{uint64_t(callee2), 2500},
{uint64_t(callee1), 1300}};
Record.addValueData(IPVK_IndirectCallTarget, 1, VD1, 4, nullptr);
Record.addValueData(IPVK_IndirectCallTarget, 1, VD1, nullptr);
InstrProfValueData VD2[] = {{uint64_t(callee6), 800},
{uint64_t(callee3), 1000},
{uint64_t(callee4), 5500}};
Record.addValueData(IPVK_IndirectCallTarget, 2, VD2, 3, nullptr);
Record.addValueData(IPVK_IndirectCallTarget, 2, VD2, nullptr);
InstrProfValueData VD3[] = {{uint64_t(callee2), 1800},
{uint64_t(callee3), 2000}};
Record.addValueData(IPVK_IndirectCallTarget, 3, VD3, 2, nullptr);
Record.addValueData(IPVK_IndirectCallTarget, 4, nullptr, 0, nullptr);
Record.addValueData(IPVK_IndirectCallTarget, 3, VD3, nullptr);
Record.addValueData(IPVK_IndirectCallTarget, 4, std::nullopt, nullptr);
InstrProfValueData VD5[] = {{uint64_t(callee7), 1234},
{uint64_t(callee8), 5678}};
Record.addValueData(IPVK_IndirectCallTarget, 5, VD5, 2, nullptr);
Record.addValueData(IPVK_IndirectCallTarget, 5, VD5, nullptr);
}

// Add test data for vtables
Expand All @@ -1355,10 +1355,10 @@ static void addValueProfData(InstrProfRecord &Record) {
};
InstrProfValueData VD3[] = {{getCalleeAddress(vtable2), 1800},
{getCalleeAddress(vtable3), 2000}};
Record.addValueData(IPVK_VTableTarget, 0, VD0, 5, nullptr);
Record.addValueData(IPVK_VTableTarget, 1, VD1, 4, nullptr);
Record.addValueData(IPVK_VTableTarget, 2, VD2, 3, nullptr);
Record.addValueData(IPVK_VTableTarget, 3, VD3, 2, nullptr);
Record.addValueData(IPVK_VTableTarget, 0, VD0, nullptr);
Record.addValueData(IPVK_VTableTarget, 1, VD1, nullptr);
Record.addValueData(IPVK_VTableTarget, 2, VD2, nullptr);
Record.addValueData(IPVK_VTableTarget, 3, VD3, nullptr);
}
}

Expand Down
Loading