summaryrefslogtreecommitdiff
path: root/lib/ObjectYAML
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 /lib/ObjectYAML
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 'lib/ObjectYAML')
-rw-r--r--lib/ObjectYAML/CodeViewYAMLTypes.cpp44
1 files changed, 20 insertions, 24 deletions
diff --git a/lib/ObjectYAML/CodeViewYAMLTypes.cpp b/lib/ObjectYAML/CodeViewYAMLTypes.cpp
index 81046b21786..84b52b463c4 100644
--- a/lib/ObjectYAML/CodeViewYAMLTypes.cpp
+++ b/lib/ObjectYAML/CodeViewYAMLTypes.cpp
@@ -20,6 +20,7 @@
#include "llvm/DebugInfo/CodeView/CVTypeVisitor.h"
#include "llvm/DebugInfo/CodeView/CodeView.h"
#include "llvm/DebugInfo/CodeView/CodeViewError.h"
+#include "llvm/DebugInfo/CodeView/ContinuationRecordBuilder.h"
#include "llvm/DebugInfo/CodeView/TypeDeserializer.h"
#include "llvm/DebugInfo/CodeView/TypeIndex.h"
#include "llvm/DebugInfo/CodeView/TypeTableBuilder.h"
@@ -82,7 +83,7 @@ struct LeafRecordBase {
virtual ~LeafRecordBase() = default;
virtual void map(yaml::IO &io) = 0;
- virtual CVType toCodeViewRecord(TypeTableBuilder &TTB) const = 0;
+ virtual CVType toCodeViewRecord(TypeTableBuilder &TS) const = 0;
virtual Error fromCodeViewRecord(CVType Type) = 0;
};
@@ -96,9 +97,9 @@ template <typename T> struct LeafRecordImpl : public LeafRecordBase {
return TypeDeserializer::deserializeAs<T>(Type, Record);
}
- CVType toCodeViewRecord(TypeTableBuilder &TTB) const override {
- TTB.writeKnownType(Record);
- return CVType(Kind, TTB.records().back());
+ CVType toCodeViewRecord(TypeTableBuilder &TS) const override {
+ TS.writeLeafType(Record);
+ return CVType(Kind, TS.records().back());
}
mutable T Record;
@@ -108,7 +109,7 @@ template <> struct LeafRecordImpl<FieldListRecord> : public LeafRecordBase {
explicit LeafRecordImpl(TypeLeafKind K) : LeafRecordBase(K) {}
void map(yaml::IO &io) override;
- CVType toCodeViewRecord(TypeTableBuilder &TTB) const override;
+ CVType toCodeViewRecord(TypeTableBuilder &TS) const override;
Error fromCodeViewRecord(CVType Type) override;
std::vector<MemberRecord> Members;
@@ -121,7 +122,7 @@ struct MemberRecordBase {
virtual ~MemberRecordBase() = default;
virtual void map(yaml::IO &io) = 0;
- virtual void writeTo(FieldListRecordBuilder &FLRB) = 0;
+ virtual void writeTo(ContinuationRecordBuilder &CRB) = 0;
};
template <typename T> struct MemberRecordImpl : public MemberRecordBase {
@@ -130,8 +131,8 @@ template <typename T> struct MemberRecordImpl : public MemberRecordBase {
void map(yaml::IO &io) override;
- void writeTo(FieldListRecordBuilder &FLRB) override {
- FLRB.writeMemberType(Record);
+ void writeTo(ContinuationRecordBuilder &CRB) override {
+ CRB.writeMemberType(Record);
}
mutable T Record;
@@ -489,14 +490,14 @@ Error LeafRecordImpl<FieldListRecord>::fromCodeViewRecord(CVType Type) {
}
CVType
-LeafRecordImpl<FieldListRecord>::toCodeViewRecord(TypeTableBuilder &TTB) const {
- FieldListRecordBuilder FLRB(TTB);
- FLRB.begin();
+LeafRecordImpl<FieldListRecord>::toCodeViewRecord(TypeTableBuilder &TS) const {
+ ContinuationRecordBuilder CRB;
+ CRB.begin(ContinuationRecordKind::FieldList);
for (const auto &Member : Members) {
- Member.Member->writeTo(FLRB);
+ Member.Member->writeTo(CRB);
}
- FLRB.end(true);
- return CVType(Kind, TTB.records().back());
+ TS.insertRecord(CRB);
+ return CVType(Kind, TS.records().back());
}
void MappingTraits<OneMethodRecord>::mapping(IO &io, OneMethodRecord &Record) {
@@ -681,13 +682,8 @@ Expected<LeafRecord> LeafRecord::fromCodeViewRecord(CVType Type) {
return make_error<CodeViewError>(cv_error_code::corrupt_record);
}
-CVType LeafRecord::toCodeViewRecord(BumpPtrAllocator &Alloc) const {
- TypeTableBuilder TTB(Alloc);
- return Leaf->toCodeViewRecord(TTB);
-}
-
-CVType LeafRecord::toCodeViewRecord(TypeTableBuilder &TTB) const {
- return Leaf->toCodeViewRecord(TTB);
+CVType LeafRecord::toCodeViewRecord(TypeTableBuilder &Serializer) const {
+ return Leaf->toCodeViewRecord(Serializer);
}
namespace llvm {
@@ -786,10 +782,10 @@ llvm::CodeViewYAML::fromDebugT(ArrayRef<uint8_t> DebugT) {
ArrayRef<uint8_t> llvm::CodeViewYAML::toDebugT(ArrayRef<LeafRecord> Leafs,
BumpPtrAllocator &Alloc) {
- TypeTableBuilder TTB(Alloc, false);
+ TypeTableBuilder TS(Alloc, false);
uint32_t Size = sizeof(uint32_t);
for (const auto &Leaf : Leafs) {
- CVType T = Leaf.toCodeViewRecord(TTB);
+ CVType T = Leaf.Leaf->toCodeViewRecord(TS);
Size += T.length();
assert(T.length() % 4 == 0 && "Improper type record alignment!");
}
@@ -798,7 +794,7 @@ ArrayRef<uint8_t> llvm::CodeViewYAML::toDebugT(ArrayRef<LeafRecord> Leafs,
BinaryStreamWriter Writer(Output, support::little);
ExitOnError Err("Error writing type record to .debug$T section");
Err(Writer.writeInteger<uint32_t>(COFF::DEBUG_SECTION_MAGIC));
- for (const auto &R : TTB.records()) {
+ for (const auto &R : TS.records()) {
Err(Writer.writeBytes(R));
}
assert(Writer.bytesRemaining() == 0 && "Didn't write all type record bytes!");