Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:43:39

0001 //===- MergingTypeTableBuilder.h ---------------------------------*- C++-*-===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 
0009 #ifndef LLVM_DEBUGINFO_CODEVIEW_MERGINGTYPETABLEBUILDER_H
0010 #define LLVM_DEBUGINFO_CODEVIEW_MERGINGTYPETABLEBUILDER_H
0011 
0012 #include "llvm/ADT/ArrayRef.h"
0013 #include "llvm/ADT/DenseMap.h"
0014 #include "llvm/ADT/SmallVector.h"
0015 #include "llvm/DebugInfo/CodeView/CVRecord.h"
0016 #include "llvm/DebugInfo/CodeView/SimpleTypeSerializer.h"
0017 #include "llvm/DebugInfo/CodeView/TypeCollection.h"
0018 #include "llvm/DebugInfo/CodeView/TypeIndex.h"
0019 #include "llvm/Support/Allocator.h"
0020 #include <cstdint>
0021 
0022 namespace llvm {
0023 namespace codeview {
0024 struct LocallyHashedType;
0025 
0026 class ContinuationRecordBuilder;
0027 
0028 class MergingTypeTableBuilder : public TypeCollection {
0029   /// Storage for records.  These need to outlive the TypeTableBuilder.
0030   BumpPtrAllocator &RecordStorage;
0031 
0032   /// A serializer that can write non-continuation leaf types.  Only used as
0033   /// a convenience function so that we can provide an interface method to
0034   /// write an unserialized record.
0035   SimpleTypeSerializer SimpleSerializer;
0036 
0037   /// Hash table.
0038   DenseMap<LocallyHashedType, TypeIndex> HashedRecords;
0039 
0040   /// Contains a list of all records indexed by TypeIndex.toArrayIndex().
0041   SmallVector<ArrayRef<uint8_t>, 2> SeenRecords;
0042 
0043 public:
0044   explicit MergingTypeTableBuilder(BumpPtrAllocator &Storage);
0045   ~MergingTypeTableBuilder();
0046 
0047   // TypeCollection overrides
0048   std::optional<TypeIndex> getFirst() override;
0049   std::optional<TypeIndex> getNext(TypeIndex Prev) override;
0050   CVType getType(TypeIndex Index) override;
0051   StringRef getTypeName(TypeIndex Index) override;
0052   bool contains(TypeIndex Index) override;
0053   uint32_t size() override;
0054   uint32_t capacity() override;
0055   bool replaceType(TypeIndex &Index, CVType Data, bool Stabilize) override;
0056 
0057   // public interface
0058   void reset();
0059   TypeIndex nextTypeIndex() const;
0060 
0061   BumpPtrAllocator &getAllocator() { return RecordStorage; }
0062 
0063   ArrayRef<ArrayRef<uint8_t>> records() const;
0064 
0065   TypeIndex insertRecordAs(hash_code Hash, ArrayRef<uint8_t> &Record);
0066   TypeIndex insertRecordBytes(ArrayRef<uint8_t> &Record);
0067   TypeIndex insertRecord(ContinuationRecordBuilder &Builder);
0068 
0069   template <typename T> TypeIndex writeLeafType(T &Record) {
0070     ArrayRef<uint8_t> Data = SimpleSerializer.serialize(Record);
0071     return insertRecordBytes(Data);
0072   }
0073 };
0074 
0075 } // end namespace codeview
0076 } // end namespace llvm
0077 
0078 #endif // LLVM_DEBUGINFO_CODEVIEW_MERGINGTYPETABLEBUILDER_H