[PATCH] D65162: [llvm-profdata] Profile dump for compact binary format

Wenlei He via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Jul 23 11:50:42 PDT 2019


wenlei created this revision.
wenlei added reviewers: wmi, davidxl, danielcdh.
Herald added subscribers: llvm-commits, hiraditya.
Herald added a project: LLVM.

Fix "llvm-profdata show" so it can work with compact binary format profile. The change is to mark all functions "used" so SampleProfileReaderCompactBinary::read will read in all profiles available for dumping. The function names will be MD5 hash for compact binary format.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D65162

Files:
  llvm/include/llvm/ProfileData/SampleProfReader.h
  llvm/lib/ProfileData/SampleProfReader.cpp
  llvm/test/tools/llvm-profdata/Inputs/compat-sample.profdata
  llvm/test/tools/llvm-profdata/compact-sample.proftext
  llvm/tools/llvm-profdata/llvm-profdata.cpp


Index: llvm/tools/llvm-profdata/llvm-profdata.cpp
===================================================================
--- llvm/tools/llvm-profdata/llvm-profdata.cpp
+++ llvm/tools/llvm-profdata/llvm-profdata.cpp
@@ -955,6 +955,7 @@
     exitWithErrorCode(EC, Filename);
 
   auto Reader = std::move(ReaderOrErr.get());
+  Reader->markAllFuncToUse();
   if (std::error_code EC = Reader->read())
     exitWithErrorCode(EC, Filename);
 
Index: llvm/test/tools/llvm-profdata/compact-sample.proftext
===================================================================
--- /dev/null
+++ llvm/test/tools/llvm-profdata/compact-sample.proftext
@@ -0,0 +1,8 @@
+# Make sure "llvm-profdata show" works for sample profile in binary compact format
+
+# RUN: llvm-profdata show -sample %S/Inputs/compat-sample.profdata  | FileCheck %s 
+
+# CHECK: Function: 15822663052811949562: 17, 0, 6 sampled lines 
+# CHECK-NEXT: Samples collected in the function's body {
+# CHECK: Samples collected in inlined callsites {
+# CHECK-NEXT: 1: inlined callee: 6309742469962978389: 17, 0, 1
Index: llvm/lib/ProfileData/SampleProfReader.cpp
===================================================================
--- llvm/lib/ProfileData/SampleProfReader.cpp
+++ llvm/lib/ProfileData/SampleProfReader.cpp
@@ -468,14 +468,26 @@
 }
 
 std::error_code SampleProfileReaderCompactBinary::read() {
-  for (auto Name : FuncsToUse) {
-    auto GUID = std::to_string(MD5Hash(Name));
-    auto iter = FuncOffsetTable.find(StringRef(GUID));
-    if (iter == FuncOffsetTable.end())
-      continue;
+  std::vector<uint64_t> OffsetsToUse;
+  if (UseAllFuncs) {
+    for (auto FuncEntry : FuncOffsetTable) {
+      OffsetsToUse.push_back(FuncEntry.second);
+    }
+  }
+  else {
+    for (auto Name : FuncsToUse) {
+      auto GUID = std::to_string(MD5Hash(Name));
+      auto iter = FuncOffsetTable.find(StringRef(GUID));
+      if (iter == FuncOffsetTable.end())
+        continue;
+      OffsetsToUse.push_back(iter->second);
+    }
+  }
+
+  for (auto Offset : OffsetsToUse) {
     const uint8_t *SavedData = Data;
     Data = reinterpret_cast<const uint8_t *>(Buffer->getBufferStart()) +
-           iter->second;
+           Offset;
     if (std::error_code EC = readFuncProfile())
       return EC;
     Data = SavedData;
Index: llvm/include/llvm/ProfileData/SampleProfReader.h
===================================================================
--- llvm/include/llvm/ProfileData/SampleProfReader.h
+++ llvm/include/llvm/ProfileData/SampleProfReader.h
@@ -281,6 +281,8 @@
 
   virtual void collectFuncsToUse(const Module &M) {}
 
+  virtual void markAllFuncToUse() {}
+
   /// Print all the profiles on stream \p OS.
   void dump(raw_ostream &OS = dbgs());
 
@@ -462,6 +464,8 @@
   DenseMap<StringRef, uint64_t> FuncOffsetTable;
   /// The set containing the functions to use when compiling a module.
   DenseSet<StringRef> FuncsToUse;
+  /// Use all functions from the input profile.
+  bool UseAllFuncs = false;
   virtual std::error_code verifySPMagic(uint64_t Magic) override;
   virtual std::error_code readNameTable() override;
   /// Read a string indirectly via the name table.
@@ -482,6 +486,9 @@
 
   /// Collect functions to be used when compiling Module \p M.
   void collectFuncsToUse(const Module &M) override;
+
+  /// Ignore FuncsToUse set and use all functions from input profile.
+  void markAllFuncToUse() override { UseAllFuncs = true; }
 };
 
 using InlineCallStack = SmallVector<FunctionSamples *, 10>;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D65162.211344.patch
Type: text/x-patch
Size: 3485 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190723/fdc65a06/attachment.bin>


More information about the llvm-commits mailing list