[WebAssembly] Fix asan issue from https://reviews.llvm.org/D121349
[llvm-project.git] / lld / COFF / TypeMerger.h
blob838db691a822e52e2936b1e9955cee0c78dc3434
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 //===----------------------------------------------------------------------===//
9 #ifndef LLD_COFF_TYPEMERGER_H
10 #define LLD_COFF_TYPEMERGER_H
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>
20 namespace lld {
21 namespace coff {
23 using llvm::codeview::GloballyHashedType;
24 using llvm::codeview::TypeIndex;
26 struct GHashState;
28 class TypeMerger {
29 public:
30 TypeMerger(COFFLinkerContext &ctx, llvm::BumpPtrAllocator &alloc);
32 ~TypeMerger();
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;
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;
46 /// Use global hashes to eliminate duplicate types and identify unique type
47 /// indices in each TpiSource.
48 void mergeTypesWithGHash();
50 /// Map from PDB function id type indexes to PDB function type indexes.
51 /// Populated after mergeTypesWithGHash.
52 llvm::DenseMap<TypeIndex, TypeIndex> funcIdToType;
54 /// Type records that will go into the PDB TPI stream.
55 llvm::codeview::MergingTypeTableBuilder typeTable;
57 /// Item records that will go into the PDB IPI stream.
58 llvm::codeview::MergingTypeTableBuilder idTable;
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;
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;
70 /// Object file sources. These must be processed after dependencySources.
71 ArrayRef<TpiSource *> objectSources;
73 /// Sorts the dependencies and reassigns TpiSource indices.
74 void sortDependencies();
76 private:
77 void clearGHashes();
79 COFFLinkerContext &ctx;
82 } // namespace coff
83 } // namespace lld
85 #endif