LLVM  14.0.0git
UDTLayout.h
Go to the documentation of this file.
1 //===- UDTLayout.h - UDT layout info ----------------------------*- 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_DEBUGINFO_PDB_UDTLAYOUT_H
10 #define LLVM_DEBUGINFO_PDB_UDTLAYOUT_H
11 
12 #include "llvm/ADT/ArrayRef.h"
13 #include "llvm/ADT/BitVector.h"
14 #include "llvm/ADT/StringRef.h"
22 #include <cstdint>
23 #include <memory>
24 #include <string>
25 #include <vector>
26 
27 namespace llvm {
28 namespace pdb {
29 
30 class BaseClassLayout;
31 class ClassLayout;
32 class UDTLayoutBase;
33 
35 public:
37  const std::string &Name, uint32_t OffsetInParent,
38  uint32_t Size, bool IsElided);
39  virtual ~LayoutItemBase() = default;
40 
41  uint32_t deepPaddingSize() const;
42  virtual uint32_t immediatePadding() const { return 0; }
43  virtual uint32_t tailPadding() const;
44 
45  const UDTLayoutBase *getParent() const { return Parent; }
46  StringRef getName() const { return Name; }
48  uint32_t getSize() const { return SizeOf; }
49  uint32_t getLayoutSize() const { return LayoutSize; }
50  const PDBSymbol *getSymbol() const { return Symbol; }
51  const BitVector &usedBytes() const { return UsedBytes; }
52  bool isElided() const { return IsElided; }
53  virtual bool isVBPtr() const { return false; }
54 
56  uint32_t Begin = getOffsetInParent();
57  uint32_t End = Begin + getSize();
58  return (Off >= Begin && Off < End);
59  }
60 
61 protected:
62  const PDBSymbol *Symbol = nullptr;
63  const UDTLayoutBase *Parent = nullptr;
65  std::string Name;
69  bool IsElided = false;
70 };
71 
73 public:
75  std::unique_ptr<PDBSymbolTypeBuiltin> Sym, uint32_t Offset,
76  uint32_t Size);
77 
78  bool isVBPtr() const override { return true; }
79 
80 private:
81  std::unique_ptr<PDBSymbolTypeBuiltin> Type;
82 };
83 
85 public:
87  std::unique_ptr<PDBSymbolData> DataMember);
88 
90  bool hasUDTLayout() const;
91  const ClassLayout &getUDTLayout() const;
92 
93 private:
94  std::unique_ptr<PDBSymbolData> DataMember;
95  std::unique_ptr<ClassLayout> UdtLayout;
96 };
97 
99 public:
101  std::unique_ptr<PDBSymbolTypeVTable> VTable);
102 
103  uint32_t getElementSize() const { return ElementSize; }
104 
105 private:
106  uint32_t ElementSize = 0;
107  std::unique_ptr<PDBSymbolTypeVTable> VTable;
108 };
109 
111  template <typename T> using UniquePtrVector = std::vector<std::unique_ptr<T>>;
112 
113 public:
114  UDTLayoutBase(const UDTLayoutBase *Parent, const PDBSymbol &Sym,
115  const std::string &Name, uint32_t OffsetInParent, uint32_t Size,
116  bool IsElided);
117 
118  uint32_t tailPadding() const override;
126 
127 protected:
128  bool hasVBPtrAtOffset(uint32_t Off) const;
129  void initializeChildren(const PDBSymbol &Sym);
130 
131  void addChildToLayout(std::unique_ptr<LayoutItemBase> Child);
132 
134 
135  UniquePtrVector<PDBSymbol> Other;
136  UniquePtrVector<PDBSymbolFunc> Funcs;
137  UniquePtrVector<LayoutItemBase> ChildStorage;
138  std::vector<LayoutItemBase *> LayoutItems;
139 
140  std::vector<BaseClassLayout *> AllBases;
143 
145  VBPtrLayoutItem *VBPtr = nullptr;
146 };
147 
149 public:
151  bool Elide, std::unique_ptr<PDBSymbolTypeBaseClass> Base);
152 
153  const PDBSymbolTypeBaseClass &getBase() const { return *Base; }
154  bool isVirtualBase() const { return IsVirtualBase; }
155  bool isEmptyBase() { return SizeOf == 1 && LayoutSize == 0; }
156 
157 private:
158  std::unique_ptr<PDBSymbolTypeBaseClass> Base;
159  bool IsVirtualBase;
160 };
161 
162 class ClassLayout : public UDTLayoutBase {
163 public:
164  explicit ClassLayout(const PDBSymbolTypeUDT &UDT);
165  explicit ClassLayout(std::unique_ptr<PDBSymbolTypeUDT> UDT);
166 
167  ClassLayout(ClassLayout &&Other) = default;
168 
169  const PDBSymbolTypeUDT &getClass() const { return UDT; }
170  uint32_t immediatePadding() const override;
171 
172 private:
173  BitVector ImmediateUsedBytes;
174  std::unique_ptr<PDBSymbolTypeUDT> OwnedStorage;
175  const PDBSymbolTypeUDT &UDT;
176 };
177 
178 } // end namespace pdb
179 } // end namespace llvm
180 
181 #endif // LLVM_DEBUGINFO_PDB_UDTLAYOUT_H
llvm::Check::Size
@ Size
Definition: FileCheck.h:73
llvm::pdb::ClassLayout::getClass
const PDBSymbolTypeUDT & getClass() const
Definition: UDTLayout.h:169
llvm
---------------------— PointerInfo ------------------------------------—
Definition: AllocatorList.h:23
PDBSymbolTypeUDT.h
llvm::pdb::VBPtrLayoutItem::isVBPtr
bool isVBPtr() const override
Definition: UDTLayout.h:78
llvm::pdb::ClassLayout::ClassLayout
ClassLayout(const PDBSymbolTypeUDT &UDT)
Definition: UDTLayout.cpp:130
PDBSymbolTypeBaseClass.h
StringRef.h
llvm::pdb::DataMemberLayoutItem::getUDTLayout
const ClassLayout & getUDTLayout() const
Definition: UDTLayout.cpp:92
llvm::pdb::UDTLayoutBase::layout_items
ArrayRef< LayoutItemBase * > layout_items() const
Definition: UDTLayout.h:119
llvm::pdb::LayoutItemBase::tailPadding
virtual uint32_t tailPadding() const
Definition: UDTLayout.cpp:61
llvm::pdb::LayoutItemBase::LayoutSize
uint32_t LayoutSize
Definition: UDTLayout.h:68
llvm::pdb::LayoutItemBase::getLayoutSize
uint32_t getLayoutSize() const
Definition: UDTLayout.h:49
llvm::pdb::LayoutItemBase::getSize
uint32_t getSize() const
Definition: UDTLayout.h:48
llvm::pdb::UDTLayoutBase::VBPtr
VBPtrLayoutItem * VBPtr
Definition: UDTLayout.h:145
PDBSymbolTypeBuiltin.h
llvm::Type
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:45
llvm::pdb::LayoutItemBase::isElided
bool isElided() const
Definition: UDTLayout.h:52
Offset
uint64_t Offset
Definition: ELFObjHandler.cpp:81
llvm::pdb::PDBSymbolData
Definition: PDBSymbolData.h:22
llvm::pdb::UDTLayoutBase::UDTLayoutBase
UDTLayoutBase(const UDTLayoutBase *Parent, const PDBSymbol &Sym, const std::string &Name, uint32_t OffsetInParent, uint32_t Size, bool IsElided)
Definition: UDTLayout.cpp:104
llvm::pdb::UDTLayoutBase::regular_bases
ArrayRef< BaseClassLayout * > regular_bases() const
Definition: UDTLayout.h:121
llvm::pdb::UDTLayoutBase::AllBases
std::vector< BaseClassLayout * > AllBases
Definition: UDTLayout.h:140
llvm::pdb::UDTLayoutBase::virtual_bases
ArrayRef< BaseClassLayout * > virtual_bases() const
Definition: UDTLayout.h:122
llvm::pdb::LayoutItemBase::deepPaddingSize
uint32_t deepPaddingSize() const
Definition: UDTLayout.cpp:57
llvm::pdb::BaseClassLayout::isEmptyBase
bool isEmptyBase()
Definition: UDTLayout.h:155
llvm::pdb::UDTLayoutBase::tailPadding
uint32_t tailPadding() const override
Definition: UDTLayout.cpp:117
llvm::pdb::LayoutItemBase::getName
StringRef getName() const
Definition: UDTLayout.h:46
llvm::pdb::VBPtrLayoutItem::VBPtrLayoutItem
VBPtrLayoutItem(const UDTLayoutBase &Parent, std::unique_ptr< PDBSymbolTypeBuiltin > Sym, uint32_t Offset, uint32_t Size)
Definition: UDTLayout.cpp:79
PDBSymbolTypeVTable.h
llvm::pdb::UDTLayoutBase
Definition: UDTLayout.h:110
llvm::pdb::UDTLayoutBase::VTable
VTableLayoutItem * VTable
Definition: UDTLayout.h:144
llvm::pdb::PDBSymbolTypeBaseClass
Definition: PDBSymbolTypeBaseClass.h:23
llvm::pdb::PDB_SymType::UDT
@ UDT
llvm::pdb::DataMemberLayoutItem::getDataMember
const PDBSymbolData & getDataMember()
Definition: UDTLayout.cpp:86
llvm::pdb::PDBSymbol
PDBSymbol defines the base of the inheritance hierarchy for concrete symbol types (e....
Definition: PDBSymbol.h:70
BitVector.h
llvm::BitVector
Definition: BitVector.h:74
llvm::pdb::LayoutItemBase::OffsetInParent
uint32_t OffsetInParent
Definition: UDTLayout.h:66
PDBSymbol.h
PDBTypes.h
llvm::pdb::UDTLayoutBase::NonVirtualBases
ArrayRef< BaseClassLayout * > NonVirtualBases
Definition: UDTLayout.h:141
llvm::pdb::UDTLayoutBase::directVirtualBaseCount
uint32_t directVirtualBaseCount() const
Definition: UDTLayout.h:123
llvm::pdb::VBPtrLayoutItem
Definition: UDTLayout.h:72
llvm::pdb::LayoutItemBase::~LayoutItemBase
virtual ~LayoutItemBase()=default
llvm::pdb::LayoutItemBase::IsElided
bool IsElided
Definition: UDTLayout.h:69
llvm::pdb::UDTLayoutBase::funcs
ArrayRef< std::unique_ptr< PDBSymbolFunc > > funcs() const
Definition: UDTLayout.h:124
llvm::pdb::UDTLayoutBase::other_items
ArrayRef< std::unique_ptr< PDBSymbol > > other_items() const
Definition: UDTLayout.h:125
llvm::pdb::UDTLayoutBase::LayoutItems
std::vector< LayoutItemBase * > LayoutItems
Definition: UDTLayout.h:138
llvm::pdb::DataMemberLayoutItem::DataMemberLayoutItem
DataMemberLayoutItem(const UDTLayoutBase &Parent, std::unique_ptr< PDBSymbolData > DataMember)
Definition: UDTLayout.cpp:67
llvm::pdb::BaseClassLayout
Definition: UDTLayout.h:148
llvm::pdb::LayoutItemBase::immediatePadding
virtual uint32_t immediatePadding() const
Definition: UDTLayout.h:42
llvm::pdb::UDTLayoutBase::VirtualBases
ArrayRef< BaseClassLayout * > VirtualBases
Definition: UDTLayout.h:142
llvm::pdb::LayoutItemBase::getOffsetInParent
uint32_t getOffsetInParent() const
Definition: UDTLayout.h:47
llvm::pdb::LayoutItemBase::usedBytes
const BitVector & usedBytes() const
Definition: UDTLayout.h:51
ArrayRef.h
llvm::pdb::PDB_SymType::VTable
@ VTable
llvm::pdb::UDTLayoutBase::hasVBPtrAtOffset
bool hasVBPtrAtOffset(uint32_t Off) const
Definition: UDTLayout.cpp:267
llvm::pdb::UDTLayoutBase::DirectVBaseCount
uint32_t DirectVBaseCount
Definition: UDTLayout.h:133
llvm::pdb::VTableLayoutItem
Definition: UDTLayout.h:98
llvm::pdb::LayoutItemBase::SizeOf
uint32_t SizeOf
Definition: UDTLayout.h:67
llvm::pdb::LayoutItemBase::isVBPtr
virtual bool isVBPtr() const
Definition: UDTLayout.h:53
llvm::pdb::LayoutItemBase::Name
std::string Name
Definition: UDTLayout.h:65
llvm::pdb::LayoutItemBase::containsOffset
uint32_t containsOffset(uint32_t Off) const
Definition: UDTLayout.h:55
llvm::pdb::UDTLayoutBase::Other
UniquePtrVector< PDBSymbol > Other
Definition: UDTLayout.h:135
llvm::ArrayRef
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: APInt.h:32
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:58
uint32_t
llvm::pdb::UDTLayoutBase::Funcs
UniquePtrVector< PDBSymbolFunc > Funcs
Definition: UDTLayout.h:136
llvm::pdb::ClassLayout::immediatePadding
uint32_t immediatePadding() const override
Definition: UDTLayout.cpp:147
llvm::pdb::UDTLayoutBase::addChildToLayout
void addChildToLayout(std::unique_ptr< LayoutItemBase > Child)
Definition: UDTLayout.cpp:277
llvm::pdb::LayoutItemBase::getSymbol
const PDBSymbol * getSymbol() const
Definition: UDTLayout.h:50
llvm::pdb::BaseClassLayout::BaseClassLayout
BaseClassLayout(const UDTLayoutBase &Parent, uint32_t OffsetInParent, bool Elide, std::unique_ptr< PDBSymbolTypeBaseClass > Base)
Definition: UDTLayout.cpp:151
llvm::pdb::LayoutItemBase::LayoutItemBase
LayoutItemBase(const UDTLayoutBase *Parent, const PDBSymbol *Symbol, const std::string &Name, uint32_t OffsetInParent, uint32_t Size, bool IsElided)
Definition: UDTLayout.cpp:47
llvm::pdb::UDTLayoutBase::initializeChildren
void initializeChildren(const PDBSymbol &Sym)
Definition: UDTLayout.cpp:165
llvm::pdb::UDTLayoutBase::bases
ArrayRef< BaseClassLayout * > bases() const
Definition: UDTLayout.h:120
llvm::pdb::LayoutItemBase::Symbol
const PDBSymbol * Symbol
Definition: UDTLayout.h:62
llvm::pdb::LayoutItemBase
Definition: UDTLayout.h:34
llvm::pdb::DataMemberLayoutItem::hasUDTLayout
bool hasUDTLayout() const
Definition: UDTLayout.cpp:90
llvm::pdb::BaseClassLayout::isVirtualBase
bool isVirtualBase() const
Definition: UDTLayout.h:154
llvm::pdb::BaseClassLayout::getBase
const PDBSymbolTypeBaseClass & getBase() const
Definition: UDTLayout.h:153
llvm::pdb::UDTLayoutBase::ChildStorage
UniquePtrVector< LayoutItemBase > ChildStorage
Definition: UDTLayout.h:137
llvm::pdb::PDBSymbolTypeUDT
Definition: PDBSymbolTypeUDT.h:24
llvm::pdb::LayoutItemBase::UsedBytes
BitVector UsedBytes
Definition: UDTLayout.h:64
llvm::pdb::VTableLayoutItem::getElementSize
uint32_t getElementSize() const
Definition: UDTLayout.h:103
llvm::pdb::LayoutItemBase::getParent
const UDTLayoutBase * getParent() const
Definition: UDTLayout.h:45
PDBSymbolData.h
llvm::pdb::LayoutItemBase::Parent
const UDTLayoutBase * Parent
Definition: UDTLayout.h:63
llvm::pdb::ClassLayout
Definition: UDTLayout.h:162
llvm::pdb::DataMemberLayoutItem
Definition: UDTLayout.h:84
llvm::sampleprof::Base
@ Base
Definition: Discriminator.h:58
llvm::pdb::VTableLayoutItem::VTableLayoutItem
VTableLayoutItem(const UDTLayoutBase &Parent, std::unique_ptr< PDBSymbolTypeVTable > VTable)
Definition: UDTLayout.cpp:96