CGRecordLayoutBuilder.cpp (206084) | CGRecordLayoutBuilder.cpp (206275) |
---|---|
1//===--- CGRecordLayoutBuilder.cpp - CGRecordLayout builder ----*- 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//===----------------------------------------------------------------------===// --- 23 unchanged lines hidden (view full) --- 32 /// FieldTypes - Holds the LLVM types that the struct is created from. 33 std::vector<const llvm::Type *> FieldTypes; 34 35 /// LLVMFieldInfo - Holds a field and its corresponding LLVM field number. 36 typedef std::pair<const FieldDecl *, unsigned> LLVMFieldInfo; 37 llvm::SmallVector<LLVMFieldInfo, 16> LLVMFields; 38 39 /// LLVMBitFieldInfo - Holds location and size information about a bit field. | 1//===--- CGRecordLayoutBuilder.cpp - CGRecordLayout builder ----*- 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//===----------------------------------------------------------------------===// --- 23 unchanged lines hidden (view full) --- 32 /// FieldTypes - Holds the LLVM types that the struct is created from. 33 std::vector<const llvm::Type *> FieldTypes; 34 35 /// LLVMFieldInfo - Holds a field and its corresponding LLVM field number. 36 typedef std::pair<const FieldDecl *, unsigned> LLVMFieldInfo; 37 llvm::SmallVector<LLVMFieldInfo, 16> LLVMFields; 38 39 /// LLVMBitFieldInfo - Holds location and size information about a bit field. |
40 struct LLVMBitFieldInfo { 41 LLVMBitFieldInfo(const FieldDecl *FD, unsigned FieldNo, unsigned Start, 42 unsigned Size) 43 : FD(FD), FieldNo(FieldNo), Start(Start), Size(Size) { } 44 45 const FieldDecl *FD; 46 47 unsigned FieldNo; 48 unsigned Start; 49 unsigned Size; 50 }; | 40 typedef std::pair<const FieldDecl *, CGBitFieldInfo> LLVMBitFieldInfo; |
51 llvm::SmallVector<LLVMBitFieldInfo, 16> LLVMBitFields; 52 53 /// ContainsPointerToDataMember - Whether one of the fields in this record 54 /// layout is a pointer to data member, or a struct that contains pointer to 55 /// data member. 56 bool ContainsPointerToDataMember; 57 58 /// Packed - Whether the resulting LLVM struct will be packed or not. --- 124 unchanged lines hidden (view full) --- 183 llvm::RoundUpToAlignment(FieldSize, 8) / 8; 184 185 assert(NumBytesToAppend && "No bytes to append!"); 186 } 187 188 const llvm::Type *Ty = Types.ConvertTypeForMemRecursive(D->getType()); 189 uint64_t TypeSizeInBits = getTypeSizeInBytes(Ty) * 8; 190 | 41 llvm::SmallVector<LLVMBitFieldInfo, 16> LLVMBitFields; 42 43 /// ContainsPointerToDataMember - Whether one of the fields in this record 44 /// layout is a pointer to data member, or a struct that contains pointer to 45 /// data member. 46 bool ContainsPointerToDataMember; 47 48 /// Packed - Whether the resulting LLVM struct will be packed or not. --- 124 unchanged lines hidden (view full) --- 173 llvm::RoundUpToAlignment(FieldSize, 8) / 8; 174 175 assert(NumBytesToAppend && "No bytes to append!"); 176 } 177 178 const llvm::Type *Ty = Types.ConvertTypeForMemRecursive(D->getType()); 179 uint64_t TypeSizeInBits = getTypeSizeInBytes(Ty) * 8; 180 |
191 LLVMBitFields.push_back(LLVMBitFieldInfo(D, FieldOffset / TypeSizeInBits, 192 FieldOffset % TypeSizeInBits, 193 FieldSize)); | 181 bool IsSigned = D->getType()->isSignedIntegerType(); 182 LLVMBitFields.push_back(LLVMBitFieldInfo( 183 D, CGBitFieldInfo(FieldOffset / TypeSizeInBits, 184 FieldOffset % TypeSizeInBits, 185 FieldSize, IsSigned))); |
194 195 AppendBytes(NumBytesToAppend); 196 197 BitsAvailableInLastField = 198 NextFieldOffsetInBytes * 8 - (FieldOffset + FieldSize); 199} 200 201bool CGRecordLayoutBuilder::LayoutField(const FieldDecl *D, --- 81 unchanged lines hidden (view full) --- 283 uint64_t FieldSize = 284 Field->getBitWidth()->EvaluateAsInt(Types.getContext()).getZExtValue(); 285 286 // Ignore zero sized bit fields. 287 if (FieldSize == 0) 288 continue; 289 290 // Add the bit field info. | 186 187 AppendBytes(NumBytesToAppend); 188 189 BitsAvailableInLastField = 190 NextFieldOffsetInBytes * 8 - (FieldOffset + FieldSize); 191} 192 193bool CGRecordLayoutBuilder::LayoutField(const FieldDecl *D, --- 81 unchanged lines hidden (view full) --- 275 uint64_t FieldSize = 276 Field->getBitWidth()->EvaluateAsInt(Types.getContext()).getZExtValue(); 277 278 // Ignore zero sized bit fields. 279 if (FieldSize == 0) 280 continue; 281 282 // Add the bit field info. |
291 LLVMBitFields.push_back(LLVMBitFieldInfo(*Field, 0, 0, FieldSize)); | 283 bool IsSigned = Field->getType()->isSignedIntegerType(); 284 LLVMBitFields.push_back(LLVMBitFieldInfo( 285 *Field, CGBitFieldInfo(0, 0, FieldSize, 286 IsSigned))); |
292 } else { 293 LLVMFields.push_back(LLVMFieldInfo(*Field, 0)); 294 } 295 296 HasOnlyZeroSizedBitFields = false; 297 298 const llvm::Type *FieldTy = 299 Types.ConvertTypeForMemRecursive(Field->getType()); --- 189 unchanged lines hidden (view full) --- 489 assert(getContext().getASTRecordLayout(D).getSize() / 8 == 490 getTargetData().getTypeAllocSize(Ty) && 491 "Type size mismatch!"); 492 493 CGRecordLayout *RL = 494 new CGRecordLayout(Ty, Builder.ContainsPointerToDataMember); 495 496 // Add all the field numbers. | 287 } else { 288 LLVMFields.push_back(LLVMFieldInfo(*Field, 0)); 289 } 290 291 HasOnlyZeroSizedBitFields = false; 292 293 const llvm::Type *FieldTy = 294 Types.ConvertTypeForMemRecursive(Field->getType()); --- 189 unchanged lines hidden (view full) --- 484 assert(getContext().getASTRecordLayout(D).getSize() / 8 == 485 getTargetData().getTypeAllocSize(Ty) && 486 "Type size mismatch!"); 487 488 CGRecordLayout *RL = 489 new CGRecordLayout(Ty, Builder.ContainsPointerToDataMember); 490 491 // Add all the field numbers. |
497 for (unsigned i = 0, e = Builder.LLVMFields.size(); i != e; ++i) { 498 const FieldDecl *FD = Builder.LLVMFields[i].first; 499 unsigned FieldNo = Builder.LLVMFields[i].second; | 492 for (unsigned i = 0, e = Builder.LLVMFields.size(); i != e; ++i) 493 RL->FieldInfo.insert(Builder.LLVMFields[i]); |
500 | 494 |
501 RL->FieldInfo.insert(std::make_pair(FD, FieldNo)); 502 } 503 | |
504 // Add bitfield info. | 495 // Add bitfield info. |
505 for (unsigned i = 0, e = Builder.LLVMBitFields.size(); i != e; ++i) { 506 const CGRecordLayoutBuilder::LLVMBitFieldInfo &Info = 507 Builder.LLVMBitFields[i]; | 496 for (unsigned i = 0, e = Builder.LLVMBitFields.size(); i != e; ++i) 497 RL->BitFields.insert(Builder.LLVMBitFields[i]); |
508 | 498 |
509 CGRecordLayout::BitFieldInfo BFI(Info.FieldNo, Info.Start, Info.Size); 510 RL->BitFields.insert(std::make_pair(Info.FD, BFI)); 511 } 512 | |
513 return RL; 514} | 499 return RL; 500} |