[llvm] r276459 - [pdb] Have builders share a single BumpPtrAllocator.

Zachary Turner via llvm-commits llvm-commits at lists.llvm.org
Fri Jul 22 12:56:26 PDT 2016


Author: zturner
Date: Fri Jul 22 14:56:26 2016
New Revision: 276459

URL: http://llvm.org/viewvc/llvm-project?rev=276459&view=rev
Log:
[pdb] Have builders share a single BumpPtrAllocator.

This makes it easier to have the writable and readable PDB
interfaces share code since the read/write and write-only
interfaces now share a single allocator, you don't have to worry
about a builder building a read only interface and then having
the read-only interface's data become corrupt when the builder
goes out of scope.  Now the allocator is specified explicitly
to all constructors, so all interfaces can share a single allocator
that is scoped appropriately.

Modified:
    llvm/trunk/include/llvm/DebugInfo/PDB/Raw/PDBFile.h
    llvm/trunk/include/llvm/DebugInfo/PDB/Raw/PDBFileBuilder.h
    llvm/trunk/include/llvm/DebugInfo/PDB/Raw/RawSession.h
    llvm/trunk/lib/DebugInfo/PDB/Raw/PDBFile.cpp
    llvm/trunk/lib/DebugInfo/PDB/Raw/PDBFileBuilder.cpp
    llvm/trunk/lib/DebugInfo/PDB/Raw/RawSession.cpp
    llvm/trunk/tools/llvm-pdbdump/llvm-pdbdump.cpp

Modified: llvm/trunk/include/llvm/DebugInfo/PDB/Raw/PDBFile.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/DebugInfo/PDB/Raw/PDBFile.h?rev=276459&r1=276458&r2=276459&view=diff
==============================================================================
--- llvm/trunk/include/llvm/DebugInfo/PDB/Raw/PDBFile.h (original)
+++ llvm/trunk/include/llvm/DebugInfo/PDB/Raw/PDBFile.h Fri Jul 22 14:56:26 2016
@@ -42,7 +42,8 @@ class PDBFile : public msf::IMsfFile {
   friend PDBFileBuilder;
 
 public:
-  explicit PDBFile(std::unique_ptr<msf::StreamInterface> PdbFileBuffer);
+  PDBFile(std::unique_ptr<msf::StreamInterface> PdbFileBuffer,
+          BumpPtrAllocator &Allocator);
   ~PDBFile() override;
 
   uint32_t getFreeBlockMapBlock() const;
@@ -89,7 +90,7 @@ public:
 private:
   Error setSuperBlock(const msf::SuperBlock *Block);
 
-  BumpPtrAllocator Allocator;
+  BumpPtrAllocator &Allocator;
 
   std::unique_ptr<msf::StreamInterface> Buffer;
   const msf::SuperBlock *SB;

Modified: llvm/trunk/include/llvm/DebugInfo/PDB/Raw/PDBFileBuilder.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/DebugInfo/PDB/Raw/PDBFileBuilder.h?rev=276459&r1=276458&r2=276459&view=diff
==============================================================================
--- llvm/trunk/include/llvm/DebugInfo/PDB/Raw/PDBFileBuilder.h (original)
+++ llvm/trunk/include/llvm/DebugInfo/PDB/Raw/PDBFileBuilder.h Fri Jul 22 14:56:26 2016
@@ -14,6 +14,7 @@
 #include "llvm/ADT/BitVector.h"
 #include "llvm/ADT/Optional.h"
 #include "llvm/DebugInfo/PDB/Raw/PDBFile.h"
+#include "llvm/Support/Allocator.h"
 #include "llvm/Support/Endian.h"
 #include "llvm/Support/Error.h"
 
@@ -28,11 +29,10 @@ class StreamInterface;
 namespace pdb {
 class DbiStreamBuilder;
 class InfoStreamBuilder;
-class PDBFile;
 
 class PDBFileBuilder {
 public:
-  explicit PDBFileBuilder(std::unique_ptr<msf::StreamInterface> FileBuffer);
+  explicit PDBFileBuilder(BumpPtrAllocator &Allocator);
   PDBFileBuilder(const PDBFileBuilder &) = delete;
   PDBFileBuilder &operator=(const PDBFileBuilder &) = delete;
 
@@ -42,14 +42,15 @@ public:
   InfoStreamBuilder &getInfoBuilder();
   DbiStreamBuilder &getDbiBuilder();
 
-  Expected<std::unique_ptr<PDBFile>> build();
+  Expected<std::unique_ptr<PDBFile>>
+  build(std::unique_ptr<msf::StreamInterface> PdbFileBuffer);
 
 private:
-  std::unique_ptr<InfoStreamBuilder> Info;
-  std::unique_ptr<DbiStreamBuilder> Dbi;
+  BumpPtrAllocator &Allocator;
 
-  std::unique_ptr<PDBFile> File;
   std::unique_ptr<msf::MsfBuilder> Msf;
+  std::unique_ptr<InfoStreamBuilder> Info;
+  std::unique_ptr<DbiStreamBuilder> Dbi;
 };
 }
 }

