[llvm] cb9f66d - [Profile] Pass InstrProfSymtab instead of IndexedInstrProfReader when creating BinaryCoverageReader

Zequan Wu via llvm-commits llvm-commits at lists.llvm.org
Mon Sep 18 09:44:45 PDT 2023


Author: Zequan Wu
Date: 2023-09-18T12:44:26-04:00
New Revision: cb9f66de8b8e333dc51c3dd1af2193af0133d39a

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

LOG: [Profile] Pass InstrProfSymtab instead of IndexedInstrProfReader when creating BinaryCoverageReader

Only InstrProfSymtab is needed to retrieve function names when debug info corrletaion is enabled.

Added: 
    

Modified: 
    llvm/include/llvm/ProfileData/Coverage/CoverageMappingReader.h
    llvm/lib/ProfileData/Coverage/CoverageMapping.cpp
    llvm/lib/ProfileData/Coverage/CoverageMappingReader.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/ProfileData/Coverage/CoverageMappingReader.h b/llvm/include/llvm/ProfileData/Coverage/CoverageMappingReader.h
index 75cb44a47a81868..051276557892cc7 100644
--- a/llvm/include/llvm/ProfileData/Coverage/CoverageMappingReader.h
+++ b/llvm/include/llvm/ProfileData/Coverage/CoverageMappingReader.h
@@ -203,9 +203,10 @@ class BinaryCoverageReader : public CoverageMappingReader {
   BinaryCoverageReader &operator=(const BinaryCoverageReader &) = delete;
 
   static Expected<std::vector<std::unique_ptr<BinaryCoverageReader>>>
-  create(MemoryBufferRef ObjectBuffer, IndexedInstrProfReader &ProfileReader,
+  create(MemoryBufferRef ObjectBuffer,
          StringRef Arch,
          SmallVectorImpl<std::unique_ptr<MemoryBuffer>> &ObjectFileBuffers,
+         InstrProfSymtab IndexedProfSymTab,
          StringRef CompilationDir = "",
          SmallVectorImpl<object::BuildIDRef> *BinaryIDs = nullptr);
 

diff  --git a/llvm/lib/ProfileData/Coverage/CoverageMapping.cpp b/llvm/lib/ProfileData/Coverage/CoverageMapping.cpp
index f879c73e1e4d6f6..6fa2247682ad5f5 100644
--- a/llvm/lib/ProfileData/Coverage/CoverageMapping.cpp
+++ b/llvm/lib/ProfileData/Coverage/CoverageMapping.cpp
@@ -358,11 +358,12 @@ Error CoverageMapping::loadFromFile(
   MemoryBufferRef CovMappingBufRef =
       CovMappingBufOrErr.get()->getMemBufferRef();
   SmallVector<std::unique_ptr<MemoryBuffer>, 4> Buffers;
+  InstrProfSymtab& ProfSymTab = ProfileReader.getSymtab();
 
   SmallVector<object::BuildIDRef> BinaryIDs;
   auto CoverageReadersOrErr = BinaryCoverageReader::create(
-      CovMappingBufRef, ProfileReader, Arch, Buffers, CompilationDir,
-      FoundBinaryIDs ? &BinaryIDs : nullptr);
+      CovMappingBufRef, Arch, Buffers, ProfSymTab,
+      CompilationDir, FoundBinaryIDs ? &BinaryIDs : nullptr);
   if (Error E = CoverageReadersOrErr.takeError()) {
     E = handleMaybeNoDataFoundError(std::move(E));
     if (E)

diff  --git a/llvm/lib/ProfileData/Coverage/CoverageMappingReader.cpp b/llvm/lib/ProfileData/Coverage/CoverageMappingReader.cpp
index 40ce0ebd25e2bac..f68c234d5da8b47 100644
--- a/llvm/lib/ProfileData/Coverage/CoverageMappingReader.cpp
+++ b/llvm/lib/ProfileData/Coverage/CoverageMappingReader.cpp
@@ -1037,9 +1037,8 @@ static Error getProfileNamesFromDebugInfo(StringRef FileName,
 }
 
 static Expected<std::unique_ptr<BinaryCoverageReader>>
-loadBinaryFormat(std::unique_ptr<Binary> Bin,
-                 IndexedInstrProfReader &ProfileReader, StringRef Arch,
-                 StringRef CompilationDir = "",
+loadBinaryFormat(std::unique_ptr<Binary> Bin, StringRef Arch,
+                 InstrProfSymtab ProfSymTab, StringRef CompilationDir = "",
                  object::BuildIDRef *BinaryID = nullptr) {
   std::unique_ptr<ObjectFile> OF;
   if (auto *Universal = dyn_cast<MachOUniversalBinary>(Bin.get())) {
@@ -1068,7 +1067,12 @@ loadBinaryFormat(std::unique_ptr<Binary> Bin,
 
   // Look for the sections that we are interested in.
   auto ObjFormat = OF->getTripleObjectFormat();
-  InstrProfSymtab ProfileNames = ProfileReader.getSymtab();
+  // Without debug info correlation, all function names are stored in the
+  // binary's profile name section.
+  // When debug info correlation is enabled, instrumented function names are
+  // stored in the indexed profile file, and unused function names are stored in
+  // the binary's debug info.
+  InstrProfSymtab ProfileNames = ProfSymTab;
   auto NamesSection =
       lookupSections(*OF, getInstrProfSectionName(IPSK_name, ObjFormat,
                                                   /*AddSegmentInfo=*/false));
@@ -1086,6 +1090,7 @@ loadBinaryFormat(std::unique_ptr<Binary> Bin,
     if (Error E = ProfileNames.create(NamesSectionRefs.back()))
       return std::move(E);
   }
+
   auto CoverageSection =
       lookupSections(*OF, getInstrProfSectionName(IPSK_covmap, ObjFormat,
                                                   /*AddSegmentInfo=*/false));
@@ -1169,10 +1174,10 @@ static bool isArchSpecifierInvalidOrMissing(Binary *Bin, StringRef Arch) {
 
 Expected<std::vector<std::unique_ptr<BinaryCoverageReader>>>
 BinaryCoverageReader::create(
-    MemoryBufferRef ObjectBuffer, IndexedInstrProfReader &ProfileReader,
-    StringRef Arch,
+    MemoryBufferRef ObjectBuffer, StringRef Arch,
     SmallVectorImpl<std::unique_ptr<MemoryBuffer>> &ObjectFileBuffers,
-    StringRef CompilationDir, SmallVectorImpl<object::BuildIDRef> *BinaryIDs) {
+    InstrProfSymtab ProfSymTab, StringRef CompilationDir,
+    SmallVectorImpl<object::BuildIDRef> *BinaryIDs) {
   std::vector<std::unique_ptr<BinaryCoverageReader>> Readers;
 
   if (ObjectBuffer.getBuffer().size() > sizeof(TestingFormatMagic)) {
@@ -1216,8 +1221,8 @@ BinaryCoverageReader::create(
       }
 
       return BinaryCoverageReader::create(
-          ArchiveOrErr.get()->getMemoryBufferRef(), ProfileReader, Arch,
-          ObjectFileBuffers, CompilationDir, BinaryIDs);
+          ArchiveOrErr.get()->getMemoryBufferRef(), Arch,
+          ObjectFileBuffers, ProfSymTab, CompilationDir, BinaryIDs);
     }
   }
 
@@ -1230,7 +1235,7 @@ BinaryCoverageReader::create(
         return ChildBufOrErr.takeError();
 
       auto ChildReadersOrErr = BinaryCoverageReader::create(
-          ChildBufOrErr.get(), ProfileReader, Arch, ObjectFileBuffers,
+          ChildBufOrErr.get(), Arch, ObjectFileBuffers, ProfSymTab,
           CompilationDir, BinaryIDs);
       if (!ChildReadersOrErr)
         return ChildReadersOrErr.takeError();
@@ -1252,7 +1257,7 @@ BinaryCoverageReader::create(
 
   object::BuildIDRef BinaryID;
   auto ReaderOrErr =
-      loadBinaryFormat(std::move(Bin), ProfileReader, Arch, CompilationDir,
+      loadBinaryFormat(std::move(Bin), Arch, ProfSymTab, CompilationDir,
                        BinaryIDs ? &BinaryID : nullptr);
   if (!ReaderOrErr)
     return ReaderOrErr.takeError();


        


More information about the llvm-commits mailing list