[llvm] r270960 - [codeview] Remove StreamReader copying method.

Zachary Turner via llvm-commits llvm-commits at lists.llvm.org
Thu May 26 20:51:54 PDT 2016


Author: zturner
Date: Thu May 26 22:51:53 2016
New Revision: 270960

URL: http://llvm.org/viewvc/llvm-project?rev=270960&view=rev
Log:
[codeview] Remove StreamReader copying method.

Since we want to move toward zero-copy access to stream data, we
want to remove all instances of copying operations.  So get rid
of some of those here.

Differential Revision: http://reviews.llvm.org/D20720
Reviewed By: ruiu

Modified:
    llvm/trunk/include/llvm/DebugInfo/CodeView/StreamReader.h
    llvm/trunk/include/llvm/DebugInfo/PDB/Raw/NameHashTable.h
    llvm/trunk/include/llvm/DebugInfo/PDB/Raw/PublicsStream.h
    llvm/trunk/include/llvm/DebugInfo/PDB/Raw/RawConstants.h
    llvm/trunk/include/llvm/Support/ScopedPrinter.h
    llvm/trunk/lib/DebugInfo/PDB/Raw/NameHashTable.cpp
    llvm/trunk/lib/DebugInfo/PDB/Raw/PublicsStream.cpp
    llvm/trunk/tools/llvm-pdbdump/llvm-pdbdump.cpp

Modified: llvm/trunk/include/llvm/DebugInfo/CodeView/StreamReader.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/DebugInfo/CodeView/StreamReader.h?rev=270960&r1=270959&r2=270960&view=diff
==============================================================================
--- llvm/trunk/include/llvm/DebugInfo/CodeView/StreamReader.h (original)
+++ llvm/trunk/include/llvm/DebugInfo/CodeView/StreamReader.h Thu May 26 22:51:53 2016
@@ -29,13 +29,13 @@ public:
   StreamReader(const StreamInterface &S);
 
   Error readBytes(uint32_t Size, ArrayRef<uint8_t> &Buffer);
-  Error readBytes(MutableArrayRef<uint8_t> Buffer);
   Error readInteger(uint16_t &Dest);
   Error readInteger(uint32_t &Dest);
   Error readZeroString(StringRef &Dest);
   Error readFixedString(StringRef &Dest, uint32_t Length);
   Error readStreamRef(StreamRef &Ref);
   Error readStreamRef(StreamRef &Ref, uint32_t Length);
+  Error readBytes(MutableArrayRef<uint8_t> Buffer);
 
   template <typename T> Error readObject(const T *&Dest) {
     ArrayRef<uint8_t> Buffer;
@@ -60,12 +60,6 @@ public:
     return Error::success();
   }
 
-  template <typename T> Error readArray(MutableArrayRef<T> Array) {
-    MutableArrayRef<uint8_t> Casted(reinterpret_cast<uint8_t *>(Array.data()),
-                                    Array.size() * sizeof(T));
-    return readBytes(Casted);
-  }
-
   void setOffset(uint32_t Off) { Offset = Off; }
   uint32_t getOffset() const { return Offset; }
   uint32_t getLength() const { return Stream.getLength(); }

Modified: llvm/trunk/include/llvm/DebugInfo/PDB/Raw/NameHashTable.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/DebugInfo/PDB/Raw/NameHashTable.h?rev=270960&r1=270959&r2=270960&view=diff
==============================================================================
--- llvm/trunk/include/llvm/DebugInfo/PDB/Raw/NameHashTable.h (original)
+++ llvm/trunk/include/llvm/DebugInfo/PDB/Raw/NameHashTable.h Thu May 26 22:51:53 2016
@@ -12,7 +12,9 @@
 
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/StringRef.h"
+#include "llvm/DebugInfo/CodeView/StreamArray.h"
 #include "llvm/DebugInfo/CodeView/StreamRef.h"
+#include "llvm/Support/Endian.h"
 #include "llvm/Support/Error.h"
 #include <cstdint>
 #include <vector>
@@ -36,11 +38,11 @@ public:
   StringRef getStringForID(uint32_t ID) const;
   uint32_t getIDForString(StringRef Str) const;
 
-  ArrayRef<uint32_t> name_ids() const;
+  codeview::FixedStreamArray<support::ulittle32_t> name_ids() const;
 
 private:
   codeview::StreamRef NamesBuffer;
-  std::vector<uint32_t> IDs;
+  codeview::FixedStreamArray<support::ulittle32_t> IDs;
   uint32_t Signature;
   uint32_t HashVersion;
   uint32_t NameCount;

