From 26dbc5420dba8552835eb9b12768ffc3ebac26f7 Mon Sep 17 00:00:00 2001 From: Zachary Turner Date: Sun, 18 Jun 2017 20:52:45 +0000 Subject: Delete TypeDatabase. Merge the functionality into the random access type collection. This class was only being used in 2 places, so getting rid of it simplifies the code. llvm-svn: 305653 --- llvm/include/llvm/DebugInfo/CodeView/CVRecord.h | 5 +- .../DebugInfo/CodeView/LazyRandomTypeCollection.h | 40 +++++------ .../include/llvm/DebugInfo/CodeView/TypeDatabase.h | 84 ---------------------- .../llvm/DebugInfo/CodeView/TypeDatabaseVisitor.h | 62 ---------------- .../llvm/DebugInfo/CodeView/TypeTableCollection.h | 11 +-- 5 files changed, 28 insertions(+), 174 deletions(-) delete mode 100644 llvm/include/llvm/DebugInfo/CodeView/TypeDatabase.h delete mode 100644 llvm/include/llvm/DebugInfo/CodeView/TypeDatabaseVisitor.h (limited to 'llvm/include') diff --git a/llvm/include/llvm/DebugInfo/CodeView/CVRecord.h b/llvm/include/llvm/DebugInfo/CodeView/CVRecord.h index 4c6bbedc6bb..44040e04388 100644 --- a/llvm/include/llvm/DebugInfo/CodeView/CVRecord.h +++ b/llvm/include/llvm/DebugInfo/CodeView/CVRecord.h @@ -27,9 +27,12 @@ namespace codeview { template class CVRecord { public: - CVRecord() = default; + CVRecord() : Type(static_cast(0)) {} + CVRecord(Kind K, ArrayRef Data) : Type(K), RecordData(Data) {} + bool valid() const { return Type != static_cast(0); } + uint32_t length() const { return RecordData.size(); } Kind kind() const { return Type; } ArrayRef data() const { return RecordData; } diff --git a/llvm/include/llvm/DebugInfo/CodeView/LazyRandomTypeCollection.h b/llvm/include/llvm/DebugInfo/CodeView/LazyRandomTypeCollection.h index 950815ef897..3c678d6169c 100644 --- a/llvm/include/llvm/DebugInfo/CodeView/LazyRandomTypeCollection.h +++ b/llvm/include/llvm/DebugInfo/CodeView/LazyRandomTypeCollection.h @@ -11,18 +11,15 @@ #define LLVM_DEBUGINFO_CODEVIEW_LAZYRANDOMTYPECOLLECTION_H #include "llvm/DebugInfo/CodeView/TypeCollection.h" -#include "llvm/DebugInfo/CodeView/TypeDatabase.h" -#include "llvm/DebugInfo/CodeView/TypeDatabaseVisitor.h" #include "llvm/DebugInfo/CodeView/TypeIndex.h" #include "llvm/DebugInfo/CodeView/TypeRecord.h" +#include "llvm/Support/Allocator.h" #include "llvm/Support/Error.h" +#include "llvm/Support/StringSaver.h" namespace llvm { namespace codeview { -class TypeDatabase; -class TypeVisitorCallbacks; - /// \brief Provides amortized O(1) random access to a CodeView type stream. /// Normally to access a type from a type stream, you must know its byte /// offset into the type stream, because type records are variable-lengthed. @@ -47,6 +44,11 @@ class TypeVisitorCallbacks; /// of O(N/M) and an amortized time of O(1). class LazyRandomTypeCollection : public TypeCollection { typedef FixedStreamArray PartialOffsetArray; + struct CacheEntry { + CVType Type; + uint32_t Offset; + StringRef Name; + }; public: explicit LazyRandomTypeCollection(uint32_t RecordCountHint); @@ -56,8 +58,8 @@ public: PartialOffsetArray PartialOffsets); LazyRandomTypeCollection(const CVTypeArray &Types, uint32_t RecordCountHint); - void reset(ArrayRef Data); - void reset(StringRef Data); + void reset(ArrayRef Data, uint32_t RecordCountHint); + void reset(StringRef Data, uint32_t RecordCountHint); CVType getType(TypeIndex Index) override; StringRef getTypeName(TypeIndex Index) override; @@ -68,32 +70,26 @@ public: Optional getNext(TypeIndex Prev) override; private: - const TypeDatabase &database() const { return Database; } Error ensureTypeExists(TypeIndex Index); + void ensureCapacityFor(TypeIndex Index); Error visitRangeForType(TypeIndex TI); Error fullScanForType(TypeIndex TI); - Error visitRange(TypeIndex Begin, uint32_t BeginOffset, TypeIndex End); - Error visitOneRecord(TypeIndex TI, uint32_t Offset, CVType &Record); + void visitRange(TypeIndex Begin, uint32_t BeginOffset, TypeIndex End); - BumpPtrAllocator Allocator; - StringSaver NameStorage; + /// Number of actual records. + uint32_t Count = 0; - SmallVector TypeNames; + /// The largest type index which we've visited. + TypeIndex LargestTypeIndex = TypeIndex::None(); - /// Visited records get automatically added to the type database. - TypeDatabase Database; + BumpPtrAllocator Allocator; + StringSaver NameStorage; /// The type array to allow random access visitation of. CVTypeArray Types; - /// The database visitor which adds new records to the database. - TypeDatabaseVisitor DatabaseVisitor; - - /// A vector mapping type indices to type offset. For every record that has - /// been visited, contains the absolute offset of that record in the record - /// array. - std::vector KnownOffsets; + std::vector Records; /// An array of index offsets for the given type stream, allowing log(N) /// lookups of a type record by index. Similar to KnownOffsets but only diff --git a/llvm/include/llvm/DebugInfo/CodeView/TypeDatabase.h b/llvm/include/llvm/DebugInfo/CodeView/TypeDatabase.h deleted file mode 100644 index a743e7f7085..00000000000 --- a/llvm/include/llvm/DebugInfo/CodeView/TypeDatabase.h +++ /dev/null @@ -1,84 +0,0 @@ -//===- TypeDatabase.h - A collection of CodeView type records ---*- C++ -*-===// -// -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// - -#ifndef LLVM_DEBUGINFO_CODEVIEW_TYPEDATABASE_H -#define LLVM_DEBUGINFO_CODEVIEW_TYPEDATABASE_H - -#include "llvm/ADT/BitVector.h" -#include "llvm/ADT/SmallVector.h" -#include "llvm/ADT/StringRef.h" -#include "llvm/DebugInfo/CodeView/TypeCollection.h" -#include "llvm/DebugInfo/CodeView/TypeIndex.h" -#include "llvm/DebugInfo/CodeView/TypeRecord.h" -#include "llvm/Support/Allocator.h" -#include "llvm/Support/StringSaver.h" - -namespace llvm { -namespace codeview { -class TypeDatabase : public TypeCollection { - friend class RandomAccessTypeVisitor; - -public: - explicit TypeDatabase(uint32_t Capacity); - - /// Records the name of a type, and reserves its type index. - TypeIndex appendType(StringRef Name, const CVType &Data); - - /// Records the name of a type, and reserves its type index. - void recordType(StringRef Name, TypeIndex Index, const CVType &Data); - - /// Saves the name in a StringSet and creates a stable StringRef. - StringRef saveTypeName(StringRef TypeName); - - StringRef getTypeName(TypeIndex Index) const; - - const CVType &getTypeRecord(TypeIndex Index) const; - CVType &getTypeRecord(TypeIndex Index); - - bool contains(TypeIndex Index) const; - uint32_t size() const; - uint32_t capacity() const; - bool empty() const; - - CVType getType(TypeIndex Index) override; - StringRef getTypeName(TypeIndex Index) override; - bool contains(TypeIndex Index) override; - uint32_t size() override; - uint32_t capacity() override; - - Optional getFirst() override; - Optional getNext(TypeIndex Prev) override; - - Optional largestTypeIndexLessThan(TypeIndex TI) const; - -private: - TypeIndex getAppendIndex() const; - - void grow(); - void grow(TypeIndex Index); - - BumpPtrAllocator Allocator; - - uint32_t Count = 0; - TypeIndex LargestTypeIndex; - - /// All user defined type records in .debug$T live in here. Type indices - /// greater than 0x1000 are user defined. Subtract 0x1000 from the index to - /// index into this vector. - SmallVector CVUDTNames; - SmallVector TypeRecords; - - StringSaver TypeNameStorage; - - BitVector ValidRecords; -}; -} -} - -#endif \ No newline at end of file diff --git a/llvm/include/llvm/DebugInfo/CodeView/TypeDatabaseVisitor.h b/llvm/include/llvm/DebugInfo/CodeView/TypeDatabaseVisitor.h deleted file mode 100644 index 77dbc91a7d3..00000000000 --- a/llvm/include/llvm/DebugInfo/CodeView/TypeDatabaseVisitor.h +++ /dev/null @@ -1,62 +0,0 @@ -//===-- TypeDatabaseVisitor.h -----------------------------------*- C++ -*-===// -// -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// - -#ifndef LLVM_DEBUGINFO_CODEVIEW_TYPEDATABASEVISITOR_H -#define LLVM_DEBUGINFO_CODEVIEW_TYPEDATABASEVISITOR_H - -#include "llvm/ADT/PointerUnion.h" - -#include "llvm/DebugInfo/CodeView/TypeDatabase.h" -#include "llvm/DebugInfo/CodeView/TypeIndex.h" -#include "llvm/DebugInfo/CodeView/TypeRecord.h" -#include "llvm/DebugInfo/CodeView/TypeVisitorCallbacks.h" - -namespace llvm { -namespace codeview { - -/// Dumper for CodeView type streams found in COFF object files and PDB files. -class TypeDatabaseVisitor : public TypeVisitorCallbacks { -public: - explicit TypeDatabaseVisitor(TypeDatabase &TypeDB) : TypeDB(&TypeDB) {} - - /// Paired begin/end actions for all types. Receives all record data, - /// including the fixed-length record prefix. - Error visitTypeBegin(CVType &Record) override; - Error visitTypeBegin(CVType &Record, TypeIndex Index) override; - Error visitTypeEnd(CVType &Record) override; - Error visitMemberBegin(CVMemberRecord &Record) override; - Error visitMemberEnd(CVMemberRecord &Record) override; - -#define TYPE_RECORD(EnumName, EnumVal, Name) \ - Error visitKnownRecord(CVType &CVR, Name##Record &Record) override; -#define MEMBER_RECORD(EnumName, EnumVal, Name) \ - Error visitKnownMember(CVMemberRecord &CVR, Name##Record &Record) override; -#define TYPE_RECORD_ALIAS(EnumName, EnumVal, Name, AliasName) -#define MEMBER_RECORD_ALIAS(EnumName, EnumVal, Name, AliasName) -#include "llvm/DebugInfo/CodeView/CodeViewTypes.def" - -private: - StringRef getTypeName(TypeIndex Index) const; - StringRef saveTypeName(StringRef Name); - - bool IsInFieldList = false; - - /// Name of the current type. Only valid before visitTypeEnd. - StringRef Name; - /// Current type index. Only valid before visitTypeEnd, and if we are - /// visiting a random access type database. - Optional CurrentTypeIndex; - - TypeDatabase *TypeDB; -}; - -} // end namespace codeview -} // end namespace llvm - -#endif // LLVM_DEBUGINFO_CODEVIEW_TYPEDUMPER_H diff --git a/llvm/include/llvm/DebugInfo/CodeView/TypeTableCollection.h b/llvm/include/llvm/DebugInfo/CodeView/TypeTableCollection.h index 42b62ba2b6c..80326a0ffd3 100644 --- a/llvm/include/llvm/DebugInfo/CodeView/TypeTableCollection.h +++ b/llvm/include/llvm/DebugInfo/CodeView/TypeTableCollection.h @@ -11,7 +11,9 @@ #define LLVM_DEBUGINFO_CODEVIEW_TYPETABLECOLLECTION_H #include "llvm/DebugInfo/CodeView/TypeCollection.h" -#include "llvm/DebugInfo/CodeView/TypeDatabase.h" +#include "llvm/Support/StringSaver.h" + +#include namespace llvm { namespace codeview { @@ -30,11 +32,10 @@ public: uint32_t capacity() override; private: - bool hasCapacityFor(TypeIndex Index) const; - void ensureTypeExists(TypeIndex Index); - + BumpPtrAllocator Allocator; + StringSaver NameStorage; + std::vector Names; ArrayRef> Records; - TypeDatabase Database; }; } } -- cgit v1.2.3