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 "COFFLinkerContext.h" |
13 | #include "Config.h" |
14 | #include "DebugTypes.h" |
15 | #include "lld/Common/Timer.h" |
16 | #include "llvm/DebugInfo/CodeView/MergingTypeTableBuilder.h" |
17 | #include "llvm/DebugInfo/CodeView/TypeHashing.h" |
18 | #include "llvm/Support/Allocator.h" |
19 | #include <atomic> |
20 | |
21 | namespace lld::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(!ctx.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(!ctx.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 lld::coff |
83 | |
84 | #endif |
85 | |