Modified: llvm/trunk/include/llvm/DebugInfo/PDB/Raw/PublicsStream.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/DebugInfo/PDB/Raw/PublicsStream.h?rev=270960&r1=270959&r2=270960&view=diff
==============================================================================
--- llvm/trunk/include/llvm/DebugInfo/PDB/Raw/PublicsStream.h (original)
+++ llvm/trunk/include/llvm/DebugInfo/PDB/Raw/PublicsStream.h Thu May 26 22:51:53 2016
@@ -10,6 +10,7 @@
 #ifndef LLVM_DEBUGINFO_PDB_RAW_PUBLICSSTREAM_H
 #define LLVM_DEBUGINFO_PDB_RAW_PUBLICSSTREAM_H
 
+#include "llvm/DebugInfo/CodeView/StreamArray.h"
 #include "llvm/DebugInfo/CodeView/SymbolRecord.h"
 #include "llvm/DebugInfo/CodeView/TypeStream.h"
 #include "llvm/DebugInfo/PDB/PDBTypes.h"
@@ -25,7 +26,6 @@ class PDBFile;
 
 class PublicsStream {
   struct GSIHashHeader;
-  struct HashRecord;
   struct HeaderInfo;
 
 public:
@@ -38,10 +38,18 @@ public:
   uint32_t getAddrMap() const;
   uint32_t getNumBuckets() const { return NumBuckets; }
   iterator_range<codeview::SymbolIterator> getSymbols() const;
-  ArrayRef<uint32_t> getHashBuckets() const { return HashBuckets; }
-  ArrayRef<uint32_t> getAddressMap() const { return AddressMap; }
-  ArrayRef<uint32_t> getThunkMap() const { return ThunkMap; }
-  ArrayRef<uint32_t> getSectionOffsets() const { return SectionOffsets; }
+  codeview::FixedStreamArray<support::ulittle32_t> getHashBuckets() const {
+    return HashBuckets;
+  }
+  codeview::FixedStreamArray<support::ulittle32_t> getAddressMap() const {
+    return AddressMap;
+  }
+  codeview::FixedStreamArray<support::ulittle32_t> getThunkMap() const {
+    return ThunkMap;
+  }
+  codeview::FixedStreamArray<SectionOffset> getSectionOffsets() const {
+    return SectionOffsets;
+  }
 
 private:
   Error readSymbols();
@@ -51,11 +59,12 @@ private:
   uint32_t StreamNum;
   MappedBlockStream Stream;
   uint32_t NumBuckets = 0;
-  std::vector<HashRecord> HashRecords;
-  std::vector<uint32_t> HashBuckets;
-  std::vector<uint32_t> AddressMap;
-  std::vector<uint32_t> ThunkMap;
-  std::vector<uint32_t> SectionOffsets;
+  ArrayRef<uint8_t> Bitmap;
+  codeview::FixedStreamArray<PSHashRecord> HashRecords;
+  codeview::FixedStreamArray<support::ulittle32_t> HashBuckets;
+  codeview::FixedStreamArray<support::ulittle32_t> AddressMap;
+  codeview::FixedStreamArray<support::ulittle32_t> ThunkMap;
+  codeview::FixedStreamArray<SectionOffset> SectionOffsets;
 
   const HeaderInfo *Header;
   const GSIHashHeader *HashHdr;

Modified: llvm/trunk/include/llvm/DebugInfo/PDB/Raw/RawConstants.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/DebugInfo/PDB/Raw/RawConstants.h?rev=270960&r1=270959&r2=270960&view=diff
==============================================================================
--- llvm/trunk/include/llvm/DebugInfo/PDB/Raw/RawConstants.h (original)
+++ llvm/trunk/include/llvm/DebugInfo/PDB/Raw/RawConstants.h Thu May 26 22:51:53 2016
@@ -10,6 +10,8 @@
 #ifndef LLVM_DEBUGINFO_PDB_RAW_PDBRAWCONSTANTS_H
 #define LLVM_DEBUGINFO_PDB_RAW_PDBRAWCONSTANTS_H
 
+#include "llvm/Support/Endian.h"
+
 #include <cstdint>
 
 namespace llvm {
@@ -71,6 +73,19 @@ enum class DbgHeaderType : uint16_t {
   Max
 };
 
+// This struct is defined as "SO" in langapi/include/pdb.h.
+struct SectionOffset {
+  support::ulittle32_t Off;
+  support::ulittle16_t Isect;
+  char Padding[2];
+};
+
+// This is HRFile.
+struct PSHashRecord {
+  support::ulittle32_t Off; // Offset in the symbol record stream
+  support::ulittle32_t CRef;
+};
+
 } // end namespace pdb
 } // end namespace llvm
 

