[PATCH] D100235: [CSSPGO][llvm-profgen] Fixing an obselete iterator issue.

Hongtao Yu via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Apr 9 15:45:16 PDT 2021


hoy updated this revision to Diff 336574.
hoy added a comment.

Updating D100235 <https://reviews.llvm.org/D100235>: [CSSPGO][llvm-profgen] Fixing an obselete iterator issue.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D100235/new/

https://reviews.llvm.org/D100235

Files:
  llvm/include/llvm/MC/MCPseudoProbe.h
  llvm/tools/llvm-profgen/PseudoProbe.cpp
  llvm/tools/llvm-profgen/PseudoProbe.h


Index: llvm/tools/llvm-profgen/PseudoProbe.h
===================================================================
--- llvm/tools/llvm-profgen/PseudoProbe.h
+++ llvm/tools/llvm-profgen/PseudoProbe.h
@@ -71,6 +71,7 @@
     return Ret.first->second.get();
   }
 
+  auto &getChildren() { return Children; }
   void addProbes(PseudoProbe *Probe) { ProbeVector.push_back(Probe); }
   // Return false if it's a dummy inline site
   bool hasInlineSite() const { return std::get<0>(ISite) != 0; }
@@ -91,7 +92,7 @@
 // GUID to PseudoProbeFuncDesc map
 using GUIDProbeFunctionMap = std::unordered_map<uint64_t, PseudoProbeFuncDesc>;
 // Address to pseudo probes map.
-using AddressProbesMap = std::unordered_map<uint64_t, std::vector<PseudoProbe>>;
+using AddressProbesMap = std::unordered_map<uint64_t, std::list<PseudoProbe>>;
 
 /*
 A pseudo probe has the format like below:
Index: llvm/tools/llvm-profgen/PseudoProbe.cpp
===================================================================
--- llvm/tools/llvm-profgen/PseudoProbe.cpp
+++ llvm/tools/llvm-profgen/PseudoProbe.cpp
@@ -198,7 +198,6 @@
   //         A list of NUM_INLINED_FUNCTIONS entries describing each of the
   //         inlined callees.  Each record contains:
   //           INLINE SITE
-  //             GUID of the inlinee (uint64)
   //             Index of the callsite probe (ULEB128)
   //           FUNCTION BODY
   //             A FUNCTION BODY entry describing the inlined function.
@@ -214,8 +213,11 @@
   uint32_t Index = 0;
   // A DFS-based decoding
   while (Data < End) {
-    // Read inline site for inlinees
-    if (Root != Cur) {
+    if (Root == Cur) {
+      // Use a sequential id for outline functions.
+      Index = Root->getChildren().size();
+    } else {
+      // Read inline site for inlinees
       Index = readUnsignedNumber<uint32_t>();
     }
     // Switch/add to a new tree node(inlinee)
@@ -243,10 +245,10 @@
         Addr = readUnencodedNumber<int64_t>();
       }
       // Populate Address2ProbesMap
-      std::vector<PseudoProbe> &ProbeVec = Address2ProbesMap[Addr];
-      ProbeVec.emplace_back(Addr, Cur->GUID, Index, PseudoProbeType(Kind), Attr,
-                            Cur);
-      Cur->addProbes(&ProbeVec.back());
+      auto &Probes = Address2ProbesMap[Addr];
+      Probes.emplace_back(Addr, Cur->GUID, Index, PseudoProbeType(Kind), Attr,
+                          Cur);
+      Cur->addProbes(&Probes.back());
       LastAddr = Addr;
     }
 
@@ -298,7 +300,7 @@
   auto It = Address2ProbesMap.find(Address);
   if (It == Address2ProbesMap.end())
     return nullptr;
-  const std::vector<PseudoProbe> &Probes = It->second;
+  const auto &Probes = It->second;
 
   const PseudoProbe *CallProbe = nullptr;
   for (const auto &Probe : Probes) {
Index: llvm/include/llvm/MC/MCPseudoProbe.h
===================================================================
--- llvm/include/llvm/MC/MCPseudoProbe.h
+++ llvm/include/llvm/MC/MCPseudoProbe.h
@@ -36,7 +36,6 @@
 //        A list of NUM_INLINED_FUNCTIONS entries describing each of the inlined
 //        callees.  Each record contains:
 //          INLINE SITE
-//            GUID of the inlinee (uint64)
 //            ID of the callsite probe (ULEB128)
 //          FUNCTION BODY
 //            A FUNCTION BODY entry describing the inlined function.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D100235.336574.patch
Type: text/x-patch
Size: 3316 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210409/9aedce73/attachment.bin>


More information about the llvm-commits mailing list