Modified: llvm/trunk/include/llvm/DebugInfo/PDB/Raw/RawSession.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/DebugInfo/PDB/Raw/RawSession.h?rev=276459&r1=276458&r2=276459&view=diff
==============================================================================
--- llvm/trunk/include/llvm/DebugInfo/PDB/Raw/RawSession.h (original)
+++ llvm/trunk/include/llvm/DebugInfo/PDB/Raw/RawSession.h Fri Jul 22 14:56:26 2016
@@ -12,6 +12,7 @@
 
 #include "llvm/ADT/StringRef.h"
 #include "llvm/DebugInfo/PDB/IPDBSession.h"
+#include "llvm/Support/Allocator.h"
 #include "llvm/Support/Error.h"
 
 namespace llvm {
@@ -20,7 +21,8 @@ class PDBFile;
 
 class RawSession : public IPDBSession {
 public:
-  explicit RawSession(std::unique_ptr<PDBFile> PdbFile);
+  RawSession(std::unique_ptr<PDBFile> PdbFile,
+             std::unique_ptr<BumpPtrAllocator> Allocator);
   ~RawSession() override;
 
   static Error createFromPdb(StringRef Path,
@@ -68,6 +70,7 @@ public:
 
 private:
   std::unique_ptr<PDBFile> Pdb;
+  std::unique_ptr<BumpPtrAllocator> Allocator;
 };
 }
 }

Modified: llvm/trunk/lib/DebugInfo/PDB/Raw/PDBFile.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/PDB/Raw/PDBFile.cpp?rev=276459&r1=276458&r2=276459&view=diff
==============================================================================
--- llvm/trunk/lib/DebugInfo/PDB/Raw/PDBFile.cpp (original)
+++ llvm/trunk/lib/DebugInfo/PDB/Raw/PDBFile.cpp Fri Jul 22 14:56:26 2016
@@ -36,8 +36,9 @@ namespace {
 typedef FixedStreamArray<support::ulittle32_t> ulittle_array;
 }
 
-PDBFile::PDBFile(std::unique_ptr<StreamInterface> PdbFileBuffer)
-    : Buffer(std::move(PdbFileBuffer)), SB(nullptr) {}
+PDBFile::PDBFile(std::unique_ptr<StreamInterface> PdbFileBuffer,
+                 BumpPtrAllocator &Allocator)
+    : Allocator(Allocator), Buffer(std::move(PdbFileBuffer)), SB(nullptr) {}
 
 PDBFile::~PDBFile() {}
 

Modified: llvm/trunk/lib/DebugInfo/PDB/Raw/PDBFileBuilder.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/PDB/Raw/PDBFileBuilder.cpp?rev=276459&r1=276458&r2=276459&view=diff
==============================================================================
--- llvm/trunk/lib/DebugInfo/PDB/Raw/PDBFileBuilder.cpp (original)
+++ llvm/trunk/lib/DebugInfo/PDB/Raw/PDBFileBuilder.cpp Fri Jul 22 14:56:26 2016
@@ -26,12 +26,12 @@ using namespace llvm::msf;
 using namespace llvm::pdb;
 using namespace llvm::support;
 