Modified: llvm/trunk/include/llvm/Support/ScopedPrinter.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/ScopedPrinter.h?rev=270960&r1=270959&r2=270960&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Support/ScopedPrinter.h (original)
+++ llvm/trunk/include/llvm/Support/ScopedPrinter.h Thu May 26 22:51:53 2016
@@ -211,6 +211,19 @@ public:
     OS << "]\n";
   }
 
+  template <typename T, typename U>
+  void printList(StringRef Label, const T &List, const U &Printer) {
+    startLine() << Label << ": [";
+    bool Comma = false;
+    for (const auto &Item : List) {
+      if (Comma)
+        OS << ", ";
+      Printer(OS, Item);
+      Comma = true;
+    }
+    OS << "]\n";
+  }
+
   template <typename T> void printHexList(StringRef Label, const T &List) {
     startLine() << Label << ": [";
     bool Comma = false;

Modified: llvm/trunk/lib/DebugInfo/PDB/Raw/NameHashTable.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/PDB/Raw/NameHashTable.cpp?rev=270960&r1=270959&r2=270960&view=diff
==============================================================================
--- llvm/trunk/lib/DebugInfo/PDB/Raw/NameHashTable.cpp (original)
+++ llvm/trunk/lib/DebugInfo/PDB/Raw/NameHashTable.cpp Thu May 26 22:51:53 2016
@@ -105,11 +105,9 @@ Error NameHashTable::load(codeview::Stre
   if (auto EC = Stream.readObject(HashCount))
     return EC;
 
-  std::vector<support::ulittle32_t> BucketArray(*HashCount);
-  if (auto EC = Stream.readArray<support::ulittle32_t>(BucketArray))
+  if (auto EC = Stream.readArray(IDs, *HashCount))
     return make_error<RawError>(raw_error_code::corrupt_file,
                                 "Could not read bucket array");
-  IDs.assign(BucketArray.begin(), BucketArray.end());
 
   if (Stream.bytesRemaining() < sizeof(support::ulittle32_t))
     return make_error<RawError>(raw_error_code::corrupt_file,
@@ -154,4 +152,7 @@ uint32_t NameHashTable::getIDForString(S
   return IDs[0];
 }
 
-ArrayRef<uint32_t> NameHashTable::name_ids() const { return IDs; }
+codeview::FixedStreamArray<support::ulittle32_t>
+NameHashTable::name_ids() const {
+  return IDs;
+}

Modified: llvm/trunk/lib/DebugInfo/PDB/Raw/PublicsStream.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/PDB/Raw/PublicsStream.cpp?rev=270960&r1=270959&r2=270960&view=diff
==============================================================================
--- llvm/trunk/lib/DebugInfo/PDB/Raw/PublicsStream.cpp (original)
+++ llvm/trunk/lib/DebugInfo/PDB/Raw/PublicsStream.cpp Thu May 26 22:51:53 2016
@@ -70,21 +70,6 @@ struct PublicsStream::GSIHashHeader {
   ulittle32_t NumBuckets;
 };
 
-// This is HRFile.
-struct PublicsStream::HashRecord {
-  ulittle32_t Off; // Offset in the symbol record stream
-  ulittle32_t CRef;
-};
-
-// This struct is defined as "SO" in langapi/include/pdb.h.
-namespace {
-struct SectionOffset {
-  ulittle32_t Off;
-  ulittle16_t Isect;
-  char Padding[2];
-};
-}
-
 PublicsStream::PublicsStream(PDBFile &File, uint32_t StreamNum)
     : Pdb(File), StreamNum(StreamNum), Stream(StreamNum, File) {}
 
@@ -116,18 +101,18 @@ Error PublicsStream::reload() {
                                 "Publics Stream does not contain a header.");
 
   // An array of HashRecord follows. Read them.
-  if (HashHdr->HrSize % sizeof(HashRecord))
+  if (HashHdr->HrSize % sizeof(PSHashRecord))
     return make_error<RawError>(raw_error_code::corrupt_file,
                                 "Invalid HR array size.");
-  HashRecords.resize(HashHdr->HrSize / sizeof(HashRecord));
-  if (auto EC = Reader.readArray<HashRecord>(HashRecords))
+  uint32_t NumHashRecords = HashHdr->HrSize / sizeof(PSHashRecord);
+  if (auto EC = Reader.readArray(HashRecords, NumHashRecords))
     return make_error<RawError>(raw_error_code::corrupt_file,
                                 "Could not read an HR array");
 
   // A bitmap of a fixed length follows.
   size_t BitmapSizeInBits = alignTo(IPHR_HASH + 1, 32);
-  std::vector<uint8_t> Bitmap(BitmapSizeInBits / 8);
-  if (auto EC = Reader.readArray<uint8_t>(Bitmap))
+  uint32_t NumBitmapEntries = BitmapSizeInBits / 8;
+  if (auto EC = Reader.readBytes(NumBitmapEntries, Bitmap))
     return make_error<RawError>(raw_error_code::corrupt_file,
                                 "Could not read a bitmap.");
   for (uint8_t B : Bitmap)
@@ -139,40 +124,25 @@ Error PublicsStream::reload() {
   // corrupted streams.
 
   // Hash buckets follow.
-  std::vector<ulittle32_t> TempHashBuckets(NumBuckets);
-  if (auto EC = Reader.readArray<ulittle32_t>(TempHashBuckets))
+  if (auto EC = Reader.readArray(HashBuckets, NumBuckets))
     return make_error<RawError>(raw_error_code::corrupt_file,
                                 "Hash buckets corrupted.");
-  HashBuckets.resize(NumBuckets);
-  std::copy(TempHashBuckets.begin(), TempHashBuckets.end(),
-            HashBuckets.begin());
 
   // Something called "address map" follows.
-  std::vector<ulittle32_t> TempAddressMap(Header->AddrMap / sizeof(uint32_t));
-  if (auto EC = Reader.readArray<ulittle32_t>(TempAddressMap))
+  uint32_t NumAddressMapEntries = Header->AddrMap / sizeof(uint32_t);
+  if (auto EC = Reader.readArray(AddressMap, NumAddressMapEntries))
     return make_error<RawError>(raw_error_code::corrupt_file,
                                 "Could not read an address map.");
-  AddressMap.resize(Header->AddrMap / sizeof(uint32_t));
-  std::copy(TempAddressMap.begin(), TempAddressMap.end(), AddressMap.begin());
 
   // Something called "thunk map" follows.
-  std::vector<ulittle32_t> TempThunkMap(Header->NumThunks);
-  ThunkMap.resize(Header->NumThunks);
-  if (auto EC = Reader.readArray<ulittle32_t>(TempThunkMap))
+  if (auto EC = Reader.readArray(ThunkMap, Header->NumThunks))
     return make_error<RawError>(raw_error_code::corrupt_file,
                                 "Could not read a thunk map.");
-  ThunkMap.resize(Header->NumThunks);
-  std::copy(TempThunkMap.begin(), TempThunkMap.end(), ThunkMap.begin());
 
   // Something called "section map" follows.
-  std::vector<SectionOffset> Offsets(Header->NumSections);
-  if (auto EC = Reader.readArray<SectionOffset>(Offsets))
+  if (auto EC = Reader.readArray(SectionOffsets, Header->NumSections))
     return make_error<RawError>(raw_error_code::corrupt_file,
                                 "Could not read a section map.");
-  for (auto &SO : Offsets) {
-    SectionOffsets.push_back(SO.Off);
-    SectionOffsets.push_back(SO.Isect);
-  }
 
   if (Reader.bytesRemaining() > 0)
     return make_error<RawError>(raw_error_code::corrupt_file,

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=270960&r1=270959&r2=270960&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-pdbdump/llvm-pdbdump.cpp (original)
+++ llvm/trunk/tools/llvm-pdbdump/llvm-pdbdump.cpp Thu May 26 22:51:53 2016
@@ -569,6 +569,11 @@ static Error dumpTpiStream(ScopedPrinter
   return Error::success();
 }
 
+static void printSectionOffset(llvm::raw_ostream &OS,
+                               const SectionOffset &Off) {
+  OS << Off.Off << ", " << Off.Isect;
+}
+
 static Error dumpPublicsStream(ScopedPrinter &P, PDBFile &File,
                                codeview::CVTypeDumper &TD) {
   if (!opts::DumpPublics)
@@ -586,7 +591,8 @@ static Error dumpPublicsStream(ScopedPri
   P.printList("Hash Buckets", Publics.getHashBuckets());
   P.printList("Address Map", Publics.getAddressMap());
   P.printList("Thunk Map", Publics.getThunkMap());
-  P.printList("Section Offsets", Publics.getSectionOffsets());
+  P.printList("Section Offsets", Publics.getSectionOffsets(),
+              printSectionOffset);
   ListScope L(P, "Symbols");
   codeview::CVSymbolDumper SD(P, TD, nullptr, false);
   for (auto S : Publics.getSymbols()) {




More information about the llvm-commits mailing list