[llvm] 4b493e3 - [ProfileData] Add getValueArrayForSite (#95335)
via llvm-commits
llvm-commits at lists.llvm.org
Thu Jun 13 11:08:22 PDT 2024
Author: Kazu Hirata
Date: 2024-06-13T11:08:17-07:00
New Revision: 4b493e31b2c5d72d993f0e914adb711f3ce4ba05
URL: https://github.com/llvm/llvm-project/commit/4b493e31b2c5d72d993f0e914adb711f3ce4ba05
DIFF: https://github.com/llvm/llvm-project/commit/4b493e31b2c5d72d993f0e914adb711f3ce4ba05.diff
LOG: [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.
Added:
Modified:
llvm/include/llvm/ProfileData/InstrProf.h
llvm/unittests/ProfileData/InstrProfTest.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/ProfileData/InstrProf.h b/llvm/include/llvm/ProfileData/InstrProf.h
index 2772fddc08737..0c899e6d84965 100644
--- a/llvm/include/llvm/ProfileData/InstrProf.h
+++ b/llvm/include/llvm/ProfileData/InstrProf.h
@@ -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,
@@ -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);
diff --git a/llvm/unittests/ProfileData/InstrProfTest.cpp b/llvm/unittests/ProfileData/InstrProfTest.cpp
index 8acb0fa0c717a..0309be4eb10fb 100644
--- a/llvm/unittests/ProfileData/InstrProfTest.cpp
+++ b/llvm/unittests/ProfileData/InstrProfTest.cpp
@@ -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());
@@ -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());
@@ -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());
@@ -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");
@@ -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));
@@ -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));
@@ -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));
More information about the llvm-commits
mailing list