[llvm] 3d2bbea - [ProfileData] Clean up validateRecord (#95488)

via llvm-commits llvm-commits at lists.llvm.org
Tue Jun 18 13:06:47 PDT 2024


Author: Kazu Hirata
Date: 2024-06-18T13:06:43-07:00
New Revision: 3d2bbea37002e38759c06d975b6656a91e908dc6

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

LOG: [ProfileData] Clean up validateRecord (#95488)

validateRecord ensures that all the values are unique except for
IPVK_IndirectCallTarget and IPVK_VTableTarget.  The problem is that we
exclude them in the innermost loop.

This patch pulls the loop invariant out of the loop.  While I am at
it, this patch migrates a use of getValueForSite to
getValueArrayForSite.

Added: 
    

Modified: 
    llvm/lib/ProfileData/InstrProfWriter.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/ProfileData/InstrProfWriter.cpp b/llvm/lib/ProfileData/InstrProfWriter.cpp
index cf2416c4e8074..eac59ea11a47e 100644
--- a/llvm/lib/ProfileData/InstrProfWriter.cpp
+++ b/llvm/lib/ProfileData/InstrProfWriter.cpp
@@ -1034,16 +1034,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) &&
-            !SeenValues.insert(VD[I].Value).second)
+      for (const auto &V : Func.getValueArrayForSite(VK, S))
+        if (!SeenValues.insert(V.Value).second)
           return make_error<InstrProfError>(instrprof_error::invalid_prof);
     }
   }


        


More information about the llvm-commits mailing list