[llvm] [ProfileData] Clean up validateRecord (PR #95488)

Mingming Liu via llvm-commits llvm-commits at lists.llvm.org
Thu Jun 13 22:38:08 PDT 2024


================
@@ -1035,16 +1035,13 @@ static const char *ValueProfKindStr[] = {
 
 Error InstrProfWriter::validateRecord(const InstrProfRecord &Func) {
   for (uint32_t VK = 0; VK <= IPVK_Last; VK++) {
-    uint32_t NS = Func.getNumValueSites(VK);
-    if (!NS)
+    if (VK == IPVK_IndirectCallTarget || VK == IPVK_VTableTarget)
       continue;
+    uint32_t NS = Func.getNumValueSites(VK);
     for (uint32_t S = 0; S < NS; S++) {
-      uint32_t ND = Func.getNumValueDataForSite(VK, S);
-      std::unique_ptr<InstrProfValueData[]> VD = Func.getValueForSite(VK, S);
       DenseSet<uint64_t> SeenValues;
-      for (uint32_t I = 0; I < ND; I++)
-        if ((VK != IPVK_IndirectCallTarget && VK != IPVK_VTableTarget) &&
----------------
minglotus-6 wrote:

Before https://github.com/llvm/llvm-project/commit/a4b543a5a541eeff5a7ba92ada4b0d809a2c8482, 'validateRecord' allows 'Value' to be zero.

I read the commit message of https://github.com/llvm/llvm-project/commit/a4b543a5a541eeff5a7ba92ada4b0d809a2c8482 a second time, and think duplicated zeros can come from valid profiles; IndirectCallTarget and VTableTarget value profiles map runtime address to functions' and global variables' GUID. If the function or global variable isn't instrumented (e.g., per IR module opt-out of `-fprofile-generate`),  (unique) runtime address might be mapped to (duplicated) zero (by `InstrProfRecord::remapValue`).

https://github.com/llvm/llvm-project/pull/95488


More information about the llvm-commits mailing list