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