Fix test failures introduced by PR #113697 (#116941)
[llvm-project.git] / llvm / tools / llvm-pdbutil / TypeReferenceTracker.h
blob8262129b82996f358bb0361dc65a1ddfef75cad2
1 //===- TypeReferenceTracker.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 LLVM_TOOLS_LLVMPDBDUMP_TYPEREFERENCETRACKER_H
10 #define LLVM_TOOLS_LLVMPDBDUMP_TYPEREFERENCETRACKER_H
12 #include "llvm/ADT/BitVector.h"
13 #include "llvm/ADT/SmallVector.h"
14 #include "llvm/DebugInfo/CodeView/CVRecord.h"
15 #include "llvm/DebugInfo/CodeView/TypeIndex.h"
16 #include "llvm/DebugInfo/CodeView/TypeIndexDiscovery.h"
17 #include "llvm/DebugInfo/PDB/Native/InputFile.h"
18 #include "llvm/Support/Error.h"
20 namespace llvm {
21 namespace pdb {
23 class TpiStream;
25 /// Maintains bitvector to track whether a type was referenced by a symbol
26 /// record.
27 class TypeReferenceTracker {
28 public:
29 TypeReferenceTracker(InputFile &File);
31 // Do the work of marking referenced types.
32 void mark();
34 // Return true if a symbol record transitively references this type.
35 bool isTypeReferenced(codeview::TypeIndex TI) {
36 return TI.toArrayIndex() <= NumTypeRecords &&
37 TypeReferenced.test(TI.toArrayIndex());
40 private:
41 void addTypeRefsFromSymbol(const codeview::CVSymbol &Sym);
43 // Mark types on this list as referenced.
44 void addReferencedTypes(ArrayRef<uint8_t> RecData,
45 ArrayRef<codeview::TiReference> Refs);
47 // Consume all types on the worklist.
48 void markReferencedTypes();
50 void addOneTypeRef(codeview::TiRefKind RefKind, codeview::TypeIndex RefTI);
52 InputFile &File;
53 codeview::LazyRandomTypeCollection &Types;
54 codeview::LazyRandomTypeCollection *Ids = nullptr;
55 TpiStream *Tpi = nullptr;
56 BitVector TypeReferenced;
57 BitVector IdReferenced;
58 SmallVector<std::pair<codeview::TiRefKind, codeview::TypeIndex>, 10>
59 RefWorklist;
60 uint32_t NumTypeRecords = 0;
61 uint32_t NumIdRecords = 0;
64 } // namespace pdb
65 } // namespace llvm
67 #endif // LLVM_TOOLS_LLVMPDBDUMP_TYPEREFERENCETRACKER_H