1 //===- TypeMerger.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 LLD_COFF_TYPEMERGER_H 10 #define LLD_COFF_TYPEMERGER_H 11 12 #include "Config.h" 13 #include "DebugTypes.h" 14 #include "lld/Common/Timer.h" 15 #include "llvm/DebugInfo/CodeView/MergingTypeTableBuilder.h" 16 #include "llvm/DebugInfo/CodeView/TypeHashing.h" 17 #include "llvm/Support/Allocator.h" 18 #include <atomic> 19 20 namespace lld { 21 namespace coff { 22 23 using llvm::codeview::GloballyHashedType; 24 using llvm::codeview::TypeIndex; 25 26 struct GHashState; 27 28 class TypeMerger { 29 public: 30 TypeMerger(COFFLinkerContext &ctx, llvm::BumpPtrAllocator &alloc); 31 32 ~TypeMerger(); 33 34 /// Get the type table or the global type table if /DEBUG:GHASH is enabled. 35 inline llvm::codeview::TypeCollection &getTypeTable() { 36 assert(!config->debugGHashes); 37 return typeTable; 38 } 39 40 /// Get the ID table or the global ID table if /DEBUG:GHASH is enabled. 41 inline llvm::codeview::TypeCollection &getIDTable() { 42 assert(!config->debugGHashes); 43 return idTable; 44 } 45 46 /// Use global hashes to eliminate duplicate types and identify unique type 47 /// indices in each TpiSource. 48 void mergeTypesWithGHash(); 49 50 /// Map from PDB function id type indexes to PDB function type indexes. 51 /// Populated after mergeTypesWithGHash. 52 llvm::DenseMap<TypeIndex, TypeIndex> funcIdToType; 53 54 /// Type records that will go into the PDB TPI stream. 55 llvm::codeview::MergingTypeTableBuilder typeTable; 56 57 /// Item records that will go into the PDB IPI stream. 58 llvm::codeview::MergingTypeTableBuilder idTable; 59 60 // When showSummary is enabled, these are histograms of TPI and IPI records 61 // keyed by type index. 62 SmallVector<uint32_t, 0> tpiCounts; 63 SmallVector<uint32_t, 0> ipiCounts; 64 65 /// Dependency type sources, such as type servers or PCH object files. These 66 /// must be processed before objects that rely on them. Set by 67 /// sortDependencies. 68 ArrayRef<TpiSource *> dependencySources; 69 70 /// Object file sources. These must be processed after dependencySources. 71 ArrayRef<TpiSource *> objectSources; 72 73 /// Sorts the dependencies and reassigns TpiSource indices. 74 void sortDependencies(); 75 76 private: 77 void clearGHashes(); 78 79 COFFLinkerContext &ctx; 80 }; 81 82 } // namespace coff 83 } // namespace lld 84 85 #endif 86