llvm.org GIT mirror llvm / 7c02071
DebugInfo: Remove unnecessary API from DIDerivedType and DIType Remove the accessors of `DIDerivedType` that downcast to `MDDerivedType`, shifting the `cast<MDDerivedType>` into the callers. Also remove `DIType::isValid()`, which is really just a check against `nullptr` at this point. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@235059 91177308-0d34-0410-b5e6-96231b3b80d8 Duncan P. N. Exon Smith 4 years ago
3 changed file(s) with 37 addition(s) and 47 deletion(s). Raw diff Collapse all Expand all
816816 static DIBuilder *DBuilder;
817817
818818 DIType DebugInfo::getDoubleTy() {
819 if (DblTy.isValid())
819 if (DblTy)
820820 return DblTy;
821821
822822 DblTy = DBuilder->createBasicType("double", 64, 64, dwarf::DW_ATE_float);
274274 bool isStaticMember() const { return get()->isStaticMember(); }
275275 bool isLValueReference() const { return get()->isLValueReference(); }
276276 bool isRValueReference() const { return get()->isRValueReference(); }
277
278 bool isValid() const { return DbgNode && isa(*this); }
279277 };
280278
281279 /// \brief A basic type, like 'int' or 'float'.
311309 MDDerivedTypeBase &operator*() const { return *get(); }
312310
313311 DITypeRef getTypeDerivedFrom() const { return get()->getBaseType(); }
314
315 /// \brief Return property node, if this ivar is associated with one.
316 MDObjCProperty *getObjCProperty() const {
317 return cast(get())->getObjCProperty();
318 }
319
320 DITypeRef getClassType() const {
321 return cast(get())->getClassType();
322 }
323
324 Constant *getConstant() const {
325 return cast(get())->getConstant();
326 }
327312 };
328313
329314 /// \brief Types that refer to multiple other types.
654654
655655 DIType BaseType = DD->resolve(Ty.getTypeDerivedFrom());
656656
657 assert(BaseType.isValid() && "Unexpected invalid base type");
657 assert(BaseType && "Unexpected invalid base type");
658658
659659 // If this is a derived type, go ahead and get the base type, unless it's a
660660 // reference then it's just the size of the field. Pointer types have no need
970970 addUInt(Buffer, dwarf::DW_AT_byte_size, None, Size);
971971
972972 if (Tag == dwarf::DW_TAG_ptr_to_member_type)
973 addDIEEntry(Buffer, dwarf::DW_AT_containing_type,
974 *getOrCreateTypeDIE(resolve(DTy.getClassType())));
973 addDIEEntry(
974 Buffer, dwarf::DW_AT_containing_type,
975 *getOrCreateTypeDIE(resolve(cast(DTy)->getClassType())));
975976 // Add source line info if available and TyDesc is not a forward declaration.
976977 if (!DTy.isForwardDecl())
977978 addSourceLine(Buffer, DTy);
14531454 }
14541455
14551456 /// constructMemberDIE - Construct member DIE from DIDerivedType.
1456 void DwarfUnit::constructMemberDIE(DIE &Buffer, DIDerivedType DT) {
1457 DIE &MemberDie = createAndAddDIE(DT.getTag(), Buffer);
1458 StringRef Name = DT.getName();
1457 void DwarfUnit::constructMemberDIE(DIE &Buffer, DIDerivedType DT_) {
1458 // Downcast to MDDerivedType.
1459 const MDDerivedType *DT = cast(DT_);
1460
1461 DIE &MemberDie = createAndAddDIE(DT->getTag(), Buffer);
1462 StringRef Name = DT->getName();
14591463 if (!Name.empty())
14601464 addString(MemberDie, dwarf::DW_AT_name, Name);
14611465
1462 addType(MemberDie, resolve(DT.getTypeDerivedFrom()));
1466 addType(MemberDie, resolve(DT->getBaseType()));
14631467
14641468 addSourceLine(MemberDie, DT);
14651469
1466 if (DT.getTag() == dwarf::DW_TAG_inheritance && DT.isVirtual()) {
1470 if (DT->getTag() == dwarf::DW_TAG_inheritance && DT->isVirtual()) {
14671471
14681472 // For C++, virtual base classes are not at fixed offset. Use following
14691473 // expression to extract appropriate offset from vtable.
14731477 addUInt(*VBaseLocationDie, dwarf::DW_FORM_data1, dwarf::DW_OP_dup);
14741478 addUInt(*VBaseLocationDie, dwarf::DW_FORM_data1, dwarf::DW_OP_deref);
14751479 addUInt(*VBaseLocationDie, dwarf::DW_FORM_data1, dwarf::DW_OP_constu);
1476 addUInt(*VBaseLocationDie, dwarf::DW_FORM_udata, DT.getOffsetInBits());
1480 addUInt(*VBaseLocationDie, dwarf::DW_FORM_udata, DT->getOffsetInBits());
14771481 addUInt(*VBaseLocationDie, dwarf::DW_FORM_data1, dwarf::DW_OP_minus);
14781482 addUInt(*VBaseLocationDie, dwarf::DW_FORM_data1, dwarf::DW_OP_deref);
14791483 addUInt(*VBaseLocationDie, dwarf::DW_FORM_data1, dwarf::DW_OP_plus);
14801484
14811485 addBlock(MemberDie, dwarf::DW_AT_data_member_location, VBaseLocationDie);
14821486 } else {
1483 uint64_t Size = DT.getSizeInBits();
1487 uint64_t Size = DT->getSizeInBits();
14841488 uint64_t FieldSize = getBaseTypeSize(DD, DT);
14851489 uint64_t OffsetInBytes;
14861490
14891493 addUInt(MemberDie, dwarf::DW_AT_byte_size, None, FieldSize/8);
14901494 addUInt(MemberDie, dwarf::DW_AT_bit_size, None, Size);
14911495
1492 uint64_t Offset = DT.getOffsetInBits();
1493 uint64_t AlignMask = ~(DT.getAlignInBits() - 1);
1496 uint64_t Offset = DT->getOffsetInBits();
1497 uint64_t AlignMask = ~(DT->getAlignInBits() - 1);
14941498 uint64_t HiMark = (Offset + FieldSize) & AlignMask;
14951499 uint64_t FieldOffset = (HiMark - FieldSize);
14961500 Offset -= FieldOffset;
15051509 OffsetInBytes = FieldOffset >> 3;
15061510 } else
15071511 // This is not a bitfield.
1508 OffsetInBytes = DT.getOffsetInBits() >> 3;
1512 OffsetInBytes = DT->getOffsetInBits() >> 3;
15091513
15101514 if (DD->getDwarfVersion() <= 2) {
15111515 DIELoc *MemLocationDie = new (DIEValueAllocator) DIELoc();
15171521 OffsetInBytes);
15181522 }
15191523
1520 if (DT.isProtected())
1524 if (DT->isProtected())
15211525 addUInt(MemberDie, dwarf::DW_AT_accessibility, dwarf::DW_FORM_data1,
15221526 dwarf::DW_ACCESS_protected);
1523 else if (DT.isPrivate())
1527 else if (DT->isPrivate())
15241528 addUInt(MemberDie, dwarf::DW_AT_accessibility, dwarf::DW_FORM_data1,
15251529 dwarf::DW_ACCESS_private);
15261530 // Otherwise C++ member and base classes are considered public.
1527 else if (DT.isPublic())
1531 else if (DT->isPublic())
15281532 addUInt(MemberDie, dwarf::DW_AT_accessibility, dwarf::DW_FORM_data1,
15291533 dwarf::DW_ACCESS_public);
1530 if (DT.isVirtual())
1534 if (DT->isVirtual())
15311535 addUInt(MemberDie, dwarf::DW_AT_virtuality, dwarf::DW_FORM_data1,
15321536 dwarf::DW_VIRTUALITY_virtual);
15331537
15341538 // Objective-C properties.
1535 if (MDNode *PNode = DT.getObjCProperty())
1539 if (MDNode *PNode = DT->getObjCProperty())
15361540 if (DIEEntry *PropertyDie = getDIEEntry(PNode))
15371541 MemberDie.addValue(dwarf::DW_AT_APPLE_property, dwarf::DW_FORM_ref4,
15381542 PropertyDie);
15391543
1540 if (DT.isArtificial())
1544 if (DT->isArtificial())
15411545 addFlag(MemberDie, dwarf::DW_AT_artificial);
15421546 }
15431547
15441548 /// getOrCreateStaticMemberDIE - Create new DIE for C++ static member.
1545 DIE *DwarfUnit::getOrCreateStaticMemberDIE(DIDerivedType DT) {
1549 DIE *DwarfUnit::getOrCreateStaticMemberDIE(DIDerivedType DT_) {
1550 const MDDerivedType *DT = cast_or_null(DT_);
15461551 if (!DT)
15471552 return nullptr;
15481553
15491554 // Construct the context before querying for the existence of the DIE in case
15501555 // such construction creates the DIE.
1551 DIE *ContextDIE = getOrCreateContextDIE(resolve(DT.getContext()));
1556 DIE *ContextDIE = getOrCreateContextDIE(resolve(DT->getScope()));
15521557 assert(dwarf::isType(ContextDIE->getTag()) &&
15531558 "Static member should belong to a type.");
15541559
15551560 if (DIE *StaticMemberDIE = getDIE(DT))
15561561 return StaticMemberDIE;
15571562
1558 DIE &StaticMemberDIE = createAndAddDIE(DT.getTag(), *ContextDIE, DT);
1559
1560 DIType Ty = resolve(DT.getTypeDerivedFrom());
1561
1562 addString(StaticMemberDIE, dwarf::DW_AT_name, DT.getName());
1563 DIE &StaticMemberDIE = createAndAddDIE(DT->getTag(), *ContextDIE, DT);
1564
1565 DIType Ty = resolve(DT->getBaseType());
1566
1567 addString(StaticMemberDIE, dwarf::DW_AT_name, DT->getName());
15631568 addType(StaticMemberDIE, Ty);
15641569 addSourceLine(StaticMemberDIE, DT);
15651570 addFlag(StaticMemberDIE, dwarf::DW_AT_external);
15671572
15681573 // FIXME: We could omit private if the parent is a class_type, and
15691574 // public if the parent is something else.
1570 if (DT.isProtected())
1575 if (DT->isProtected())
15711576 addUInt(StaticMemberDIE, dwarf::DW_AT_accessibility, dwarf::DW_FORM_data1,
15721577 dwarf::DW_ACCESS_protected);
1573 else if (DT.isPrivate())
1578 else if (DT->isPrivate())
15741579 addUInt(StaticMemberDIE, dwarf::DW_AT_accessibility, dwarf::DW_FORM_data1,
15751580 dwarf::DW_ACCESS_private);
1576 else if (DT.isPublic())
1581 else if (DT->isPublic())
15771582 addUInt(StaticMemberDIE, dwarf::DW_AT_accessibility, dwarf::DW_FORM_data1,
15781583 dwarf::DW_ACCESS_public);
15791584
1580 if (const ConstantInt *CI = dyn_cast_or_null(DT.getConstant()))
1585 if (const ConstantInt *CI = dyn_cast_or_null(DT->getConstant()))
15811586 addConstantValue(StaticMemberDIE, CI, Ty);
1582 if (const ConstantFP *CFP = dyn_cast_or_null(DT.getConstant()))
1587 if (const ConstantFP *CFP = dyn_cast_or_null(DT->getConstant()))
15831588 addConstantFPValue(StaticMemberDIE, CFP);
15841589
15851590 return &StaticMemberDIE;