summaryrefslogtreecommitdiff
path: root/unittests
diff options
context:
space:
mode:
authorZachary Turner <zturner@google.com>2017-11-28 18:33:17 +0000
committerZachary Turner <zturner@google.com>2017-11-28 18:33:17 +0000
commitab45c0673e7510b52995f560cce64b002601ed9f (patch)
tree5070004d67b7856a64a77c523faeb3c426adbc1c /unittests
parenta710db28b7f3ef5d7fe54930822b88ec8901c02f (diff)
[CodeView] Refactor / Rewrite TypeSerializer and TypeTableBuilder.
The motivation behind this patch is that future directions require us to be able to compute the hash value of records independently of actually using them for de-duplication. The current structure of TypeSerializer / TypeTableBuilder being a single entry point that takes an unserialized type record, and then hashes and de-duplicates it is not flexible enough to allow this. At the same time, the existing TypeSerializer is already extremely complex for this very reason -- it tries to be too many things. In addition to serializing, hashing, and de-duplicating, ti also supports splitting up field list records and adding continuations. All of this functionality crammed into this one class makes it very complicated to work with and hard to maintain. To solve all of these problems, I've re-written everything from scratch and split the functionality into separate pieces that can easily be reused. The end result is that one class TypeSerializer is turned into 3 new classes SimpleTypeSerializer, ContinuationRecordBuilder, and TypeTableBuilder, each of which in isolation is simple and straightforward. A quick summary of these new classes and their responsibilities are: - SimpleTypeSerializer : Turns a non-FieldList leaf type into a series of bytes. Does not do any hashing. Every time you call it, it will re-serialize and return bytes again. The same instance can be re-used over and over to avoid re-allocations, and in exchange for this optimization the bytes returned by the serializer only live until the caller attempts to serialize a new record. - ContinuationRecordBuilder : Turns a FieldList-like record into a series of fragments. Does not do any hashing. Like SimpleTypeSerializer, returns references to privately owned bytes, so the storage is invalidated as soon as the caller tries to re-use the instance. Works equally well for LF_FIELDLIST as it does for LF_METHODLIST, solving a long-standing theoretical limitation of the previous implementation. - TypeTableBuilder : Accepts sequences of bytes that the user has already serialized, and inserts them by de-duplicating with a hash table. For the sake of convenience and efficiency, this class internally stores a SimpleTypeSerializer so that it can accept unserialized records. The same is not true of ContinuationRecordBuilder. The user is required to create their own instance of ContinuationRecordBuilder. Differential Revision: https://reviews.llvm.org/D40518 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@319198 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'unittests')
-rw-r--r--unittests/DebugInfo/CodeView/RandomAccessVisitorTest.cpp7
-rw-r--r--unittests/DebugInfo/CodeView/TypeIndexDiscoveryTest.cpp20
2 files changed, 14 insertions, 13 deletions
diff --git a/unittests/DebugInfo/CodeView/RandomAccessVisitorTest.cpp b/unittests/DebugInfo/CodeView/RandomAccessVisitorTest.cpp
index 04b7bb0ba93..6fb95bdbbfd 100644
--- a/unittests/DebugInfo/CodeView/RandomAccessVisitorTest.cpp
+++ b/unittests/DebugInfo/CodeView/RandomAccessVisitorTest.cpp
@@ -12,7 +12,6 @@
#include "llvm/DebugInfo/CodeView/LazyRandomTypeCollection.h"
#include "llvm/DebugInfo/CodeView/TypeRecord.h"
#include "llvm/DebugInfo/CodeView/TypeRecordMapping.h"
-#include "llvm/DebugInfo/CodeView/TypeSerializer.h"
#include "llvm/DebugInfo/CodeView/TypeTableBuilder.h"
#include "llvm/DebugInfo/CodeView/TypeVisitorCallbacks.h"
#include "llvm/DebugInfo/PDB/Native/RawTypes.h"
@@ -108,7 +107,7 @@ public:
Stream << "Array [" << I << "]";
AR.Name = GlobalState->Strings.save(Stream.str());
GlobalState->Records.push_back(AR);
- GlobalState->Indices.push_back(Builder.writeKnownType(AR));
+ GlobalState->Indices.push_back(Builder.writeLeafType(AR));
CVType Type(TypeLeafKind::LF_ARRAY, Builder.records().back());
GlobalState->TypeVector.push_back(Type);
@@ -363,13 +362,13 @@ TEST_F(RandomAccessVisitorTest, CrossChunkName) {
Class.DerivationList = TypeIndex::fromArrayIndex(0);
Class.FieldList = TypeIndex::fromArrayIndex(0);
Class.VTableShape = TypeIndex::fromArrayIndex(0);
- TypeIndex IndexZero = Builder.writeKnownType(Class);
+ TypeIndex IndexZero = Builder.writeLeafType(Class);
// TypeIndex 1 refers to type index 0.
ModifierRecord Modifier(TypeRecordKind::Modifier);
Modifier.ModifiedType = TypeIndex::fromArrayIndex(0);
Modifier.Modifiers = ModifierOptions::Const;
- TypeIndex IndexOne = Builder.writeKnownType(Modifier);
+ TypeIndex IndexOne = Builder.writeLeafType(Modifier);
// set up a type stream that refers to the above two serialized records.
std::vector<CVType> TypeArray;
diff --git a/unittests/DebugInfo/CodeView/TypeIndexDiscoveryTest.cpp b/unittests/DebugInfo/CodeView/TypeIndexDiscoveryTest.cpp
index 125506716d9..8b3889c193f 100644
--- a/unittests/DebugInfo/CodeView/TypeIndexDiscoveryTest.cpp
+++ b/unittests/DebugInfo/CodeView/TypeIndexDiscoveryTest.cpp
@@ -9,8 +9,9 @@
#include "llvm/DebugInfo/CodeView/TypeIndexDiscovery.h"
-#include "llvm/DebugInfo/CodeView/TypeTableBuilder.h"
+#include "llvm/DebugInfo/CodeView/ContinuationRecordBuilder.h"
#include "llvm/DebugInfo/CodeView/SymbolSerializer.h"
+#include "llvm/DebugInfo/CodeView/TypeTableBuilder.h"
#include "llvm/Support/Allocator.h"
#include "gmock/gmock.h"
@@ -26,12 +27,12 @@ public:
void SetUp() override {
Refs.clear();
TTB = make_unique<TypeTableBuilder>(Storage);
- FLRB = make_unique<FieldListRecordBuilder>(*TTB);
+ CRB = make_unique<ContinuationRecordBuilder>();
Symbols.clear();
}
void TearDown() override {
- FLRB.reset();
+ CRB.reset();
TTB.reset();
}
@@ -55,10 +56,11 @@ protected:
}
template <typename... T> void writeFieldList(T &&... MemberRecords) {
- FLRB->begin();
+ CRB->begin(ContinuationRecordKind::FieldList);
writeFieldListImpl(std::forward<T>(MemberRecords)...);
- FLRB->end(true);
- ASSERT_EQ(1u, TTB->records().size());
+ auto Records = CRB->end(TTB->nextTypeIndex());
+ ASSERT_EQ(1u, Records.size());
+ TTB->insertRecordBytes(Records.front().RecordData);
discoverAllTypeIndices();
}
@@ -140,7 +142,7 @@ private:
template <typename RecType, typename... Rest>
void writeFieldListImpl(RecType &&Record, Rest &&... Records) {
- FLRB->writeMemberType(Record);
+ CRB->writeMemberType(Record);
writeFieldListImpl(std::forward<Rest>(Records)...);
}
@@ -149,7 +151,7 @@ private:
template <typename RecType, typename... Rest>
void writeTypeRecordsImpl(RecType &&Record, Rest &&... Records) {
- TTB->writeKnownType(Record);
+ TTB->writeLeafType(Record);
writeTypeRecordsImpl(std::forward<Rest>(Records)...);
}
@@ -164,7 +166,7 @@ private:
}
std::vector<SmallVector<TiReference, 4>> Refs;
- std::unique_ptr<FieldListRecordBuilder> FLRB;
+ std::unique_ptr<ContinuationRecordBuilder> CRB;
std::vector<CVSymbol> Symbols;
BumpPtrAllocator Storage;
};