From 08bbd35a80bf7765fe0d3043f9eb5a2f2786b649 Mon Sep 17 00:00:00 2001 From: Dimitry Andric Date: Mon, 26 Jun 2017 20:32:52 +0000 Subject: Vendor import of llvm trunk r306325: https://llvm.org/svn/llvm-project/llvm/trunk@306325 --- lib/DebugInfo/CodeView/TypeTableCollection.cpp | 58 ++++++++++---------------- 1 file changed, 21 insertions(+), 37 deletions(-) (limited to 'lib/DebugInfo/CodeView/TypeTableCollection.cpp') diff --git a/lib/DebugInfo/CodeView/TypeTableCollection.cpp b/lib/DebugInfo/CodeView/TypeTableCollection.cpp index 8d974d522f28..4eca5aeaa0ae 100644 --- a/lib/DebugInfo/CodeView/TypeTableCollection.cpp +++ b/lib/DebugInfo/CodeView/TypeTableCollection.cpp @@ -10,7 +10,7 @@ #include "llvm/DebugInfo/CodeView/TypeTableCollection.h" #include "llvm/DebugInfo/CodeView/CVTypeVisitor.h" -#include "llvm/DebugInfo/CodeView/TypeDatabaseVisitor.h" +#include "llvm/DebugInfo/CodeView/TypeName.h" #include "llvm/DebugInfo/CodeView/TypeTableBuilder.h" #include "llvm/Support/BinaryByteStream.h" #include "llvm/Support/BinaryStreamReader.h" @@ -18,14 +18,10 @@ using namespace llvm; using namespace llvm::codeview; -static void error(Error &&EC) { - assert(!static_cast(EC)); - if (EC) - consumeError(std::move(EC)); -} - TypeTableCollection::TypeTableCollection(ArrayRef> Records) - : Records(Records), Database(Records.size()) {} + : NameStorage(Allocator), Records(Records) { + Names.resize(Records.size()); +} Optional TypeTableCollection::getFirst() { if (empty()) @@ -34,50 +30,38 @@ Optional TypeTableCollection::getFirst() { } Optional TypeTableCollection::getNext(TypeIndex Prev) { + assert(contains(Prev)); ++Prev; - assert(Prev.toArrayIndex() <= size()); if (Prev.toArrayIndex() == size()) return None; return Prev; } -void TypeTableCollection::ensureTypeExists(TypeIndex Index) { - assert(hasCapacityFor(Index)); - - if (Database.contains(Index)) - return; - - BinaryByteStream Bytes(Records[Index.toArrayIndex()], support::little); - - CVType Type; - uint32_t Len; - VarStreamArrayExtractor Extract; - error(Extract(Bytes, Len, Type)); - - TypeDatabaseVisitor DBV(Database); - error(codeview::visitTypeRecord(Type, Index, DBV)); - assert(Database.contains(Index)); -} - CVType TypeTableCollection::getType(TypeIndex Index) { - ensureTypeExists(Index); - return Database.getTypeRecord(Index); + assert(Index.toArrayIndex() < Records.size()); + ArrayRef Bytes = Records[Index.toArrayIndex()]; + const RecordPrefix *Prefix = + reinterpret_cast(Bytes.data()); + TypeLeafKind Kind = static_cast(uint16_t(Prefix->RecordKind)); + return CVType(Kind, Bytes); } StringRef TypeTableCollection::getTypeName(TypeIndex Index) { - if (!Index.isSimple()) - ensureTypeExists(Index); - return Database.getTypeName(Index); + if (Index.isNoneType() || Index.isSimple()) + return TypeIndex::simpleTypeName(Index); + + uint32_t I = Index.toArrayIndex(); + if (Names[I].data() == nullptr) { + StringRef Result = NameStorage.save(computeTypeName(*this, Index)); + Names[I] = Result; + } + return Names[I]; } bool TypeTableCollection::contains(TypeIndex Index) { - return Database.contains(Index); + return Index.toArrayIndex() <= size(); } uint32_t TypeTableCollection::size() { return Records.size(); } uint32_t TypeTableCollection::capacity() { return Records.size(); } - -bool TypeTableCollection::hasCapacityFor(TypeIndex Index) const { - return Index.toArrayIndex() < Records.size(); -} -- cgit v1.2.3