LLVM  15.0.0git
NativeEnumTypes.cpp
Go to the documentation of this file.
1 //==- NativeEnumTypes.cpp - Native Type Enumerator impl ----------*- 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 
10 
11 #include "llvm/ADT/Optional.h"
12 #include "llvm/ADT/STLExtras.h"
21 
22 using namespace llvm;
23 using namespace llvm::codeview;
24 using namespace llvm::pdb;
25 
26 NativeEnumTypes::NativeEnumTypes(NativeSession &PDBSession,
28  std::vector<codeview::TypeLeafKind> Kinds)
29  : Index(0), Session(PDBSession) {
30  Optional<TypeIndex> TI = Types.getFirst();
31  while (TI) {
32  CVType CVT = Types.getType(*TI);
33  TypeLeafKind K = CVT.kind();
34  if (llvm::is_contained(Kinds, K)) {
35  // Don't add forward refs, we'll find those later while enumerating.
36  if (!isUdtForwardRef(CVT))
37  Matches.push_back(*TI);
38  } else if (K == TypeLeafKind::LF_MODIFIER) {
39  TypeIndex ModifiedTI = getModifiedType(CVT);
40  if (!ModifiedTI.isSimple()) {
41  CVType UnmodifiedCVT = Types.getType(ModifiedTI);
42  // LF_MODIFIERs point to forward refs, but don't worry about that
43  // here. We're pushing the TypeIndex of the LF_MODIFIER itself,
44  // so we'll worry about resolving forward refs later.
45  if (llvm::is_contained(Kinds, UnmodifiedCVT.kind()))
46  Matches.push_back(*TI);
47  }
48  }
49  TI = Types.getNext(*TI);
50  }
51 }
52 
54  std::vector<codeview::TypeIndex> Indices)
55  : Matches(std::move(Indices)), Index(0), Session(PDBSession) {}
56 
58  return static_cast<uint32_t>(Matches.size());
59 }
60 
61 std::unique_ptr<PDBSymbol> NativeEnumTypes::getChildAtIndex(uint32_t N) const {
62  if (N < Matches.size()) {
63  SymIndexId Id = Session.getSymbolCache().findSymbolByTypeIndex(Matches[N]);
64  return Session.getSymbolCache().getSymbolById(Id);
65  }
66  return nullptr;
67 }
68 
69 std::unique_ptr<PDBSymbol> NativeEnumTypes::getNext() {
70  return getChildAtIndex(Index++);
71 }
72 
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:17
Optional.h
llvm::pdb::NativeEnumTypes::reset
void reset() override
Definition: NativeEnumTypes.cpp:73
llvm::Optional
Definition: APInt.h:33
llvm::codeview::isUdtForwardRef
bool isUdtForwardRef(CVType CVT)
Given an arbitrary codeview type, determine if it is an LF_STRUCTURE, LF_CLASS, LF_INTERFACE,...
Definition: TypeRecordHelpers.cpp:27
STLExtras.h
llvm::pdb::NativeEnumTypes::NativeEnumTypes
NativeEnumTypes(NativeSession &Session, codeview::LazyRandomTypeCollection &TypeCollection, std::vector< codeview::TypeLeafKind > Kinds)
Definition: NativeEnumTypes.cpp:26
llvm::codeview::getModifiedType
TypeIndex getModifiedType(const CVType &CVT)
Given a CVType which is assumed to be an LF_MODIFIER, return the TypeIndex of the type that the LF_MO...
Definition: TypeRecordHelpers.cpp:47
llvm::pdb::NativeEnumTypes::getNext
std::unique_ptr< PDBSymbol > getNext() override
Definition: NativeEnumTypes.cpp:69
LazyRandomTypeCollection.h
llvm::codeview::LazyRandomTypeCollection
Provides amortized O(1) random access to a CodeView type stream.
Definition: LazyRandomTypeCollection.h:49
llvm::dwarf::Index
Index
Definition: Dwarf.h:472
PDBSymbol.h
PDBTypes.h
llvm::pdb
Definition: ConcreteSymbolEnumerator.h:20
llvm::pdb::SymbolCache::getSymbolById
std::unique_ptr< PDBSymbol > getSymbolById(SymIndexId SymbolId) const
Definition: SymbolCache.cpp:247
llvm::codeview::CVRecord::kind
Kind kind() const
Definition: CVRecord.h:42
llvm::pdb::NativeEnumTypes::getChildCount
uint32_t getChildCount() const override
Definition: NativeEnumTypes.cpp:57
llvm::is_contained
bool is_contained(R &&Range, const E &Element)
Wrapper function around std::find to detect if an element exists in a container.
Definition: STLExtras.h:1682
llvm::pdb::NativeSession::getSymbolCache
SymbolCache & getSymbolCache()
Definition: NativeSession.h:113
IPDBEnumChildren.h
llvm::move
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
Definition: STLExtras.h:1675
TypeRecordHelpers.h
NativeEnumTypes.h
llvm::codeview::CVRecord< TypeLeafKind >
uint32_t
llvm::codeview::LazyRandomTypeCollection::getNext
Optional< TypeIndex > getNext(TypeIndex Prev) override
Definition: LazyRandomTypeCollection.cpp:214
llvm::pdb::SymbolCache::findSymbolByTypeIndex
SymIndexId findSymbolByTypeIndex(codeview::TypeIndex TI) const
Definition: SymbolCache.cpp:158
std
Definition: BitVector.h:851
CVRecord.h
llvm::pdb::NativeSession
Definition: NativeSession.h:32
llvm::codeview::TypeLeafKind
TypeLeafKind
Duplicate copy of the above enum, but using the official CV names.
Definition: CodeView.h:33
llvm::codeview
Definition: AppendingTypeTableBuilder.h:22
llvm::codeview::TypeIndex::isSimple
bool isSimple() const
Definition: TypeIndex.h:113
N
#define N
SymbolCache.h
llvm::codeview::TypeIndex
A 32-bit type reference.
Definition: TypeIndex.h:96
llvm::codeview::LazyRandomTypeCollection::getFirst
Optional< TypeIndex > getFirst() override
Definition: LazyRandomTypeCollection.cpp:205
llvm::codeview::LazyRandomTypeCollection::getType
CVType getType(TypeIndex Index) override
Definition: LazyRandomTypeCollection.cpp:91
llvm::AMDGPU::VGPRIndexMode::Id
Id
Definition: SIDefines.h:241
llvm::pdb::NativeEnumTypes::getChildAtIndex
std::unique_ptr< PDBSymbol > getChildAtIndex(uint32_t Index) const override
Definition: NativeEnumTypes.cpp:61
NativeSession.h