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