Recommit r369190 "[llvm-readobj/llvm-readelf] - Improve/cleanup the error reporting...
[llvm-complete.git] / tools / llvm-pdbutil / TypeReferenceTracker.h
blob8861731ab6ee8db76a92f5d59b443e5d32cb40a3
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 "InputFile.h"
14 #include "llvm/ADT/BitVector.h"
15 #include "llvm/ADT/Optional.h"
16 #include "llvm/ADT/SmallVector.h"
17 #include "llvm/DebugInfo/CodeView/CVRecord.h"
18 #include "llvm/DebugInfo/CodeView/TypeIndex.h"
19 #include "llvm/DebugInfo/CodeView/TypeIndexDiscovery.h"
20 #include "llvm/Support/Error.h"
22 namespace llvm {
23 namespace pdb {
25 class TpiStream;
27 /// Maintains bitvector to track whether a type was referenced by a symbol
28 /// record.
29 class TypeReferenceTracker {
30 public:
31 TypeReferenceTracker(InputFile &File);
33 // Do the work of marking referenced types.
34 void mark();
36 // Return true if a symbol record transitively references this type.
37 bool isTypeReferenced(codeview::TypeIndex TI) {
38 return TI.toArrayIndex() <= NumTypeRecords &&
39 TypeReferenced.test(TI.toArrayIndex());
42 private:
43 void addTypeRefsFromSymbol(const codeview::CVSymbol &Sym);
45 // Mark types on this list as referenced.
46 void addReferencedTypes(ArrayRef<uint8_t> RecData,
47 ArrayRef<codeview::TiReference> Refs);
49 // Consume all types on the worklist.
50 void markReferencedTypes();
52 void addOneTypeRef(codeview::TiRefKind RefKind, codeview::TypeIndex RefTI);
54 InputFile &File;
55 codeview::LazyRandomTypeCollection &Types;
56 codeview::LazyRandomTypeCollection *Ids = nullptr;
57 TpiStream *Tpi = nullptr;
58 BitVector TypeReferenced;
59 BitVector IdReferenced;
60 SmallVector<std::pair<codeview::TiRefKind, codeview::TypeIndex>, 10>
61 RefWorklist;
62 uint32_t NumTypeRecords = 0;
63 uint32_t NumIdRecords = 0;
66 } // namespace pdb
67 } // namespace llvm
69 #endif // LLVM_TOOLS_LLVMPDBDUMP_TYPEREFERENCETRACKER_H