-PDBFileBuilder::PDBFileBuilder(std::unique_ptr<msf::StreamInterface> FileBuffer)
-    : File(llvm::make_unique<PDBFile>(std::move(FileBuffer))) {}
+PDBFileBuilder::PDBFileBuilder(BumpPtrAllocator &Allocator)
+    : Allocator(Allocator) {}
 
 Error PDBFileBuilder::initialize(const msf::SuperBlock &Super) {
   auto ExpectedMsf =
-      MsfBuilder::create(File->Allocator, Super.BlockSize, Super.NumBlocks);
+      MsfBuilder::create(Allocator, Super.BlockSize, Super.NumBlocks);
   if (!ExpectedMsf)
     return ExpectedMsf.takeError();
 
@@ -54,11 +54,12 @@ InfoStreamBuilder &PDBFileBuilder::getIn
 
 DbiStreamBuilder &PDBFileBuilder::getDbiBuilder() {
   if (!Dbi)
-    Dbi = llvm::make_unique<DbiStreamBuilder>(File->Allocator);
+    Dbi = llvm::make_unique<DbiStreamBuilder>(Allocator);
   return *Dbi;
 }
 
-Expected<std::unique_ptr<PDBFile>> PDBFileBuilder::build() {
+Expected<std::unique_ptr<PDBFile>>
+PDBFileBuilder::build(std::unique_ptr<msf::StreamInterface> PdbFileBuffer) {
   if (Info) {
     uint32_t Length = Info->calculateSerializedLength();
     if (auto EC = Msf->setStreamSize(StreamPDB, Length))
@@ -74,6 +75,7 @@ Expected<std::unique_ptr<PDBFile>> PDBFi
   if (!ExpectedLayout)
     return ExpectedLayout.takeError();
 
+  auto File = llvm::make_unique<PDBFile>(std::move(PdbFileBuffer), Allocator);
   const msf::Layout &L = *ExpectedLayout;
   File->StreamMap = L.StreamMap;
   File->StreamSizes = L.StreamSizes;

Modified: llvm/trunk/lib/DebugInfo/PDB/Raw/RawSession.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/PDB/Raw/RawSession.cpp?rev=276459&r1=276458&r2=276459&view=diff
==============================================================================
--- llvm/trunk/lib/DebugInfo/PDB/Raw/RawSession.cpp (original)
+++ llvm/trunk/lib/DebugInfo/PDB/Raw/RawSession.cpp Fri Jul 22 14:56:26 2016
@@ -41,8 +41,9 @@ public:
 };
 }
 
-RawSession::RawSession(std::unique_ptr<PDBFile> PdbFile)
-    : Pdb(std::move(PdbFile)) {}
+RawSession::RawSession(std::unique_ptr<PDBFile> PdbFile,
+                       std::unique_ptr<BumpPtrAllocator> Allocator)
+    : Pdb(std::move(PdbFile)), Allocator(std::move(Allocator)) {}
 
 RawSession::~RawSession() {}
 
@@ -58,13 +59,15 @@ Error RawSession::createFromPdb(StringRe
   std::unique_ptr<MemoryBuffer> Buffer = std::move(*ErrorOrBuffer);
   auto Stream = llvm::make_unique<InputByteStream>(std::move(Buffer));
 
-  std::unique_ptr<PDBFile> File(new PDBFile(std::move(Stream)));
+  auto Allocator = llvm::make_unique<BumpPtrAllocator>();
+  auto File = llvm::make_unique<PDBFile>(std::move(Stream), *Allocator);
   if (auto EC = File->parseFileHeaders())
     return EC;
   if (auto EC = File->parseStreamData())
     return EC;
 
-  Session.reset(new RawSession(std::move(File)));
+  Session =
+      llvm::make_unique<RawSession>(std::move(File), std::move(Allocator));
 
   return Error::success();
 }

Modified: llvm/trunk/tools/llvm-pdbdump/llvm-pdbdump.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-pdbdump/llvm-pdbdump.cpp?rev=276459&r1=276458&r2=276459&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-pdbdump/llvm-pdbdump.cpp (original)
+++ llvm/trunk/tools/llvm-pdbdump/llvm-pdbdump.cpp Fri Jul 22 14:56:26 2016
@@ -307,6 +307,7 @@ cl::list<std::string> InputFilename(cl::
 static ExitOnError ExitOnErr;
 
 static void yamlToPdb(StringRef Path) {
+  BumpPtrAllocator Allocator;
   ErrorOr<std::unique_ptr<MemoryBuffer>> ErrorOrBuffer =
       MemoryBuffer::getFileOrSTDIN(Path, /*FileSize=*/-1,
                                    /*RequiresNullTerminator=*/false);
@@ -332,7 +333,7 @@ static void yamlToPdb(StringRef Path) {
 
   auto FileByteStream =
       llvm::make_unique<FileBufferByteStream>(std::move(*OutFileOrError));
-  PDBFileBuilder Builder(std::move(FileByteStream));
+  PDBFileBuilder Builder(Allocator);
 
   ExitOnErr(Builder.initialize(YamlObj.Headers->SuperBlock));
   ExitOnErr(Builder.getMsfBuilder().setDirectoryBlocksHint(
@@ -394,7 +395,7 @@ static void yamlToPdb(StringRef Path) {
     }
   }
 
-  auto Pdb = Builder.build();
+  auto Pdb = Builder.build(std::move(FileByteStream));
   ExitOnErr(Pdb.takeError());
 
   auto &PdbFile = *Pdb;




More information about the llvm-commits mailing list