[PATCH] D136394: [Bolt][PseudoProbe] Support new pseudo probe encoding

Hongtao Yu via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Oct 20 16:48:27 PDT 2022


hoy created this revision.
Herald added subscribers: treapster, ayermolo, modimo, wenlei.
Herald added a reviewer: rafauler.
Herald added a reviewer: Amir.
Herald added a reviewer: maksfb.
Herald added a project: All.
hoy requested review of this revision.
Herald added subscribers: llvm-commits, yota9.
Herald added a project: LLVM.

Test Plan:


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D136394

Files:
  bolt/lib/Rewrite/RewriteInstance.cpp


Index: bolt/lib/Rewrite/RewriteInstance.cpp
===================================================================
--- bolt/lib/Rewrite/RewriteInstance.cpp
+++ bolt/lib/Rewrite/RewriteInstance.cpp
@@ -607,10 +607,18 @@
     errs() << "BOLT-WARNING: fail in building GUID2FuncDescMap\n";
     return;
   }
+
+  std::unordered_set<uint64_t> GuidFilter;
+  std::unordered_map<uint64_t, uint64_t> FuncStartAddrs;
+  for (const auto *F : BC->getAllBinaryFunctions()) {
+    for (const auto *Sym : F->getSymbols()) {
+      FuncStartAddrs.emplace(Function::getGUID(NameResolver::restore(Sym->getName())), F->getAddress());
+    }
+  }
   Contents = PseudoProbeSection->getContents();
   if (!BC->ProbeDecoder.buildAddress2ProbeMap(
-          reinterpret_cast<const uint8_t *>(Contents.data()),
-          Contents.size())) {
+          reinterpret_cast<const uint8_t *>(Contents.data()), Contents.size(),
+          GuidFilter, FuncStartAddrs)) {
     BC->ProbeDecoder.getAddress2ProbesMap().clear();
     errs() << "BOLT-WARNING: fail in building Address2ProbeMap\n";
     return;
@@ -3407,6 +3415,8 @@
   // Address of the first probe is absolute.
   // Other probes' address are represented by delta
   auto EmitDecodedPseudoProbe = [&](MCDecodedPseudoProbe *&CurProbe) {
+    assert(!isSentinelProbe(CurProbe->getAttributes()) &&
+           "Sentinel probes should not be emitted");
     EmitULEB128IntValue(CurProbe->getIndex());
     uint8_t PackedType = CurProbe->getType() | (CurProbe->getAttributes() << 4);
     uint8_t Flag =
@@ -3511,9 +3521,15 @@
         reinterpret_cast<const uint8_t *>(DescContents.data()),
         DescContents.size());
     StringRef ProbeContents = PseudoProbeSection->getOutputContents();
+    std::unordered_set<uint64_t> GuidFilter;
+    std::unordered_map<uint64_t, uint64_t> FuncStartAddrs;
+    for (const auto *F : BC->getAllBinaryFunctions()) {
+      uint64_t Addr = F->isEmitted() ? F->getOutputAddress() : F->getAddress();
+      FuncStartAddrs.emplace(Function::getGUID(NameResolver::restore(F->getOneName())), Addr);
+    }
     DummyDecoder.buildAddress2ProbeMap(
         reinterpret_cast<const uint8_t *>(ProbeContents.data()),
-        ProbeContents.size());
+        ProbeContents.size(), GuidFilter, FuncStartAddrs);
     DummyDecoder.printProbesForAllAddresses(outs());
   }
 }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D136394.469409.patch
Type: text/x-patch
Size: 2329 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20221020/ae0de8c8/attachment.bin>


More information about the llvm-commits mailing list