[llvm] beba2e7 - [ProfileData] Teach addValueData to honor parameter Site (#96233)

via llvm-commits llvm-commits at lists.llvm.org
Thu Jun 20 22:25:24 PDT 2024


Author: Kazu Hirata
Date: 2024-06-20T22:25:19-07:00
New Revision: beba2e738548cb7465deef640f173fa768c10711

URL: https://github.com/llvm/llvm-project/commit/beba2e738548cb7465deef640f173fa768c10711
DIFF: https://github.com/llvm/llvm-project/commit/beba2e738548cb7465deef640f173fa768c10711.diff

LOG: [ProfileData] Teach addValueData to honor parameter Site (#96233)

This patch teaches addValueData to honor Site for verification
purposes.  It does not affect the profile data in any manner.

Added: 
    

Modified: 
    llvm/include/llvm/ProfileData/InstrProf.h
    llvm/lib/ProfileData/InstrProf.cpp
    llvm/unittests/ProfileData/InstrProfTest.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/ProfileData/InstrProf.h b/llvm/include/llvm/ProfileData/InstrProf.h
index df79073da5b50..d5ddf16957c83 100644
--- a/llvm/include/llvm/ProfileData/InstrProf.h
+++ b/llvm/include/llvm/ProfileData/InstrProf.h
@@ -860,7 +860,8 @@ struct InstrProfRecord {
   /// Reserve space for NumValueSites sites.
   inline void reserveSites(uint32_t ValueKind, uint32_t NumValueSites);
 
-  /// Add ValueData for ValueKind at value Site.
+  /// 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,
                     InstrProfSymtab *SymTab);

diff  --git a/llvm/lib/ProfileData/InstrProf.cpp b/llvm/lib/ProfileData/InstrProf.cpp
index 8cc1625e1c05c..3e0e2b2284d8f 100644
--- a/llvm/lib/ProfileData/InstrProf.cpp
+++ b/llvm/lib/ProfileData/InstrProf.cpp
@@ -1001,6 +1001,7 @@ void InstrProfRecord::addValueData(uint32_t ValueKind, uint32_t Site,
   }
   std::vector<InstrProfValueSiteRecord> &ValueSites =
       getOrCreateValueSitesForKind(ValueKind);
+  assert(ValueSites.size() == Site);
   if (N == 0)
     ValueSites.emplace_back();
   else

diff  --git a/llvm/unittests/ProfileData/InstrProfTest.cpp b/llvm/unittests/ProfileData/InstrProfTest.cpp
index e39da6b33ecf2..a2cda2ba52dfe 100644
--- a/llvm/unittests/ProfileData/InstrProfTest.cpp
+++ b/llvm/unittests/ProfileData/InstrProfTest.cpp
@@ -829,7 +829,7 @@ TEST_P(InstrProfReaderWriterTest, icall_and_vtable_data_read_write) {
         {getCalleeAddress(vtable2), 2},
     };
     Record1.addValueData(IPVK_VTableTarget, 0, VD0, 3, nullptr);
-    Record1.addValueData(IPVK_VTableTarget, 2, VD2, 2, nullptr);
+    Record1.addValueData(IPVK_VTableTarget, 1, VD2, 2, nullptr);
   }
 
   Writer.addRecord(std::move(Record1), getProfWeight(), Err);
@@ -1050,7 +1050,7 @@ TEST_P(MaybeSparseInstrProfTest, icall_and_vtable_data_merge) {
     InstrProfValueData VD4[] = {{getCalleeAddress(vtable1), 1},
                                 {getCalleeAddress(vtable2), 2},
                                 {getCalleeAddress(vtable3), 3}};
-    Record11.addValueData(IPVK_VTableTarget, 3, VD4, 3, nullptr);
+    Record11.addValueData(IPVK_VTableTarget, 2, VD4, 3, nullptr);
   }
 
   // A 
diff erent record for the same caller.
@@ -1086,7 +1086,7 @@ TEST_P(MaybeSparseInstrProfTest, icall_and_vtable_data_merge) {
     InstrProfValueData VD4[] = {{getCalleeAddress(vtable1), 1},
                                 {getCalleeAddress(vtable2), 2},
                                 {getCalleeAddress(vtable3), 3}};
-    Record12.addValueData(IPVK_VTableTarget, 3, VD4, 3, nullptr);
+    Record12.addValueData(IPVK_VTableTarget, 2, VD4, 3, nullptr);
   }
 
   Writer.addRecord(std::move(Record11), Err);


        


More information about the llvm-commits mailing list