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