CGRecordLayoutBuilder.cpp revision d62328e6a0fa933e3a5daaf68e4964031e6c5c5e
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//===----------------------------------------------------------------------===// 9// 10// Builder implementation for CGRecordLayout objects. 11// 12//===----------------------------------------------------------------------===// 13 14#include "CGRecordLayout.h" 15#include "clang/AST/ASTContext.h" 16#include "clang/AST/Attr.h" 17#include "clang/AST/DeclCXX.h" 18#include "clang/AST/Expr.h" 19#include "clang/AST/RecordLayout.h" 20#include "CodeGenTypes.h" 21#include "llvm/DerivedTypes.h" 22#include "llvm/Type.h" 23#include "llvm/Support/raw_ostream.h" 24#include "llvm/Target/TargetData.h" 25using namespace clang; 26using namespace CodeGen; 27 28namespace clang { 29namespace CodeGen { 30 31class CGRecordLayoutBuilder { 32public: 33 /// FieldTypes - Holds the LLVM types that the struct is created from. 34 std::vector<const llvm::Type *> FieldTypes; 35 36 /// LLVMFieldInfo - Holds a field and its corresponding LLVM field number. 37 typedef std::pair<const FieldDecl *, unsigned> LLVMFieldInfo; 38 llvm::SmallVector<LLVMFieldInfo, 16> LLVMFields; 39 40 /// LLVMBitFieldInfo - Holds location and size information about a bit field. 41 typedef std::pair<const FieldDecl *, CGBitFieldInfo> LLVMBitFieldInfo; 42 llvm::SmallVector<LLVMBitFieldInfo, 16> LLVMBitFields; 43 44 /// ContainsPointerToDataMember - Whether one of the fields in this record 45 /// layout is a pointer to data member, or a struct that contains pointer to 46 /// data member. 47 bool ContainsPointerToDataMember; 48 49 /// Packed - Whether the resulting LLVM struct will be packed or not. 50 bool Packed; 51 52private: 53 CodeGenTypes &Types; 54 55 /// Alignment - Contains the alignment of the RecordDecl. 56 // 57 // FIXME: This is not needed and should be removed. 58 unsigned Alignment; 59 60 /// AlignmentAsLLVMStruct - Will contain the maximum alignment of all the 61 /// LLVM types. 62 unsigned AlignmentAsLLVMStruct; 63 64 /// BitsAvailableInLastField - If a bit field spans only part of a LLVM field, 65 /// this will have the number of bits still available in the field. 66 char BitsAvailableInLastField; 67 68 /// NextFieldOffsetInBytes - Holds the next field offset in bytes. 69 uint64_t NextFieldOffsetInBytes; 70 71 /// LayoutUnionField - Will layout a field in an union and return the type 72 /// that the field will have. 73 const llvm::Type *LayoutUnionField(const FieldDecl *Field, 74 const ASTRecordLayout &Layout); 75 76 /// LayoutUnion - Will layout a union RecordDecl. 77 void LayoutUnion(const RecordDecl *D); 78 79 /// LayoutField - try to layout all fields in the record decl. 80 /// Returns false if the operation failed because the struct is not packed. 81 bool LayoutFields(const RecordDecl *D); 82 83 /// LayoutBases - layout the bases and vtable pointer of a record decl. 84 void LayoutBases(const CXXRecordDecl *RD, const ASTRecordLayout &Layout); 85 86 /// LayoutField - layout a single field. Returns false if the operation failed 87 /// because the current struct is not packed. 88 bool LayoutField(const FieldDecl *D, uint64_t FieldOffset); 89 90 /// LayoutBitField - layout a single bit field. 91 void LayoutBitField(const FieldDecl *D, uint64_t FieldOffset); 92 93 /// AppendField - Appends a field with the given offset and type. 94 void AppendField(uint64_t FieldOffsetInBytes, const llvm::Type *FieldTy); 95 96 /// AppendPadding - Appends enough padding bytes so that the total struct 97 /// size matches the alignment of the passed in type. 98 void AppendPadding(uint64_t FieldOffsetInBytes, const llvm::Type *FieldTy); 99 100 /// AppendPadding - Appends enough padding bytes so that the total 101 /// struct size is a multiple of the field alignment. 102 void AppendPadding(uint64_t FieldOffsetInBytes, unsigned FieldAlignment); 103 104 /// AppendBytes - Append a given number of bytes to the record. 105 void AppendBytes(uint64_t NumBytes); 106 107 /// AppendTailPadding - Append enough tail padding so that the type will have 108 /// the passed size. 109 void AppendTailPadding(uint64_t RecordSize); 110 111 unsigned getTypeAlignment(const llvm::Type *Ty) const; 112 113 /// CheckForPointerToDataMember - Check if the given type contains a pointer 114 /// to data member. 115 void CheckForPointerToDataMember(QualType T); 116 117public: 118 CGRecordLayoutBuilder(CodeGenTypes &Types) 119 : ContainsPointerToDataMember(false), Packed(false), Types(Types), 120 Alignment(0), AlignmentAsLLVMStruct(1), 121 BitsAvailableInLastField(0), NextFieldOffsetInBytes(0) { } 122 123 /// Layout - Will layout a RecordDecl. 124 void Layout(const RecordDecl *D); 125}; 126 127} 128} 129 130void CGRecordLayoutBuilder::Layout(const RecordDecl *D) { 131 Alignment = Types.getContext().getASTRecordLayout(D).getAlignment() / 8; 132 Packed = D->hasAttr<PackedAttr>(); 133 134 if (D->isUnion()) { 135 LayoutUnion(D); 136 return; 137 } 138 139 if (LayoutFields(D)) 140 return; 141 142 // We weren't able to layout the struct. Try again with a packed struct 143 Packed = true; 144 AlignmentAsLLVMStruct = 1; 145 NextFieldOffsetInBytes = 0; 146 FieldTypes.clear(); 147 LLVMFields.clear(); 148 LLVMBitFields.clear(); 149 150 LayoutFields(D); 151} 152 153static CGBitFieldInfo ComputeBitFieldInfo(CodeGenTypes &Types, 154 const FieldDecl *FD, 155 uint64_t FieldOffset, 156 uint64_t FieldSize) { 157 const llvm::Type *Ty = Types.ConvertTypeForMemRecursive(FD->getType()); 158 uint64_t TypeSizeInBytes = Types.getTargetData().getTypeAllocSize(Ty); 159 uint64_t TypeSizeInBits = TypeSizeInBytes * 8; 160 161 bool IsSigned = FD->getType()->isSignedIntegerType(); 162 163 if (FieldSize > TypeSizeInBits) { 164 // We have a wide bit-field. 165 166 CGBitFieldInfo::AccessInfo Component; 167 168 Component.FieldIndex = 0; 169 Component.FieldByteOffset = 170 TypeSizeInBytes * ((FieldOffset / 8) / TypeSizeInBytes); 171 Component.FieldBitStart = 0; 172 Component.AccessWidth = TypeSizeInBits; 173 // FIXME: This might be wrong! 174 Component.AccessAlignment = 0; 175 Component.TargetBitOffset = 0; 176 Component.TargetBitWidth = TypeSizeInBits; 177 178 return CGBitFieldInfo(TypeSizeInBits, 1, &Component, IsSigned); 179 } 180 181 unsigned StartBit = FieldOffset % TypeSizeInBits; 182 183 // The current policy is to always access the bit-field using the source type 184 // of the bit-field. With the C bit-field rules, this implies that we always 185 // use either one or two accesses, and two accesses can only occur with a 186 // packed structure when the bit-field straddles an alignment boundary. 187 CGBitFieldInfo::AccessInfo Components[2]; 188 189 unsigned LowBits = std::min(FieldSize, TypeSizeInBits - StartBit); 190 bool NeedsHighAccess = LowBits != FieldSize; 191 unsigned NumComponents = 1 + NeedsHighAccess; 192 193 // FIXME: This access policy is probably wrong on big-endian systems. 194 CGBitFieldInfo::AccessInfo &LowAccess = Components[0]; 195 LowAccess.FieldIndex = 0; 196 LowAccess.FieldByteOffset = 197 TypeSizeInBytes * ((FieldOffset / 8) / TypeSizeInBytes); 198 LowAccess.FieldBitStart = StartBit; 199 LowAccess.AccessWidth = TypeSizeInBits; 200 // FIXME: This might be wrong! 201 LowAccess.AccessAlignment = 0; 202 LowAccess.TargetBitOffset = 0; 203 LowAccess.TargetBitWidth = LowBits; 204 205 if (NeedsHighAccess) { 206 CGBitFieldInfo::AccessInfo &HighAccess = Components[1]; 207 HighAccess.FieldIndex = 0; 208 HighAccess.FieldByteOffset = LowAccess.FieldByteOffset + TypeSizeInBytes; 209 HighAccess.FieldBitStart = 0; 210 HighAccess.AccessWidth = TypeSizeInBits; 211 // FIXME: This might be wrong! 212 HighAccess.AccessAlignment = 0; 213 HighAccess.TargetBitOffset = LowBits; 214 HighAccess.TargetBitWidth = FieldSize - LowBits; 215 } 216 217 return CGBitFieldInfo(FieldSize, NumComponents, Components, IsSigned); 218} 219 220void CGRecordLayoutBuilder::LayoutBitField(const FieldDecl *D, 221 uint64_t FieldOffset) { 222 uint64_t FieldSize = 223 D->getBitWidth()->EvaluateAsInt(Types.getContext()).getZExtValue(); 224 225 if (FieldSize == 0) 226 return; 227 228 uint64_t NextFieldOffset = NextFieldOffsetInBytes * 8; 229 unsigned NumBytesToAppend; 230 231 if (FieldOffset < NextFieldOffset) { 232 assert(BitsAvailableInLastField && "Bitfield size mismatch!"); 233 assert(NextFieldOffsetInBytes && "Must have laid out at least one byte!"); 234 235 // The bitfield begins in the previous bit-field. 236 NumBytesToAppend = 237 llvm::RoundUpToAlignment(FieldSize - BitsAvailableInLastField, 8) / 8; 238 } else { 239 assert(FieldOffset % 8 == 0 && "Field offset not aligned correctly"); 240 241 // Append padding if necessary. 242 AppendBytes((FieldOffset - NextFieldOffset) / 8); 243 244 NumBytesToAppend = 245 llvm::RoundUpToAlignment(FieldSize, 8) / 8; 246 247 assert(NumBytesToAppend && "No bytes to append!"); 248 } 249 250 // Add the bit field info. 251 LLVMBitFields.push_back( 252 LLVMBitFieldInfo(D, ComputeBitFieldInfo(Types, D, FieldOffset, FieldSize))); 253 254 AppendBytes(NumBytesToAppend); 255 256 BitsAvailableInLastField = 257 NextFieldOffsetInBytes * 8 - (FieldOffset + FieldSize); 258} 259 260bool CGRecordLayoutBuilder::LayoutField(const FieldDecl *D, 261 uint64_t FieldOffset) { 262 // If the field is packed, then we need a packed struct. 263 if (!Packed && D->hasAttr<PackedAttr>()) 264 return false; 265 266 if (D->isBitField()) { 267 // We must use packed structs for unnamed bit fields since they 268 // don't affect the struct alignment. 269 if (!Packed && !D->getDeclName()) 270 return false; 271 272 LayoutBitField(D, FieldOffset); 273 return true; 274 } 275 276 // Check if we have a pointer to data member in this field. 277 CheckForPointerToDataMember(D->getType()); 278 279 assert(FieldOffset % 8 == 0 && "FieldOffset is not on a byte boundary!"); 280 uint64_t FieldOffsetInBytes = FieldOffset / 8; 281 282 const llvm::Type *Ty = Types.ConvertTypeForMemRecursive(D->getType()); 283 unsigned TypeAlignment = getTypeAlignment(Ty); 284 285 // If the type alignment is larger then the struct alignment, we must use 286 // a packed struct. 287 if (TypeAlignment > Alignment) { 288 assert(!Packed && "Alignment is wrong even with packed struct!"); 289 return false; 290 } 291 292 if (const RecordType *RT = D->getType()->getAs<RecordType>()) { 293 const RecordDecl *RD = cast<RecordDecl>(RT->getDecl()); 294 if (const PragmaPackAttr *PPA = RD->getAttr<PragmaPackAttr>()) { 295 if (PPA->getAlignment() != TypeAlignment * 8 && !Packed) 296 return false; 297 } 298 } 299 300 // Round up the field offset to the alignment of the field type. 301 uint64_t AlignedNextFieldOffsetInBytes = 302 llvm::RoundUpToAlignment(NextFieldOffsetInBytes, TypeAlignment); 303 304 if (FieldOffsetInBytes < AlignedNextFieldOffsetInBytes) { 305 assert(!Packed && "Could not place field even with packed struct!"); 306 return false; 307 } 308 309 if (AlignedNextFieldOffsetInBytes < FieldOffsetInBytes) { 310 // Even with alignment, the field offset is not at the right place, 311 // insert padding. 312 uint64_t PaddingInBytes = FieldOffsetInBytes - NextFieldOffsetInBytes; 313 314 AppendBytes(PaddingInBytes); 315 } 316 317 // Now append the field. 318 LLVMFields.push_back(LLVMFieldInfo(D, FieldTypes.size())); 319 AppendField(FieldOffsetInBytes, Ty); 320 321 return true; 322} 323 324const llvm::Type * 325CGRecordLayoutBuilder::LayoutUnionField(const FieldDecl *Field, 326 const ASTRecordLayout &Layout) { 327 if (Field->isBitField()) { 328 uint64_t FieldSize = 329 Field->getBitWidth()->EvaluateAsInt(Types.getContext()).getZExtValue(); 330 331 // Ignore zero sized bit fields. 332 if (FieldSize == 0) 333 return 0; 334 335 const llvm::Type *FieldTy; 336 337 if (!Field->getDeclName()) { 338 // This is an unnamed bit-field, which shouldn't affect alignment on the 339 // struct so we use an array of bytes for it. 340 341 FieldTy = llvm::Type::getInt8Ty(Types.getLLVMContext()); 342 343 unsigned NumBytesToAppend = 344 llvm::RoundUpToAlignment(FieldSize, 8) / 8; 345 346 if (NumBytesToAppend > 1) 347 FieldTy = llvm::ArrayType::get(FieldTy, NumBytesToAppend); 348 } else 349 FieldTy = Types.ConvertTypeForMemRecursive(Field->getType()); 350 351 // Add the bit field info. 352 LLVMBitFields.push_back( 353 LLVMBitFieldInfo(Field, ComputeBitFieldInfo(Types, Field, 0, FieldSize))); 354 return FieldTy; 355 } 356 357 // This is a regular union field. 358 LLVMFields.push_back(LLVMFieldInfo(Field, 0)); 359 return Types.ConvertTypeForMemRecursive(Field->getType()); 360} 361 362void CGRecordLayoutBuilder::LayoutUnion(const RecordDecl *D) { 363 assert(D->isUnion() && "Can't call LayoutUnion on a non-union record!"); 364 365 const ASTRecordLayout &Layout = Types.getContext().getASTRecordLayout(D); 366 367 const llvm::Type *Ty = 0; 368 uint64_t Size = 0; 369 unsigned Align = 0; 370 371 bool HasOnlyZeroSizedBitFields = true; 372 373 unsigned FieldNo = 0; 374 for (RecordDecl::field_iterator Field = D->field_begin(), 375 FieldEnd = D->field_end(); Field != FieldEnd; ++Field, ++FieldNo) { 376 assert(Layout.getFieldOffset(FieldNo) == 0 && 377 "Union field offset did not start at the beginning of record!"); 378 const llvm::Type *FieldTy = LayoutUnionField(*Field, Layout); 379 380 if (!FieldTy) 381 continue; 382 383 HasOnlyZeroSizedBitFields = false; 384 385 unsigned FieldAlign = Types.getTargetData().getABITypeAlignment(FieldTy); 386 uint64_t FieldSize = Types.getTargetData().getTypeAllocSize(FieldTy); 387 388 if (FieldAlign < Align) 389 continue; 390 391 if (FieldAlign > Align || FieldSize > Size) { 392 Ty = FieldTy; 393 Align = FieldAlign; 394 Size = FieldSize; 395 } 396 } 397 398 // Now add our field. 399 if (Ty) { 400 AppendField(0, Ty); 401 402 if (getTypeAlignment(Ty) > Layout.getAlignment() / 8) { 403 // We need a packed struct. 404 Packed = true; 405 Align = 1; 406 } 407 } 408 if (!Align) { 409 assert(HasOnlyZeroSizedBitFields && 410 "0-align record did not have all zero-sized bit-fields!"); 411 Align = 1; 412 } 413 414 // Append tail padding. 415 if (Layout.getSize() / 8 > Size) 416 AppendPadding(Layout.getSize() / 8, Align); 417} 418 419void CGRecordLayoutBuilder::LayoutBases(const CXXRecordDecl *RD, 420 const ASTRecordLayout &Layout) { 421 // Check if we need to add a vtable pointer. 422 if (RD->isDynamicClass() && !Layout.getPrimaryBase()) { 423 const llvm::Type *Int8PtrTy = 424 llvm::Type::getInt8PtrTy(Types.getLLVMContext()); 425 426 assert(NextFieldOffsetInBytes == 0 && 427 "VTable pointer must come first!"); 428 AppendField(NextFieldOffsetInBytes, Int8PtrTy->getPointerTo()); 429 } 430} 431 432bool CGRecordLayoutBuilder::LayoutFields(const RecordDecl *D) { 433 assert(!D->isUnion() && "Can't call LayoutFields on a union!"); 434 assert(Alignment && "Did not set alignment!"); 435 436 const ASTRecordLayout &Layout = Types.getContext().getASTRecordLayout(D); 437 438 if (const CXXRecordDecl *RD = dyn_cast<CXXRecordDecl>(D)) 439 LayoutBases(RD, Layout); 440 441 unsigned FieldNo = 0; 442 443 for (RecordDecl::field_iterator Field = D->field_begin(), 444 FieldEnd = D->field_end(); Field != FieldEnd; ++Field, ++FieldNo) { 445 if (!LayoutField(*Field, Layout.getFieldOffset(FieldNo))) { 446 assert(!Packed && 447 "Could not layout fields even with a packed LLVM struct!"); 448 return false; 449 } 450 } 451 452 // Append tail padding if necessary. 453 AppendTailPadding(Layout.getSize()); 454 455 return true; 456} 457 458void CGRecordLayoutBuilder::AppendTailPadding(uint64_t RecordSize) { 459 assert(RecordSize % 8 == 0 && "Invalid record size!"); 460 461 uint64_t RecordSizeInBytes = RecordSize / 8; 462 assert(NextFieldOffsetInBytes <= RecordSizeInBytes && "Size mismatch!"); 463 464 uint64_t AlignedNextFieldOffset = 465 llvm::RoundUpToAlignment(NextFieldOffsetInBytes, AlignmentAsLLVMStruct); 466 467 if (AlignedNextFieldOffset == RecordSizeInBytes) { 468 // We don't need any padding. 469 return; 470 } 471 472 unsigned NumPadBytes = RecordSizeInBytes - NextFieldOffsetInBytes; 473 AppendBytes(NumPadBytes); 474} 475 476void CGRecordLayoutBuilder::AppendField(uint64_t FieldOffsetInBytes, 477 const llvm::Type *FieldTy) { 478 AlignmentAsLLVMStruct = std::max(AlignmentAsLLVMStruct, 479 getTypeAlignment(FieldTy)); 480 481 uint64_t FieldSizeInBytes = Types.getTargetData().getTypeAllocSize(FieldTy); 482 483 FieldTypes.push_back(FieldTy); 484 485 NextFieldOffsetInBytes = FieldOffsetInBytes + FieldSizeInBytes; 486 BitsAvailableInLastField = 0; 487} 488 489void 490CGRecordLayoutBuilder::AppendPadding(uint64_t FieldOffsetInBytes, 491 const llvm::Type *FieldTy) { 492 AppendPadding(FieldOffsetInBytes, getTypeAlignment(FieldTy)); 493} 494 495void CGRecordLayoutBuilder::AppendPadding(uint64_t FieldOffsetInBytes, 496 unsigned FieldAlignment) { 497 assert(NextFieldOffsetInBytes <= FieldOffsetInBytes && 498 "Incorrect field layout!"); 499 500 // Round up the field offset to the alignment of the field type. 501 uint64_t AlignedNextFieldOffsetInBytes = 502 llvm::RoundUpToAlignment(NextFieldOffsetInBytes, FieldAlignment); 503 504 if (AlignedNextFieldOffsetInBytes < FieldOffsetInBytes) { 505 // Even with alignment, the field offset is not at the right place, 506 // insert padding. 507 uint64_t PaddingInBytes = FieldOffsetInBytes - NextFieldOffsetInBytes; 508 509 AppendBytes(PaddingInBytes); 510 } 511} 512 513void CGRecordLayoutBuilder::AppendBytes(uint64_t NumBytes) { 514 if (NumBytes == 0) 515 return; 516 517 const llvm::Type *Ty = llvm::Type::getInt8Ty(Types.getLLVMContext()); 518 if (NumBytes > 1) 519 Ty = llvm::ArrayType::get(Ty, NumBytes); 520 521 // Append the padding field 522 AppendField(NextFieldOffsetInBytes, Ty); 523} 524 525unsigned CGRecordLayoutBuilder::getTypeAlignment(const llvm::Type *Ty) const { 526 if (Packed) 527 return 1; 528 529 return Types.getTargetData().getABITypeAlignment(Ty); 530} 531 532void CGRecordLayoutBuilder::CheckForPointerToDataMember(QualType T) { 533 // This record already contains a member pointer. 534 if (ContainsPointerToDataMember) 535 return; 536 537 // Can only have member pointers if we're compiling C++. 538 if (!Types.getContext().getLangOptions().CPlusPlus) 539 return; 540 541 T = Types.getContext().getBaseElementType(T); 542 543 if (const MemberPointerType *MPT = T->getAs<MemberPointerType>()) { 544 if (!MPT->getPointeeType()->isFunctionType()) { 545 // We have a pointer to data member. 546 ContainsPointerToDataMember = true; 547 } 548 } else if (const RecordType *RT = T->getAs<RecordType>()) { 549 const CXXRecordDecl *RD = cast<CXXRecordDecl>(RT->getDecl()); 550 551 // FIXME: It would be better if there was a way to explicitly compute the 552 // record layout instead of converting to a type. 553 Types.ConvertTagDeclType(RD); 554 555 const CGRecordLayout &Layout = Types.getCGRecordLayout(RD); 556 557 if (Layout.containsPointerToDataMember()) 558 ContainsPointerToDataMember = true; 559 } 560} 561 562CGRecordLayout *CodeGenTypes::ComputeRecordLayout(const RecordDecl *D) { 563 CGRecordLayoutBuilder Builder(*this); 564 565 Builder.Layout(D); 566 567 const llvm::Type *Ty = llvm::StructType::get(getLLVMContext(), 568 Builder.FieldTypes, 569 Builder.Packed); 570 assert(getContext().getASTRecordLayout(D).getSize() / 8 == 571 getTargetData().getTypeAllocSize(Ty) && 572 "Type size mismatch!"); 573 574 CGRecordLayout *RL = 575 new CGRecordLayout(Ty, Builder.ContainsPointerToDataMember); 576 577 // Add all the field numbers. 578 for (unsigned i = 0, e = Builder.LLVMFields.size(); i != e; ++i) 579 RL->FieldInfo.insert(Builder.LLVMFields[i]); 580 581 // Add bitfield info. 582 for (unsigned i = 0, e = Builder.LLVMBitFields.size(); i != e; ++i) 583 RL->BitFields.insert(Builder.LLVMBitFields[i]); 584 585 if (getContext().getLangOptions().DumpRecordLayouts) { 586 llvm::errs() << "\n*** Dumping Record Layout\n"; 587 llvm::errs() << "Record: "; 588 D->dump(); 589 llvm::errs() << "\nLayout: "; 590 RL->dump(); 591 } 592 593 return RL; 594} 595 596void CGRecordLayout::print(llvm::raw_ostream &OS) const { 597 OS << "<CGRecordLayout\n"; 598 OS << " LLVMType:" << *LLVMType << "\n"; 599 OS << " ContainsPointerToDataMember:" << ContainsPointerToDataMember << "\n"; 600 OS << " BitFields:[\n"; 601 for (llvm::DenseMap<const FieldDecl*, CGBitFieldInfo>::const_iterator 602 it = BitFields.begin(), ie = BitFields.end(); 603 it != ie; ++it) { 604 OS.indent(4); 605 it->second.print(OS); 606 OS << "\n"; 607 } 608 OS << "]>\n"; 609} 610 611void CGRecordLayout::dump() const { 612 print(llvm::errs()); 613} 614 615void CGBitFieldInfo::print(llvm::raw_ostream &OS) const { 616 OS << "<CGBitFieldInfo"; 617 OS << " Size:" << Size; 618 OS << " IsSigned:" << IsSigned << "\n"; 619 620 OS.indent(4 + strlen("<CGBitFieldInfo")); 621 OS << " NumComponents:" << getNumComponents(); 622 OS << " Components: ["; 623 if (getNumComponents()) { 624 OS << "\n"; 625 for (unsigned i = 0, e = getNumComponents(); i != e; ++i) { 626 const AccessInfo &AI = getComponent(i); 627 OS.indent(8); 628 OS << "<AccessInfo" 629 << " FieldIndex:" << AI.FieldIndex 630 << " FieldByteOffset:" << AI.FieldByteOffset 631 << " FieldBitStart:" << AI.FieldBitStart 632 << " AccessWidth:" << AI.AccessWidth << "\n"; 633 OS.indent(8 + strlen("<AccessInfo")); 634 OS << " AccessAlignment:" << AI.AccessAlignment 635 << " TargetBitOffset:" << AI.TargetBitOffset 636 << " TargetBitWidth:" << AI.TargetBitWidth 637 << ">\n"; 638 } 639 OS.indent(4); 640 } 641 OS << "]>"; 642} 643 644void CGBitFieldInfo::dump() const { 645 print(llvm::errs()); 646} 647