[llvm] 329e6b4 - [ProfileData] Use std::array for ValueProfData (#96440)

via llvm-commits llvm-commits at lists.llvm.org
Sun Jun 23 16:48:30 PDT 2024


Author: Kazu Hirata
Date: 2024-06-23T16:48:27-07:00
New Revision: 329e6b4fd5a995c7d8aa4d11aec1b901ca49e484

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

LOG: [ProfileData] Use std::array for ValueProfData (#96440)

This patch uses std::array for ValueProfData.  Aside from reducing the
line count and code duplication, the use of std::array here makes it
easier to add a new type of value profiling without touching as many
places.

Added: 
    

Modified: 
    llvm/include/llvm/ProfileData/InstrProf.h

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/ProfileData/InstrProf.h b/llvm/include/llvm/ProfileData/InstrProf.h
index 9bb1d8cbddc5e..7fa6d44990a14 100644
--- a/llvm/include/llvm/ProfileData/InstrProf.h
+++ b/llvm/include/llvm/ProfileData/InstrProf.h
@@ -935,11 +935,8 @@ struct InstrProfRecord {
   }
 
 private:
-  struct ValueProfData {
-    std::vector<InstrProfValueSiteRecord> IndirectCallSites;
-    std::vector<InstrProfValueSiteRecord> MemOPSizes;
-    std::vector<InstrProfValueSiteRecord> VTableTargets;
-  };
+  using ValueProfData = std::array<std::vector<InstrProfValueSiteRecord>,
+                                   IPVK_Last - IPVK_First + 1>;
   std::unique_ptr<ValueProfData> ValueData;
 
   MutableArrayRef<InstrProfValueSiteRecord>
@@ -956,32 +953,18 @@ struct InstrProfRecord {
   getValueSitesForKind(uint32_t ValueKind) const {
     if (!ValueData)
       return std::nullopt;
-    switch (ValueKind) {
-    case IPVK_IndirectCallTarget:
-      return ValueData->IndirectCallSites;
-    case IPVK_MemOPSize:
-      return ValueData->MemOPSizes;
-    case IPVK_VTableTarget:
-      return ValueData->VTableTargets;
-    default:
-      llvm_unreachable("Unknown value kind!");
-    }
+    assert(IPVK_First <= ValueKind && ValueKind <= IPVK_Last &&
+           "Unknown value kind!");
+    return (*ValueData)[ValueKind - IPVK_First];
   }
 
   std::vector<InstrProfValueSiteRecord> &
   getOrCreateValueSitesForKind(uint32_t ValueKind) {
     if (!ValueData)
       ValueData = std::make_unique<ValueProfData>();
-    switch (ValueKind) {
-    case IPVK_IndirectCallTarget:
-      return ValueData->IndirectCallSites;
-    case IPVK_MemOPSize:
-      return ValueData->MemOPSizes;
-    case IPVK_VTableTarget:
-      return ValueData->VTableTargets;
-    default:
-      llvm_unreachable("Unknown value kind!");
-    }
+    assert(IPVK_First <= ValueKind && ValueKind <= IPVK_Last &&
+           "Unknown value kind!");
+    return (*ValueData)[ValueKind - IPVK_First];
   }
 
   // Map indirect call target name hash to name string.


        


More information about the llvm-commits mailing list