1 //===- MergingTypeTableBuilder.h ---------------------------------*- C++-*-===// 2 // 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 6 // 7 //===----------------------------------------------------------------------===// 8 9 #ifndef LLVM_DEBUGINFO_CODEVIEW_MERGINGTYPETABLEBUILDER_H 10 #define LLVM_DEBUGINFO_CODEVIEW_MERGINGTYPETABLEBUILDER_H 11 12 #include "llvm/ADT/ArrayRef.h" 13 #include "llvm/ADT/DenseMap.h" 14 #include "llvm/ADT/SmallVector.h" 15 #include "llvm/DebugInfo/CodeView/CVRecord.h" 16 #include "llvm/DebugInfo/CodeView/SimpleTypeSerializer.h" 17 #include "llvm/DebugInfo/CodeView/TypeCollection.h" 18 #include "llvm/DebugInfo/CodeView/TypeIndex.h" 19 #include "llvm/Support/Allocator.h" 20 #include <cstdint> 21 22 namespace llvm { 23 namespace codeview { 24 struct LocallyHashedType; 25 26 class ContinuationRecordBuilder; 27 28 class MergingTypeTableBuilder : public TypeCollection { 29 /// Storage for records. These need to outlive the TypeTableBuilder. 30 BumpPtrAllocator &RecordStorage; 31 32 /// A serializer that can write non-continuation leaf types. Only used as 33 /// a convenience function so that we can provide an interface method to 34 /// write an unserialized record. 35 SimpleTypeSerializer SimpleSerializer; 36 37 /// Hash table. 38 DenseMap<LocallyHashedType, TypeIndex> HashedRecords; 39 40 /// Contains a list of all records indexed by TypeIndex.toArrayIndex(). 41 SmallVector<ArrayRef<uint8_t>, 2> SeenRecords; 42 43 public: 44 explicit MergingTypeTableBuilder(BumpPtrAllocator &Storage); 45 ~MergingTypeTableBuilder(); 46 47 // TypeCollection overrides 48 std::optional<TypeIndex> getFirst() override; 49 std::optional<TypeIndex> getNext(TypeIndex Prev) override; 50 CVType getType(TypeIndex Index) override; 51 StringRef getTypeName(TypeIndex Index) override; 52 bool contains(TypeIndex Index) override; 53 uint32_t size() override; 54 uint32_t capacity() override; 55 bool replaceType(TypeIndex &Index, CVType Data, bool Stabilize) override; 56 57 // public interface 58 void reset(); 59 TypeIndex nextTypeIndex() const; 60 61 BumpPtrAllocator &getAllocator() { return RecordStorage; } 62 63 ArrayRef<ArrayRef<uint8_t>> records() const; 64 65 TypeIndex insertRecordAs(hash_code Hash, ArrayRef<uint8_t> &Record); 66 TypeIndex insertRecordBytes(ArrayRef<uint8_t> &Record); 67 TypeIndex insertRecord(ContinuationRecordBuilder &Builder); 68 69 template <typename T> TypeIndex writeLeafType(T &Record) { 70 ArrayRef<uint8_t> Data = SimpleSerializer.serialize(Record); 71 return insertRecordBytes(Data); 72 } 73 }; 74 75 } // end namespace codeview 76 } // end namespace llvm 77 78 #endif // LLVM_DEBUGINFO_CODEVIEW_MERGINGTYPETABLEBUILDER_H 79