1 //===- MergingTypeTableBuilder.h ---------------------------------*- C++-*-===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 #ifndef LLVM_DEBUGINFO_CODEVIEW_MERGINGTYPETABLEBUILDER_H
10 #define LLVM_DEBUGINFO_CODEVIEW_MERGINGTYPETABLEBUILDER_H
12 #include "llvm/ADT/ArrayRef.h"
13 #include "llvm/ADT/DenseSet.h"
14 #include "llvm/ADT/SmallVector.h"
15 #include "llvm/DebugInfo/CodeView/CodeView.h"
16 #include "llvm/DebugInfo/CodeView/SimpleTypeSerializer.h"
17 #include "llvm/DebugInfo/CodeView/TypeCollection.h"
18 #include "llvm/DebugInfo/CodeView/TypeHashing.h"
19 #include "llvm/DebugInfo/CodeView/TypeIndex.h"
20 #include "llvm/Support/Allocator.h"
29 class ContinuationRecordBuilder
;
31 class MergingTypeTableBuilder
: public TypeCollection
{
32 /// Storage for records. These need to outlive the TypeTableBuilder.
33 BumpPtrAllocator
&RecordStorage
;
35 /// A serializer that can write non-continuation leaf types. Only used as
36 /// a convenience function so that we can provide an interface method to
37 /// write an unserialized record.
38 SimpleTypeSerializer SimpleSerializer
;
41 DenseMap
<LocallyHashedType
, TypeIndex
> HashedRecords
;
43 /// Contains a list of all records indexed by TypeIndex.toArrayIndex().
44 SmallVector
<ArrayRef
<uint8_t>, 2> SeenRecords
;
47 explicit MergingTypeTableBuilder(BumpPtrAllocator
&Storage
);
48 ~MergingTypeTableBuilder();
50 // TypeTableCollection overrides
51 Optional
<TypeIndex
> getFirst() override
;
52 Optional
<TypeIndex
> getNext(TypeIndex Prev
) override
;
53 CVType
getType(TypeIndex Index
) override
;
54 StringRef
getTypeName(TypeIndex Index
) override
;
55 bool contains(TypeIndex Index
) override
;
56 uint32_t size() override
;
57 uint32_t capacity() override
;
61 TypeIndex
nextTypeIndex() const;
63 BumpPtrAllocator
&getAllocator() { return RecordStorage
; }
65 ArrayRef
<ArrayRef
<uint8_t>> records() const;
67 TypeIndex
insertRecordAs(hash_code Hash
, ArrayRef
<uint8_t> &Record
);
68 TypeIndex
insertRecordBytes(ArrayRef
<uint8_t> &Record
);
69 TypeIndex
insertRecord(ContinuationRecordBuilder
&Builder
);
71 template <typename T
> TypeIndex
writeLeafType(T
&Record
) {
72 ArrayRef
<uint8_t> Data
= SimpleSerializer
.serialize(Record
);
73 return insertRecordBytes(Data
);
77 } // end namespace codeview
78 } // end namespace llvm
80 #endif // LLVM_DEBUGINFO_CODEVIEW_MERGINGTYPETABLEBUILDER_H