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