1 //===- TypeReferenceTracker.h --------------------------------- *- C++ --*-===//
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
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"
27 /// Maintains bitvector to track whether a type was referenced by a symbol
29 class TypeReferenceTracker {
31 TypeReferenceTracker(InputFile &File);
33 // Do the work of marking referenced types.
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());
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);
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>
62 uint32_t NumTypeRecords = 0;
63 uint32_t NumIdRecords = 0;
69 #endif // LLVM_TOOLS_LLVMPDBDUMP_TYPEREFERENCETRACKER_H