LLVM  8.0.0svn
UDTLayout.h
Go to the documentation of this file.
1 //===- UDTLayout.h - UDT layout info ----------------------------*- C++ -*-===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
10 #ifndef LLVM_DEBUGINFO_PDB_UDTLAYOUT_H
11 #define LLVM_DEBUGINFO_PDB_UDTLAYOUT_H
12 
13 #include "llvm/ADT/ArrayRef.h"
14 #include "llvm/ADT/BitVector.h"
15 #include "llvm/ADT/StringRef.h"
23 #include <cstdint>
24 #include <memory>
25 #include <string>
26 #include <vector>
27 
28 namespace llvm {
29 namespace pdb {
30 
31 class BaseClassLayout;
32 class ClassLayout;
33 class UDTLayoutBase;
34 
36 public:
38  const std::string &Name, uint32_t OffsetInParent,
39  uint32_t Size, bool IsElided);
40  virtual ~LayoutItemBase() = default;
41 
42  uint32_t deepPaddingSize() const;
43  virtual uint32_t immediatePadding() const { return 0; }
44  virtual uint32_t tailPadding() const;
45 
46  const UDTLayoutBase *getParent() const { return Parent; }
47  StringRef getName() const { return Name; }
49  uint32_t getSize() const { return SizeOf; }
50  uint32_t getLayoutSize() const { return LayoutSize; }
51  const PDBSymbol *getSymbol() const { return Symbol; }
52  const BitVector &usedBytes() const { return UsedBytes; }
53  bool isElided() const { return IsElided; }
54  virtual bool isVBPtr() const { return false; }
55 
57  uint32_t Begin = getOffsetInParent();
58  uint32_t End = Begin + getSize();
59  return (Off >= Begin && Off < End);
60  }
61 
62 protected:
63  const PDBSymbol *Symbol = nullptr;
64  const UDTLayoutBase *Parent = nullptr;
66  std::string Name;
67  uint32_t OffsetInParent = 0;
70  bool IsElided = false;
71 };
72 
74 public:
76  std::unique_ptr<PDBSymbolTypeBuiltin> Sym, uint32_t Offset,
77  uint32_t Size);
78 
79  bool isVBPtr() const override { return true; }
80 
81 private:
82  std::unique_ptr<PDBSymbolTypeBuiltin> Type;
83 };
84 
86 public:
88  std::unique_ptr<PDBSymbolData> DataMember);
89 
90  const PDBSymbolData &getDataMember();
91  bool hasUDTLayout() const;
92  const ClassLayout &getUDTLayout() const;
93 
94 private:
95  std::unique_ptr<PDBSymbolData> DataMember;
96  std::unique_ptr<ClassLayout> UdtLayout;
97 };
98 
100 public:
102  std::unique_ptr<PDBSymbolTypeVTable> VTable);
103 
104  uint32_t getElementSize() const { return ElementSize; }
105 
106 private:
107  uint32_t ElementSize = 0;
108  std::unique_ptr<PDBSymbolTypeVTable> VTable;
109 };
110 
112  template <typename T> using UniquePtrVector = std::vector<std::unique_ptr<T>>;
113 
114 public:
115  UDTLayoutBase(const UDTLayoutBase *Parent, const PDBSymbol &Sym,
116  const std::string &Name, uint32_t OffsetInParent, uint32_t Size,
117  bool IsElided);
118 
119  uint32_t tailPadding() const override;
120  ArrayRef<LayoutItemBase *> layout_items() const { return LayoutItems; }
121  ArrayRef<BaseClassLayout *> bases() const { return AllBases; }
122  ArrayRef<BaseClassLayout *> regular_bases() const { return NonVirtualBases; }
123  ArrayRef<BaseClassLayout *> virtual_bases() const { return VirtualBases; }
124  uint32_t directVirtualBaseCount() const { return DirectVBaseCount; }
127 
128 protected:
129  bool hasVBPtrAtOffset(uint32_t Off) const;
130  void initializeChildren(const PDBSymbol &Sym);
131 
132  void addChildToLayout(std::unique_ptr<LayoutItemBase> Child);
133 
134  uint32_t DirectVBaseCount = 0;
135 
136  UniquePtrVector<PDBSymbol> Other;
137  UniquePtrVector<PDBSymbolFunc> Funcs;
138  UniquePtrVector<LayoutItemBase> ChildStorage;
139  std::vector<LayoutItemBase *> LayoutItems;
140 
141  std::vector<BaseClassLayout *> AllBases;
144 
146  VBPtrLayoutItem *VBPtr = nullptr;
147 };
148 
150 public:
152  bool Elide, std::unique_ptr<PDBSymbolTypeBaseClass> Base);
153 
154  const PDBSymbolTypeBaseClass &getBase() const { return *Base; }
155  bool isVirtualBase() const { return IsVirtualBase; }
156  bool isEmptyBase() { return SizeOf == 1 && LayoutSize == 0; }
157 
158 private:
159  std::unique_ptr<PDBSymbolTypeBaseClass> Base;
160  bool IsVirtualBase;
161 };
162 
163 class ClassLayout : public UDTLayoutBase {
164 public:
165  explicit ClassLayout(const PDBSymbolTypeUDT &UDT);
166  explicit ClassLayout(std::unique_ptr<PDBSymbolTypeUDT> UDT);
167 
168  ClassLayout(ClassLayout &&Other) = default;
169 
170  const PDBSymbolTypeUDT &getClass() const { return UDT; }
171  uint32_t immediatePadding() const override;
172 
173 private:
174  BitVector ImmediateUsedBytes;
175  std::unique_ptr<PDBSymbolTypeUDT> OwnedStorage;
176  const PDBSymbolTypeUDT &UDT;
177 };
178 
179 } // end namespace pdb
180 } // end namespace llvm
181 
182 #endif // LLVM_DEBUGINFO_PDB_UDTLAYOUT_H
ArrayRef< std::unique_ptr< PDBSymbolFunc > > funcs() const
Definition: UDTLayout.h:125
bool isVBPtr() const override
Definition: UDTLayout.h:79
UniquePtrVector< PDBSymbolFunc > Funcs
Definition: UDTLayout.h:137
Compute iterated dominance frontiers using a linear time algorithm.
Definition: AllocatorList.h:24
const UDTLayoutBase * Parent
Definition: UDTLayout.h:64
const PDBSymbolTypeBaseClass & getBase() const
Definition: UDTLayout.h:154
UniquePtrVector< PDBSymbol > Other
Definition: UDTLayout.h:136
uint32_t directVirtualBaseCount() const
Definition: UDTLayout.h:124
UniquePtrVector< LayoutItemBase > ChildStorage
Definition: UDTLayout.h:138
const PDBSymbol * getSymbol() const
Definition: UDTLayout.h:51
uint32_t containsOffset(uint32_t Off) const
Definition: UDTLayout.h:56
virtual uint32_t immediatePadding() const
Definition: UDTLayout.h:43
ArrayRef< BaseClassLayout * > regular_bases() const
Definition: UDTLayout.h:122
virtual ~LayoutItemBase()=default
virtual bool isVBPtr() const
Definition: UDTLayout.h:54
ArrayRef< BaseClassLayout * > VirtualBases
Definition: UDTLayout.h:143
uint32_t getOffsetInParent() const
Definition: UDTLayout.h:48
uint32_t getElementSize() const
Definition: UDTLayout.h:104
const UDTLayoutBase * getParent() const
Definition: UDTLayout.h:46
ELFYAML::ELF_STO Other
Definition: ELFYAML.cpp:775
std::vector< LayoutItemBase * > LayoutItems
Definition: UDTLayout.h:139
ArrayRef< BaseClassLayout * > virtual_bases() const
Definition: UDTLayout.h:123
uint32_t deepPaddingSize() const
Definition: UDTLayout.cpp:58
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
Definition: APInt.h:33
StringRef getName() const
Definition: UDTLayout.h:47
const PDBSymbol * Symbol
Definition: UDTLayout.h:63
std::vector< BaseClassLayout * > AllBases
Definition: UDTLayout.h:141
ArrayRef< BaseClassLayout * > NonVirtualBases
Definition: UDTLayout.h:142
uint32_t getLayoutSize() const
Definition: UDTLayout.h:50
uint32_t getSize() const
Definition: UDTLayout.h:49
virtual uint32_t tailPadding() const
Definition: UDTLayout.cpp:62
ArrayRef< std::unique_ptr< PDBSymbol > > other_items() const
Definition: UDTLayout.h:126
PDBSymbol defines the base of the inheritance hierarchy for concrete symbol types (e...
Definition: PDBSymbol.h:74
bool isElided() const
Definition: UDTLayout.h:53
const BitVector & usedBytes() const
Definition: UDTLayout.h:52
uint32_t Size
Definition: Profile.cpp:47
ArrayRef< BaseClassLayout * > bases() const
Definition: UDTLayout.h:121
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:49
ArrayRef< LayoutItemBase * > layout_items() const
Definition: UDTLayout.h:120
bool isVirtualBase() const
Definition: UDTLayout.h:155
const PDBSymbolTypeUDT & getClass() const
Definition: UDTLayout.h:170
LayoutItemBase(const UDTLayoutBase *Parent, const PDBSymbol *Symbol, const std::string &Name, uint32_t OffsetInParent, uint32_t Size, bool IsElided)
Definition: UDTLayout.cpp:48