| 1 | |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
| 6 | |
| 7 | |
| 8 | |
| 9 | #ifndef LLVM_CLANG_LIB_CODEGEN_CGRECORDLAYOUT_H |
| 10 | #define LLVM_CLANG_LIB_CODEGEN_CGRECORDLAYOUT_H |
| 11 | |
| 12 | #include "clang/AST/CharUnits.h" |
| 13 | #include "clang/AST/DeclCXX.h" |
| 14 | #include "clang/Basic/LLVM.h" |
| 15 | #include "llvm/ADT/DenseMap.h" |
| 16 | #include "llvm/IR/DerivedTypes.h" |
| 17 | |
| 18 | namespace llvm { |
| 19 | class StructType; |
| 20 | } |
| 21 | |
| 22 | namespace clang { |
| 23 | namespace CodeGen { |
| 24 | |
| 25 | |
| 26 | |
| 27 | |
| 28 | |
| 29 | |
| 30 | |
| 31 | |
| 32 | |
| 33 | |
| 34 | |
| 35 | |
| 36 | |
| 37 | |
| 38 | |
| 39 | |
| 40 | |
| 41 | |
| 42 | |
| 43 | |
| 44 | |
| 45 | |
| 46 | |
| 47 | |
| 48 | |
| 49 | |
| 50 | |
| 51 | |
| 52 | |
| 53 | |
| 54 | |
| 55 | |
| 56 | |
| 57 | |
| 58 | |
| 59 | |
| 60 | |
| 61 | |
| 62 | |
| 63 | |
| 64 | |
| 65 | struct CGBitFieldInfo { |
| 66 | |
| 67 | |
| 68 | unsigned Offset : 16; |
| 69 | |
| 70 | |
| 71 | unsigned Size : 15; |
| 72 | |
| 73 | |
| 74 | unsigned IsSigned : 1; |
| 75 | |
| 76 | |
| 77 | |
| 78 | unsigned StorageSize; |
| 79 | |
| 80 | |
| 81 | CharUnits StorageOffset; |
| 82 | |
| 83 | CGBitFieldInfo() |
| 84 | : Offset(), Size(), IsSigned(), StorageSize(), StorageOffset() {} |
| 85 | |
| 86 | CGBitFieldInfo(unsigned Offset, unsigned Size, bool IsSigned, |
| 87 | unsigned StorageSize, CharUnits StorageOffset) |
| 88 | : Offset(Offset), Size(Size), IsSigned(IsSigned), |
| 89 | StorageSize(StorageSize), StorageOffset(StorageOffset) {} |
| 90 | |
| 91 | void print(raw_ostream &OS) const; |
| 92 | void dump() const; |
| 93 | |
| 94 | |
| 95 | |
| 96 | |
| 97 | static CGBitFieldInfo MakeInfo(class CodeGenTypes &Types, |
| 98 | const FieldDecl *FD, |
| 99 | uint64_t Offset, uint64_t Size, |
| 100 | uint64_t StorageSize, |
| 101 | CharUnits StorageOffset); |
| 102 | }; |
| 103 | |
| 104 | |
| 105 | |
| 106 | |
| 107 | |
| 108 | class CGRecordLayout { |
| 109 | friend class CodeGenTypes; |
| 110 | |
| 111 | CGRecordLayout(const CGRecordLayout &) = delete; |
| 112 | void operator=(const CGRecordLayout &) = delete; |
| 113 | |
| 114 | private: |
| 115 | |
| 116 | |
| 117 | llvm::StructType *CompleteObjectType; |
| 118 | |
| 119 | |
| 120 | |
| 121 | llvm::StructType *BaseSubobjectType; |
| 122 | |
| 123 | |
| 124 | |
| 125 | llvm::DenseMap<const FieldDecl *, unsigned> FieldInfo; |
| 126 | |
| 127 | |
| 128 | |
| 129 | llvm::DenseMap<const FieldDecl *, CGBitFieldInfo> BitFields; |
| 130 | |
| 131 | |
| 132 | |
| 133 | llvm::DenseMap<const CXXRecordDecl *, unsigned> NonVirtualBases; |
| 134 | |
| 135 | |
| 136 | llvm::DenseMap<const CXXRecordDecl *, unsigned> CompleteObjectVirtualBases; |
| 137 | |
| 138 | |
| 139 | |
| 140 | |
| 141 | bool IsZeroInitializable : 1; |
| 142 | |
| 143 | |
| 144 | |
| 145 | |
| 146 | bool IsZeroInitializableAsBase : 1; |
| 147 | |
| 148 | public: |
| 149 | CGRecordLayout(llvm::StructType *CompleteObjectType, |
| 150 | llvm::StructType *BaseSubobjectType, |
| 151 | bool IsZeroInitializable, |
| 152 | bool IsZeroInitializableAsBase) |
| 153 | : CompleteObjectType(CompleteObjectType), |
| 154 | BaseSubobjectType(BaseSubobjectType), |
| 155 | IsZeroInitializable(IsZeroInitializable), |
| 156 | IsZeroInitializableAsBase(IsZeroInitializableAsBase) {} |
| 157 | |
| 158 | |
| 159 | |
| 160 | llvm::StructType *getLLVMType() const { |
| 161 | return CompleteObjectType; |
| 162 | } |
| 163 | |
| 164 | |
| 165 | |
| 166 | llvm::StructType *getBaseSubobjectLLVMType() const { |
| 167 | return BaseSubobjectType; |
| 168 | } |
| 169 | |
| 170 | |
| 171 | |
| 172 | bool isZeroInitializable() const { |
| 173 | return IsZeroInitializable; |
| 174 | } |
| 175 | |
| 176 | |
| 177 | |
| 178 | bool isZeroInitializableAsBase() const { |
| 179 | return IsZeroInitializableAsBase; |
| 180 | } |
| 181 | |
| 182 | |
| 183 | |
| 184 | unsigned getLLVMFieldNo(const FieldDecl *FD) const { |
| 185 | FD = FD->getCanonicalDecl(); |
| 186 | (0) . __assert_fail ("FieldInfo.count(FD) && \"Invalid field for record!\"", "/home/seafit/code_projects/clang_source/clang/lib/CodeGen/CGRecordLayout.h", 186, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(FieldInfo.count(FD) && "Invalid field for record!"); |
| 187 | return FieldInfo.lookup(FD); |
| 188 | } |
| 189 | |
| 190 | unsigned getNonVirtualBaseLLVMFieldNo(const CXXRecordDecl *RD) const { |
| 191 | (0) . __assert_fail ("NonVirtualBases.count(RD) && \"Invalid non-virtual base!\"", "/home/seafit/code_projects/clang_source/clang/lib/CodeGen/CGRecordLayout.h", 191, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(NonVirtualBases.count(RD) && "Invalid non-virtual base!"); |
| 192 | return NonVirtualBases.lookup(RD); |
| 193 | } |
| 194 | |
| 195 | |
| 196 | |
| 197 | unsigned getVirtualBaseIndex(const CXXRecordDecl *base) const { |
| 198 | (0) . __assert_fail ("CompleteObjectVirtualBases.count(base) && \"Invalid virtual base!\"", "/home/seafit/code_projects/clang_source/clang/lib/CodeGen/CGRecordLayout.h", 198, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(CompleteObjectVirtualBases.count(base) && "Invalid virtual base!"); |
| 199 | return CompleteObjectVirtualBases.lookup(base); |
| 200 | } |
| 201 | |
| 202 | |
| 203 | const CGBitFieldInfo &getBitFieldInfo(const FieldDecl *FD) const { |
| 204 | FD = FD->getCanonicalDecl(); |
| 205 | (0) . __assert_fail ("FD->isBitField() && \"Invalid call for non-bit-field decl!\"", "/home/seafit/code_projects/clang_source/clang/lib/CodeGen/CGRecordLayout.h", 205, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(FD->isBitField() && "Invalid call for non-bit-field decl!"); |
| 206 | llvm::DenseMap<const FieldDecl *, CGBitFieldInfo>::const_iterator |
| 207 | it = BitFields.find(FD); |
| 208 | (0) . __assert_fail ("it != BitFields.end() && \"Unable to find bitfield info\"", "/home/seafit/code_projects/clang_source/clang/lib/CodeGen/CGRecordLayout.h", 208, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(it != BitFields.end() && "Unable to find bitfield info"); |
| 209 | return it->second; |
| 210 | } |
| 211 | |
| 212 | void print(raw_ostream &OS) const; |
| 213 | void dump() const; |
| 214 | }; |
| 215 | |
| 216 | } |
| 217 | } |
| 218 | |
| 219 | #endif |
| 220 | |