LLVM  9.0.0svn
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;
66  uint32_t OffsetInParent = 0;
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 
89  const PDBSymbolData &getDataMember();
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;
119  ArrayRef<LayoutItemBase *> layout_items() const { return LayoutItems; }
120  ArrayRef<BaseClassLayout *> bases() const { return AllBases; }
121  ArrayRef<BaseClassLayout *> regular_bases() const { return NonVirtualBases; }
122  ArrayRef<BaseClassLayout *> virtual_bases() const { return VirtualBases; }
123  uint32_t directVirtualBaseCount() const { return DirectVBaseCount; }
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 
133  uint32_t DirectVBaseCount = 0;
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
ArrayRef< std::unique_ptr< PDBSymbolFunc > > funcs() const
Definition: UDTLayout.h:124
bool isVBPtr() const override
Definition: UDTLayout.h:78
UniquePtrVector< PDBSymbolFunc > Funcs
Definition: UDTLayout.h:136
This class represents lattice values for constants.
Definition: AllocatorList.h:23
const UDTLayoutBase * Parent
Definition: UDTLayout.h:63
const PDBSymbolTypeBaseClass & getBase() const
Definition: UDTLayout.h:153
UniquePtrVector< PDBSymbol > Other
Definition: UDTLayout.h:135
uint32_t directVirtualBaseCount() const
Definition: UDTLayout.h:123
UniquePtrVector< LayoutItemBase > ChildStorage
Definition: UDTLayout.h:137
const PDBSymbol * getSymbol() const
Definition: UDTLayout.h:50
uint32_t containsOffset(uint32_t Off) const
Definition: UDTLayout.h:55
virtual uint32_t immediatePadding() const
Definition: UDTLayout.h:42
ArrayRef< BaseClassLayout * > regular_bases() const
Definition: UDTLayout.h:121
virtual ~LayoutItemBase()=default
virtual bool isVBPtr() const
Definition: UDTLayout.h:53
ArrayRef< BaseClassLayout * > VirtualBases
Definition: UDTLayout.h:142
uint32_t getOffsetInParent() const
Definition: UDTLayout.h:47
uint32_t getElementSize() const
Definition: UDTLayout.h:103
const UDTLayoutBase * getParent() const
Definition: UDTLayout.h:45
ELFYAML::ELF_STO Other
Definition: ELFYAML.cpp:870
std::vector< LayoutItemBase * > LayoutItems
Definition: UDTLayout.h:138
ArrayRef< BaseClassLayout * > virtual_bases() const
Definition: UDTLayout.h:122
uint32_t deepPaddingSize() const
Definition: UDTLayout.cpp:57
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
Definition: APInt.h:32
StringRef getName() const
Definition: UDTLayout.h:46
const PDBSymbol * Symbol
Definition: UDTLayout.h:62
std::vector< BaseClassLayout * > AllBases
Definition: UDTLayout.h:140
ArrayRef< BaseClassLayout * > NonVirtualBases
Definition: UDTLayout.h:141
uint32_t getLayoutSize() const
Definition: UDTLayout.h:49
uint32_t getSize() const
Definition: UDTLayout.h:48
virtual uint32_t tailPadding() const
Definition: UDTLayout.cpp:61
ArrayRef< std::unique_ptr< PDBSymbol > > other_items() const
Definition: UDTLayout.h:125
PDBSymbol defines the base of the inheritance hierarchy for concrete symbol types (e...
Definition: PDBSymbol.h:73
bool isElided() const
Definition: UDTLayout.h:52
const BitVector & usedBytes() const
Definition: UDTLayout.h:51
uint32_t Size
Definition: Profile.cpp:46
ArrayRef< BaseClassLayout * > bases() const
Definition: UDTLayout.h:120
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:48
ArrayRef< LayoutItemBase * > layout_items() const
Definition: UDTLayout.h:119
bool isVirtualBase() const
Definition: UDTLayout.h:154
const PDBSymbolTypeUDT & getClass() const
Definition: UDTLayout.h:169
LayoutItemBase(const UDTLayoutBase *Parent, const PDBSymbol *Symbol, const std::string &Name, uint32_t OffsetInParent, uint32_t Size, bool IsElided)
Definition: UDTLayout.cpp:47