TypeMerger.h revision 1.1.1.3
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 "llvm/DebugInfo/CodeView/MergingTypeTableBuilder.h"
14#include "llvm/DebugInfo/CodeView/TypeHashing.h"
15#include "llvm/Support/Allocator.h"
16#include <atomic>
17
18namespace lld {
19namespace coff {
20
21using llvm::codeview::GloballyHashedType;
22using llvm::codeview::TypeIndex;
23
24struct GHashState;
25
26class TypeMerger {
27public:
28  TypeMerger(llvm::BumpPtrAllocator &alloc);
29
30  ~TypeMerger();
31
32  /// Get the type table or the global type table if /DEBUG:GHASH is enabled.
33  inline llvm::codeview::TypeCollection &getTypeTable() {
34    assert(!config->debugGHashes);
35    return typeTable;
36  }
37
38  /// Get the ID table or the global ID table if /DEBUG:GHASH is enabled.
39  inline llvm::codeview::TypeCollection &getIDTable() {
40    assert(!config->debugGHashes);
41    return idTable;
42  }
43
44  /// Use global hashes to eliminate duplicate types and identify unique type
45  /// indices in each TpiSource.
46  void mergeTypesWithGHash();
47
48  /// Map from PDB function id type indexes to PDB function type indexes.
49  /// Populated after mergeTypesWithGHash.
50  llvm::DenseMap<TypeIndex, TypeIndex> funcIdToType;
51
52  /// Type records that will go into the PDB TPI stream.
53  llvm::codeview::MergingTypeTableBuilder typeTable;
54
55  /// Item records that will go into the PDB IPI stream.
56  llvm::codeview::MergingTypeTableBuilder idTable;
57
58  // When showSummary is enabled, these are histograms of TPI and IPI records
59  // keyed by type index.
60  SmallVector<uint32_t, 0> tpiCounts;
61  SmallVector<uint32_t, 0> ipiCounts;
62};
63
64} // namespace coff
65} // namespace lld
66
67#endif
68