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/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"
19
20namespace llvm {
21namespace pdb {
22
23class TpiStream;
24
25/// Maintains bitvector to track whether a type was referenced by a symbol
26/// record.
27class TypeReferenceTracker {
28public:
29 TypeReferenceTracker(InputFile &File);
30
31 // Do the work of marking referenced types.
32 void mark();
33
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(Idx: TI.toArrayIndex());
38 }
39
40private:
41 void addTypeRefsFromSymbol(const codeview::CVSymbol &Sym);
42
43 // Mark types on this list as referenced.
44 void addReferencedTypes(ArrayRef<uint8_t> RecData,
45 ArrayRef<codeview::TiReference> Refs);
46
47 // Consume all types on the worklist.
48 void markReferencedTypes();
49
50 void addOneTypeRef(codeview::TiRefKind RefKind, codeview::TypeIndex RefTI);
51
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;
62};
63
64} // namespace pdb
65} // namespace llvm
66
67#endif // LLVM_TOOLS_LLVMPDBDUMP_TYPEREFERENCETRACKER_H
68