[llvm] 4292086 - [ProfileData] Use ArrayRef in ProfOStream::patch (NFC) (#85317)

via llvm-commits llvm-commits at lists.llvm.org
Thu Mar 14 17:50:03 PDT 2024


Author: Kazu Hirata
Date: 2024-03-14T17:49:59-07:00
New Revision: 4292086ed0e0310208f02be1b0393555770c379c

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

LOG: [ProfileData] Use ArrayRef in ProfOStream::patch (NFC) (#85317)

We always apply all of the items in PatchItems.  This patch simplifies
the interface of ProfOStream::patch by switching to ArrayRef.

Added: 
    

Modified: 
    llvm/lib/ProfileData/InstrProfWriter.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/ProfileData/InstrProfWriter.cpp b/llvm/lib/ProfileData/InstrProfWriter.cpp
index e757c735719b1f..d9fe88a00bdfc4 100644
--- a/llvm/lib/ProfileData/InstrProfWriter.cpp
+++ b/llvm/lib/ProfileData/InstrProfWriter.cpp
@@ -60,16 +60,16 @@ class ProfOStream {
   // \c patch can only be called when all data is written and flushed.
   // For raw_string_ostream, the patch is done on the target string
   // directly and it won't be reflected in the stream's internal buffer.
-  void patch(PatchItem *P, int NItems) {
+  void patch(ArrayRef<PatchItem> P) {
     using namespace support;
 
     if (IsFDOStream) {
       raw_fd_ostream &FDOStream = static_cast<raw_fd_ostream &>(OS);
       const uint64_t LastPos = FDOStream.tell();
-      for (int K = 0; K < NItems; K++) {
-        FDOStream.seek(P[K].Pos);
-        for (int I = 0; I < P[K].N; I++)
-          write(P[K].D[I]);
+      for (const auto &K : P) {
+        FDOStream.seek(K.Pos);
+        for (int I = 0; I < K.N; I++)
+          write(K.D[I]);
       }
       // Reset the stream to the last position after patching so that users
       // don't accidentally overwrite data. This makes it consistent with
@@ -78,11 +78,11 @@ class ProfOStream {
     } else {
       raw_string_ostream &SOStream = static_cast<raw_string_ostream &>(OS);
       std::string &Data = SOStream.str(); // with flush
-      for (int K = 0; K < NItems; K++) {
-        for (int I = 0; I < P[K].N; I++) {
+      for (const auto &K : P) {
+        for (int I = 0; I < K.N; I++) {
           uint64_t Bytes =
-              endian::byte_swap<uint64_t, llvm::endianness::little>(P[K].D[I]);
-          Data.replace(P[K].Pos + I * sizeof(uint64_t), sizeof(uint64_t),
+              endian::byte_swap<uint64_t, llvm::endianness::little>(K.D[I]);
+          Data.replace(K.Pos + I * sizeof(uint64_t), sizeof(uint64_t),
                        (const char *)&Bytes, sizeof(uint64_t));
         }
       }
@@ -575,7 +575,7 @@ Error InstrProfWriter::writeImpl(ProfOStream &OS) {
         {MemProfSectionStart + sizeof(uint64_t), &FramePayloadOffset, 1},
         {MemProfSectionStart + 2 * sizeof(uint64_t), &FrameTableOffset, 1},
     };
-    OS.patch(PatchItems, 3);
+    OS.patch(PatchItems);
   }
 
   // BinaryIdSection has two parts:
@@ -693,7 +693,7 @@ Error InstrProfWriter::writeImpl(ProfOStream &OS) {
         {CSSummaryOffset, reinterpret_cast<uint64_t *>(TheCSSummary.get()),
          (int)CSSummarySize}};
 
-    OS.patch(PatchItems, std::size(PatchItems));
+    OS.patch(PatchItems);
   } else {
     // Now do the final patch:
     PatchItem PatchItems[] = {
@@ -713,7 +713,7 @@ Error InstrProfWriter::writeImpl(ProfOStream &OS) {
         {CSSummaryOffset, reinterpret_cast<uint64_t *>(TheCSSummary.get()),
          (int)CSSummarySize}};
 
-    OS.patch(PatchItems, std::size(PatchItems));
+    OS.patch(PatchItems);
   }
 
   for (const auto &I : FunctionData)


        


More information about the llvm-commits mailing list