[llvm] 9a8b73c - [memprof] Replace uint32_t with LinearCallStackId where appropriate (NFC) (#94023)

via llvm-commits llvm-commits at lists.llvm.org
Fri May 31 14:41:09 PDT 2024


Author: Kazu Hirata
Date: 2024-05-31T14:41:05-07:00
New Revision: 9a8b73c7413002b4b4015a5b9ba27ad4482809aa

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

LOG: [memprof] Replace uint32_t with LinearCallStackId where appropriate (NFC) (#94023)

This patch replaces uint32_t with LinearCallStackId where appropriate.
I'm replacing uint64_t with LinearCallStackId in
writeMemProfCallStackArray, but that's OK because it's a value to be
used as LinearCallStackId anyway.

Added: 
    

Modified: 
    llvm/include/llvm/ProfileData/MemProf.h
    llvm/lib/ProfileData/InstrProfWriter.cpp
    llvm/lib/ProfileData/MemProf.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/ProfileData/MemProf.h b/llvm/include/llvm/ProfileData/MemProf.h
index b19c1b9a051d1..2a7c853cade66 100644
--- a/llvm/include/llvm/ProfileData/MemProf.h
+++ b/llvm/include/llvm/ProfileData/MemProf.h
@@ -563,14 +563,15 @@ class RecordWriterTrait {
   IndexedVersion Version;
 
   // Mappings from CallStackId to the indexes into the call stack array.
-  llvm::DenseMap<memprof::CallStackId, uint32_t> *MemProfCallStackIndexes;
+  llvm::DenseMap<memprof::CallStackId, LinearCallStackId>
+      *MemProfCallStackIndexes;
 
 public:
   // We do not support the default constructor, which does not set Version.
   RecordWriterTrait() = delete;
-  RecordWriterTrait(
-      const MemProfSchema *Schema, IndexedVersion V,
-      llvm::DenseMap<memprof::CallStackId, uint32_t> *MemProfCallStackIndexes)
+  RecordWriterTrait(const MemProfSchema *Schema, IndexedVersion V,
+                    llvm::DenseMap<memprof::CallStackId, LinearCallStackId>
+                        *MemProfCallStackIndexes)
       : Schema(Schema), Version(V),
         MemProfCallStackIndexes(MemProfCallStackIndexes) {}
 

diff  --git a/llvm/lib/ProfileData/InstrProfWriter.cpp b/llvm/lib/ProfileData/InstrProfWriter.cpp
index 059617a2645c4..9b12922427779 100644
--- a/llvm/lib/ProfileData/InstrProfWriter.cpp
+++ b/llvm/lib/ProfileData/InstrProfWriter.cpp
@@ -454,8 +454,8 @@ static uint64_t writeMemProfRecords(
     llvm::MapVector<GlobalValue::GUID, memprof::IndexedMemProfRecord>
         &MemProfRecordData,
     memprof::MemProfSchema *Schema, memprof::IndexedVersion Version,
-    llvm::DenseMap<memprof::CallStackId, uint32_t> *MemProfCallStackIndexes =
-        nullptr) {
+    llvm::DenseMap<memprof::CallStackId, memprof::LinearCallStackId>
+        *MemProfCallStackIndexes = nullptr) {
   memprof::RecordWriterTrait RecordWriter(Schema, Version,
                                           MemProfCallStackIndexes);
   OnDiskChainedHashTableGenerator<memprof::RecordWriterTrait>
@@ -536,18 +536,20 @@ static uint64_t writeMemProfCallStacks(
   return CallStackTableGenerator.Emit(OS.OS);
 }
 
-static llvm::DenseMap<memprof::CallStackId, uint32_t>
+static llvm::DenseMap<memprof::CallStackId, memprof::LinearCallStackId>
 writeMemProfCallStackArray(
     ProfOStream &OS,
     llvm::MapVector<memprof::CallStackId, llvm::SmallVector<memprof::FrameId>>
         &MemProfCallStackData,
     llvm::DenseMap<memprof::FrameId, uint32_t> &MemProfFrameIndexes) {
-  llvm::DenseMap<memprof::CallStackId, uint32_t> MemProfCallStackIndexes;
+  llvm::DenseMap<memprof::CallStackId, memprof::LinearCallStackId>
+      MemProfCallStackIndexes;
 
   MemProfCallStackIndexes.reserve(MemProfCallStackData.size());
   uint64_t CallStackBase = OS.tell();
   for (const auto &[CSId, CallStack] : MemProfCallStackData) {
-    uint64_t CallStackIndex = (OS.tell() - CallStackBase) / sizeof(uint32_t);
+    memprof::LinearCallStackId CallStackIndex =
+        (OS.tell() - CallStackBase) / sizeof(memprof::LinearCallStackId);
     MemProfCallStackIndexes.insert({CSId, CallStackIndex});
     const llvm::SmallVector<memprof::FrameId> CS = CallStack;
     OS.write32(CS.size());
@@ -712,9 +714,9 @@ static Error writeMemProfV3(ProfOStream &OS,
       writeMemProfFrameArray(OS, MemProfData.FrameData);
 
   uint64_t CallStackPayloadOffset = OS.tell();
-  llvm::DenseMap<memprof::CallStackId, uint32_t> MemProfCallStackIndexes =
-      writeMemProfCallStackArray(OS, MemProfData.CallStackData,
-                                 MemProfFrameIndexes);
+  llvm::DenseMap<memprof::CallStackId, memprof::LinearCallStackId>
+      MemProfCallStackIndexes = writeMemProfCallStackArray(
+          OS, MemProfData.CallStackData, MemProfFrameIndexes);
 
   uint64_t RecordPayloadOffset = OS.tell();
   uint64_t RecordTableOffset =

diff  --git a/llvm/lib/ProfileData/MemProf.cpp b/llvm/lib/ProfileData/MemProf.cpp
index 1c2d760cfeaf2..1d9860e0ea7e8 100644
--- a/llvm/lib/ProfileData/MemProf.cpp
+++ b/llvm/lib/ProfileData/MemProf.cpp
@@ -169,10 +169,10 @@ static void serializeV2(const IndexedMemProfRecord &Record,
     LE.write<CallStackId>(CSId);
 }
 
-static void
-serializeV3(const IndexedMemProfRecord &Record, const MemProfSchema &Schema,
-            raw_ostream &OS,
-            llvm::DenseMap<CallStackId, uint32_t> &MemProfCallStackIndexes) {
+static void serializeV3(
+    const IndexedMemProfRecord &Record, const MemProfSchema &Schema,
+    raw_ostream &OS,
+    llvm::DenseMap<CallStackId, LinearCallStackId> &MemProfCallStackIndexes) {
   using namespace support;
 
   endian::Writer LE(OS, llvm::endianness::little);
@@ -180,7 +180,7 @@ serializeV3(const IndexedMemProfRecord &Record, const MemProfSchema &Schema,
   LE.write<uint64_t>(Record.AllocSites.size());
   for (const IndexedAllocationInfo &N : Record.AllocSites) {
     assert(MemProfCallStackIndexes.contains(N.CSId));
-    LE.write<uint32_t>(MemProfCallStackIndexes[N.CSId]);
+    LE.write<LinearCallStackId>(MemProfCallStackIndexes[N.CSId]);
     N.Info.serialize(Schema, OS);
   }
 
@@ -188,13 +188,13 @@ serializeV3(const IndexedMemProfRecord &Record, const MemProfSchema &Schema,
   LE.write<uint64_t>(Record.CallSiteIds.size());
   for (const auto &CSId : Record.CallSiteIds) {
     assert(MemProfCallStackIndexes.contains(CSId));
-    LE.write<uint32_t>(MemProfCallStackIndexes[CSId]);
+    LE.write<LinearCallStackId>(MemProfCallStackIndexes[CSId]);
   }
 }
 
 void IndexedMemProfRecord::serialize(
     const MemProfSchema &Schema, raw_ostream &OS, IndexedVersion Version,
-    llvm::DenseMap<CallStackId, uint32_t> *MemProfCallStackIndexes) {
+    llvm::DenseMap<CallStackId, LinearCallStackId> *MemProfCallStackIndexes) {
   switch (Version) {
   case Version0:
   case Version1:
@@ -297,7 +297,8 @@ static IndexedMemProfRecord deserializeV3(const MemProfSchema &Schema,
   Record.AllocSites.reserve(NumNodes);
   for (uint64_t I = 0; I < NumNodes; I++) {
     IndexedAllocationInfo Node;
-    Node.CSId = endian::readNext<uint32_t, llvm::endianness::little>(Ptr);
+    Node.CSId =
+        endian::readNext<LinearCallStackId, llvm::endianness::little>(Ptr);
     Node.Info.deserialize(Schema, Ptr);
     Ptr += PortableMemInfoBlock::serializedSize(Schema);
     Record.AllocSites.push_back(Node);


        


More information about the llvm-commits mailing list