1 //===- GlobalTypeTableBuilder.h ----------------------------------*- C++-*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #ifndef LLVM_DEBUGINFO_CODEVIEW_GLOBALTYPETABLEBUILDER_H
11 #define LLVM_DEBUGINFO_CODEVIEW_GLOBALTYPETABLEBUILDER_H
13 #include "llvm/ADT/ArrayRef.h"
14 #include "llvm/ADT/DenseSet.h"
15 #include "llvm/ADT/SmallVector.h"
16 #include "llvm/DebugInfo/CodeView/CodeView.h"
17 #include "llvm/DebugInfo/CodeView/SimpleTypeSerializer.h"
18 #include "llvm/DebugInfo/CodeView/TypeCollection.h"
19 #include "llvm/DebugInfo/CodeView/TypeHashing.h"
20 #include "llvm/DebugInfo/CodeView/TypeIndex.h"
21 #include "llvm/Support/Allocator.h"
30 class ContinuationRecordBuilder;
32 class GlobalTypeTableBuilder : public TypeCollection {
33 /// Storage for records. These need to outlive the TypeTableBuilder.
34 BumpPtrAllocator &RecordStorage;
36 /// A serializer that can write non-continuation leaf types. Only used as
37 /// a convenience function so that we can provide an interface method to
38 /// write an unserialized record.
39 SimpleTypeSerializer SimpleSerializer;
42 DenseMap<GloballyHashedType, TypeIndex> HashedRecords;
44 /// Contains a list of all records indexed by TypeIndex.toArrayIndex().
45 SmallVector<ArrayRef<uint8_t>, 2> SeenRecords;
47 /// Contains a list of all hash values inexed by TypeIndex.toArrayIndex().
48 SmallVector<GloballyHashedType, 2> SeenHashes;
51 explicit GlobalTypeTableBuilder(BumpPtrAllocator &Storage);
52 ~GlobalTypeTableBuilder();
54 // TypeTableCollection overrides
55 Optional<TypeIndex> getFirst() override;
56 Optional<TypeIndex> getNext(TypeIndex Prev) override;
57 CVType getType(TypeIndex Index) override;
58 StringRef getTypeName(TypeIndex Index) override;
59 bool contains(TypeIndex Index) override;
60 uint32_t size() override;
61 uint32_t capacity() override;
65 TypeIndex nextTypeIndex() const;
67 BumpPtrAllocator &getAllocator() { return RecordStorage; }
69 ArrayRef<ArrayRef<uint8_t>> records() const;
70 ArrayRef<GloballyHashedType> hashes() const;
72 using CreateRecord = llvm::function_ref<ArrayRef<uint8_t>()>;
74 TypeIndex insertRecordAs(GloballyHashedType Hash, CreateRecord Create);
75 TypeIndex insertRecordBytes(ArrayRef<uint8_t> Data);
76 TypeIndex insertRecord(ContinuationRecordBuilder &Builder);
78 template <typename T> TypeIndex writeLeafType(T &Record) {
79 ArrayRef<uint8_t> Data = SimpleSerializer.serialize(Record);
80 return insertRecordBytes(Data);
84 } // end namespace codeview
85 } // end namespace llvm
87 #endif // LLVM_DEBUGINFO_CODEVIEW_MERGINGTYPETABLEBUILDER_H