Skip to content

Commit

Permalink
DebugInfo: Delete old subclasses of DIType
Browse files Browse the repository at this point in the history
Delete subclasses of (the already deleted) `DIType` in favour of
directly using pointers from the `Metadata` hierarchy.

While `DICompositeType` wraps `MDCompositeTypeBase` and `DIDerivedType`
wraps `MDDerivedTypeBase`, most uses of each really meant the more
specific `MDCompositeType` and `MDDerivedType`.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@235351 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
dexonsmith committed Apr 20, 2015
1 parent 80608c5 commit 92b3bf9
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 114 deletions.
42 changes: 17 additions & 25 deletions bindings/go/llvm/DIBuilderBindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,7 @@ LLVMMetadataRef LLVMDIBuilderCreateBasicType(LLVMDIBuilderRef Dref,
uint64_t AlignInBits,
unsigned Encoding) {
DIBuilder *D = unwrap(Dref);
DIBasicType T = D->createBasicType(Name, SizeInBits, AlignInBits, Encoding);
return wrap(T);
return wrap(D->createBasicType(Name, SizeInBits, AlignInBits, Encoding));
}

LLVMMetadataRef LLVMDIBuilderCreatePointerType(LLVMDIBuilderRef Dref,
Expand All @@ -114,19 +113,17 @@ LLVMMetadataRef LLVMDIBuilderCreatePointerType(LLVMDIBuilderRef Dref,
uint64_t AlignInBits,
const char *Name) {
DIBuilder *D = unwrap(Dref);
DIDerivedType T = D->createPointerType(unwrap<MDType>(PointeeType),
SizeInBits, AlignInBits, Name);
return wrap(T);
return wrap(D->createPointerType(unwrap<MDType>(PointeeType), SizeInBits,
AlignInBits, Name));
}

LLVMMetadataRef
LLVMDIBuilderCreateSubroutineType(LLVMDIBuilderRef Dref, LLVMMetadataRef File,
LLVMMetadataRef ParameterTypes) {
DIBuilder *D = unwrap(Dref);
DICompositeType CT =
return wrap(
D->createSubroutineType(File ? unwrap<MDFile>(File) : nullptr,
DITypeArray(unwrap<MDTuple>(ParameterTypes)));
return wrap(CT);
DITypeArray(unwrap<MDTuple>(ParameterTypes))));
}

LLVMMetadataRef LLVMDIBuilderCreateStructType(
Expand All @@ -135,12 +132,11 @@ LLVMMetadataRef LLVMDIBuilderCreateStructType(
uint64_t AlignInBits, unsigned Flags, LLVMMetadataRef DerivedFrom,
LLVMMetadataRef ElementTypes) {
DIBuilder *D = unwrap(Dref);
DICompositeType CT = D->createStructType(
return wrap(D->createStructType(
unwrap<MDScope>(Scope), Name, File ? unwrap<MDFile>(File) : nullptr, Line,
SizeInBits, AlignInBits, Flags,
DerivedFrom ? unwrap<MDType>(DerivedFrom) : nullptr,
ElementTypes ? DIArray(unwrap<MDTuple>(ElementTypes)) : nullptr);
return wrap(CT);
ElementTypes ? DIArray(unwrap<MDTuple>(ElementTypes)) : nullptr));
}

LLVMMetadataRef LLVMDIBuilderCreateReplaceableCompositeType(
Expand All @@ -149,10 +145,9 @@ LLVMMetadataRef LLVMDIBuilderCreateReplaceableCompositeType(
unsigned RuntimeLang, uint64_t SizeInBits, uint64_t AlignInBits,
unsigned Flags) {
DIBuilder *D = unwrap(Dref);
DICompositeType CT = D->createReplaceableCompositeType(
return wrap(D->createReplaceableCompositeType(
Tag, Name, unwrap<MDScope>(Scope), File ? unwrap<MDFile>(File) : nullptr,
Line, RuntimeLang, SizeInBits, AlignInBits, Flags);
return wrap(CT);
Line, RuntimeLang, SizeInBits, AlignInBits, Flags));
}

LLVMMetadataRef
Expand All @@ -162,10 +157,9 @@ LLVMDIBuilderCreateMemberType(LLVMDIBuilderRef Dref, LLVMMetadataRef Scope,
uint64_t AlignInBits, uint64_t OffsetInBits,
unsigned Flags, LLVMMetadataRef Ty) {
DIBuilder *D = unwrap(Dref);
DIDerivedType DT = D->createMemberType(
return wrap(D->createMemberType(
unwrap<MDScope>(Scope), Name, File ? unwrap<MDFile>(File) : nullptr, Line,
SizeInBits, AlignInBits, OffsetInBits, Flags, unwrap<MDType>(Ty));
return wrap(DT);
SizeInBits, AlignInBits, OffsetInBits, Flags, unwrap<MDType>(Ty)));
}

LLVMMetadataRef LLVMDIBuilderCreateArrayType(LLVMDIBuilderRef Dref,
Expand All @@ -174,21 +168,19 @@ LLVMMetadataRef LLVMDIBuilderCreateArrayType(LLVMDIBuilderRef Dref,
LLVMMetadataRef ElementType,
LLVMMetadataRef Subscripts) {
DIBuilder *D = unwrap(Dref);
DICompositeType CT =
D->createArrayType(SizeInBits, AlignInBits, unwrap<MDType>(ElementType),
DIArray(unwrap<MDTuple>(Subscripts)));
return wrap(CT);
return wrap(D->createArrayType(SizeInBits, AlignInBits,
unwrap<MDType>(ElementType),
DIArray(unwrap<MDTuple>(Subscripts))));
}

LLVMMetadataRef LLVMDIBuilderCreateTypedef(LLVMDIBuilderRef Dref,
LLVMMetadataRef Ty, const char *Name,
LLVMMetadataRef File, unsigned Line,
LLVMMetadataRef Context) {
DIBuilder *D = unwrap(Dref);
DIDerivedType DT = D->createTypedef(
unwrap<MDType>(Ty), Name, File ? unwrap<MDFile>(File) : nullptr, Line,
Context ? unwrap<MDScope>(Context) : nullptr);
return wrap(DT);
return wrap(D->createTypedef(unwrap<MDType>(Ty), Name,
File ? unwrap<MDFile>(File) : nullptr, Line,
Context ? unwrap<MDScope>(Context) : nullptr));
}

LLVMMetadataRef LLVMDIBuilderGetOrCreateSubrange(LLVMDIBuilderRef Dref,
Expand Down
57 changes: 0 additions & 57 deletions include/llvm/IR/DebugInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,6 @@ typedef DenseMap<const MDString *, MDNode *> DITypeIdentifierMap;
template <> struct simplify_type<DESC>;
DECLARE_SIMPLIFY_DESCRIPTOR(DISubrange)
DECLARE_SIMPLIFY_DESCRIPTOR(DIEnumerator)
DECLARE_SIMPLIFY_DESCRIPTOR(DIBasicType)
DECLARE_SIMPLIFY_DESCRIPTOR(DIDerivedType)
DECLARE_SIMPLIFY_DESCRIPTOR(DICompositeType)
DECLARE_SIMPLIFY_DESCRIPTOR(DISubroutineType)
DECLARE_SIMPLIFY_DESCRIPTOR(DIFile)
DECLARE_SIMPLIFY_DESCRIPTOR(DICompileUnit)
DECLARE_SIMPLIFY_DESCRIPTOR(DISubprogram)
Expand Down Expand Up @@ -108,55 +104,6 @@ class DIEnumerator {
MDEnumerator &operator*() const { return *N; }
};

class DIBasicType {
MDBasicType *N;

public:
DIBasicType(const MDBasicType *N = nullptr)
: N(const_cast<MDBasicType *>(N)) {}

operator MDBasicType *() const { return N; }
MDBasicType *operator->() const { return N; }
MDBasicType &operator*() const { return *N; }
};

class DIDerivedType {
MDDerivedTypeBase *N;

public:
DIDerivedType(const MDDerivedTypeBase *N = nullptr)
: N(const_cast<MDDerivedTypeBase *>(N)) {}

operator MDDerivedTypeBase *() const { return N; }
MDDerivedTypeBase *operator->() const { return N; }
MDDerivedTypeBase &operator*() const { return *N; }
};

class DICompositeType {
MDCompositeTypeBase *N;

public:
DICompositeType(const MDCompositeTypeBase *N = nullptr)
: N(const_cast<MDCompositeTypeBase *>(N)) {}

operator MDCompositeTypeBase *() const { return N; }
MDCompositeTypeBase *operator->() const { return N; }
MDCompositeTypeBase &operator*() const { return *N; }
};

class DISubroutineType {
MDSubroutineType *N;

public:
DISubroutineType(const MDSubroutineType *N = nullptr)
: N(const_cast<MDSubroutineType *>(N)) {}

operator DICompositeType() const { return N; }
operator MDSubroutineType *() const { return N; }
MDSubroutineType *operator->() const { return N; }
MDSubroutineType &operator*() const { return *N; }
};

class DIFile {
MDFile *N;

Expand Down Expand Up @@ -331,10 +278,6 @@ class DIImportedEntity {
template <> struct simplify_type<DESC> : simplify_type<const DESC> {};
SIMPLIFY_DESCRIPTOR(DISubrange)
SIMPLIFY_DESCRIPTOR(DIEnumerator)
SIMPLIFY_DESCRIPTOR(DIBasicType)
SIMPLIFY_DESCRIPTOR(DIDerivedType)
SIMPLIFY_DESCRIPTOR(DICompositeType)
SIMPLIFY_DESCRIPTOR(DISubroutineType)
SIMPLIFY_DESCRIPTOR(DIFile)
SIMPLIFY_DESCRIPTOR(DICompileUnit)
SIMPLIFY_DESCRIPTOR(DISubprogram)
Expand Down
2 changes: 1 addition & 1 deletion lib/CodeGen/AsmPrinter/DwarfDebug.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1902,7 +1902,7 @@ static uint64_t makeTypeSignature(StringRef Identifier) {

void DwarfDebug::addDwarfTypeUnitType(DwarfCompileUnit &CU,
StringRef Identifier, DIE &RefDie,
DICompositeType CTy) {
const MDCompositeType *CTy) {
// Fast path if we're building some type units and one has already used the
// address pool we know we're going to throw away all this work anyway, so
// don't bother building dependent types.
Expand Down
5 changes: 3 additions & 2 deletions lib/CodeGen/AsmPrinter/DwarfDebug.h
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,8 @@ class DwarfDebug : public AsmPrinterHandler {
// them.
DenseMap<const MDNode *, const DwarfTypeUnit *> DwarfTypeUnits;

SmallVector<std::pair<std::unique_ptr<DwarfTypeUnit>, DICompositeType>, 1>
SmallVector<
std::pair<std::unique_ptr<DwarfTypeUnit>, const MDCompositeType *>, 1>
TypeUnitsUnderConstruction;

// Whether to emit the pubnames/pubtypes sections.
Expand Down Expand Up @@ -519,7 +520,7 @@ class DwarfDebug : public AsmPrinterHandler {
/// \brief Add a DIE to the set of types that we're going to pull into
/// type units.
void addDwarfTypeUnitType(DwarfCompileUnit &CU, StringRef Identifier,
DIE &Die, DICompositeType CTy);
DIE &Die, const MDCompositeType *CTy);

/// \brief Add a label so that arange data can be generated for it.
void addArangeLabel(SymbolCU SCU) { ArangeLabels.push_back(SCU); }
Expand Down
40 changes: 18 additions & 22 deletions lib/CodeGen/AsmPrinter/DwarfUnit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -467,19 +467,19 @@ void DwarfUnit::addBlockByrefAddress(const DbgVariable &DV, DIE &Die,
StringRef varName = DV.getName();

if (Tag == dwarf::DW_TAG_pointer_type) {
DIDerivedType DTy = cast<MDDerivedType>(Ty);
auto *DTy = cast<MDDerivedType>(Ty);
TmpTy = resolve(DTy->getBaseType());
isPointer = true;
}

// Find the __forwarding field and the variable field in the __Block_byref
// struct.
DIArray Fields = cast<MDCompositeTypeBase>(TmpTy)->getElements();
DIDerivedType varField;
DIDerivedType forwardingField;
const MDDerivedType *varField = nullptr;
const MDDerivedType *forwardingField = nullptr;

for (unsigned i = 0, N = Fields.size(); i < N; ++i) {
DIDerivedType DT = cast<MDDerivedTypeBase>(Fields[i]);
auto *DT = cast<MDDerivedType>(Fields[i]);
StringRef fieldName = DT->getName();
if (fieldName == "__forwarding")
forwardingField = DT;
Expand Down Expand Up @@ -535,7 +535,7 @@ void DwarfUnit::addBlockByrefAddress(const DbgVariable &DV, DIE &Die,

/// Return true if type encoding is unsigned.
static bool isUnsignedDIType(DwarfDebug *DD, const MDType *Ty) {
if (DIDerivedType DTy = dyn_cast<MDDerivedTypeBase>(Ty)) {
if (auto *DTy = dyn_cast<MDDerivedTypeBase>(Ty)) {
dwarf::Tag T = (dwarf::Tag)Ty->getTag();
// Encode pointer constants as unsigned bytes. This is used at least for
// null pointer constant emission.
Expand Down Expand Up @@ -565,7 +565,7 @@ static bool isUnsignedDIType(DwarfDebug *DD, const MDType *Ty) {
return false;
}

DIBasicType BTy = cast<MDBasicType>(Ty);
auto *BTy = cast<MDBasicType>(Ty);
unsigned Encoding = BTy->getEncoding();
assert((Encoding == dwarf::DW_ATE_unsigned ||
Encoding == dwarf::DW_ATE_unsigned_char ||
Expand All @@ -583,7 +583,7 @@ static bool isUnsignedDIType(DwarfDebug *DD, const MDType *Ty) {
}

/// If this type is derived from a base type then return base type size.
static uint64_t getBaseTypeSize(DwarfDebug *DD, DIDerivedType Ty) {
static uint64_t getBaseTypeSize(DwarfDebug *DD, const MDDerivedType *Ty) {
unsigned Tag = Ty->getTag();

if (Tag != dwarf::DW_TAG_member && Tag != dwarf::DW_TAG_typedef &&
Expand All @@ -602,7 +602,7 @@ static uint64_t getBaseTypeSize(DwarfDebug *DD, DIDerivedType Ty) {
BaseType->getTag() == dwarf::DW_TAG_rvalue_reference_type)
return Ty->getSizeInBits();

if (auto *DT = dyn_cast<MDDerivedTypeBase>(BaseType))
if (auto *DT = dyn_cast<MDDerivedType>(BaseType))
return getBaseTypeSize(DD, DT);

return BaseType->getSizeInBits();
Expand Down Expand Up @@ -717,7 +717,7 @@ DIE *DwarfUnit::getOrCreateContextDIE(const MDScope *Context) {
return getDIE(Context);
}

DIE *DwarfUnit::createTypeDIE(DICompositeType Ty) {
DIE *DwarfUnit::createTypeDIE(const MDCompositeType *Ty) {
auto *Context = resolve(Ty->getScope());
DIE *ContextDIE = getOrCreateContextDIE(Context);

Expand Down Expand Up @@ -853,7 +853,7 @@ std::string DwarfUnit::getParentContextString(const MDScope *Context) const {
return CS;
}

void DwarfUnit::constructTypeDIE(DIE &Buffer, DIBasicType BTy) {
void DwarfUnit::constructTypeDIE(DIE &Buffer, const MDBasicType *BTy) {
// Get core information.
StringRef Name = BTy->getName();
// Add name if not anonymous or intermediate type.
Expand All @@ -871,7 +871,7 @@ void DwarfUnit::constructTypeDIE(DIE &Buffer, DIBasicType BTy) {
addUInt(Buffer, dwarf::DW_AT_byte_size, None, Size);
}

void DwarfUnit::constructTypeDIE(DIE &Buffer, DIDerivedType DTy) {
void DwarfUnit::constructTypeDIE(DIE &Buffer, const MDDerivedType *DTy) {
// Get core information.
StringRef Name = DTy->getName();
uint64_t Size = DTy->getSizeInBits() >> 3;
Expand Down Expand Up @@ -967,7 +967,7 @@ void DwarfUnit::constructTypeDIE(DIE &Buffer, const MDCompositeType *CTy) {
continue;
if (auto *SP = dyn_cast<MDSubprogram>(Element))
getOrCreateSubprogramDIE(SP);
else if (DIDerivedType DDTy = dyn_cast<MDDerivedTypeBase>(Element)) {
else if (auto *DDTy = dyn_cast<MDDerivedType>(Element)) {
if (DDTy->getTag() == dwarf::DW_TAG_friend) {
DIE &ElemDie = createAndAddDIE(dwarf::DW_TAG_friend, Buffer);
addType(ElemDie, resolve(DDTy->getBaseType()), dwarf::DW_AT_friend);
Expand Down Expand Up @@ -1006,7 +1006,7 @@ void DwarfUnit::constructTypeDIE(DIE &Buffer, const MDCompositeType *CTy) {

// This is outside the DWARF spec, but GDB expects a DW_AT_containing_type
// inside C++ composite types to point to the base class with the vtable.
if (DICompositeType ContainingType =
if (auto *ContainingType =
dyn_cast_or_null<MDCompositeType>(resolve(CTy->getVTableHolder())))
addDIEEntry(Buffer, dwarf::DW_AT_containing_type,
*getOrCreateTypeDIE(ContainingType));
Expand Down Expand Up @@ -1208,7 +1208,7 @@ void DwarfUnit::applySubprogramAttributes(DISubprogram SP, DIE &SPDie,
Language == dwarf::DW_LANG_ObjC))
addFlag(SPDie, dwarf::DW_AT_prototyped);

DISubroutineType SPTy = SP->getType();
const MDSubroutineType *SPTy = SP->getType();
assert(SPTy->getTag() == dwarf::DW_TAG_subroutine_type &&
"the type of a subprogram should be a subroutine");

Expand Down Expand Up @@ -1303,7 +1303,7 @@ DIE *DwarfUnit::getIndexTyDie() {
return IndexTyDie;
}

void DwarfUnit::constructArrayTypeDIE(DIE &Buffer, DICompositeType CTy) {
void DwarfUnit::constructArrayTypeDIE(DIE &Buffer, const MDCompositeType *CTy) {
if (CTy->isVector())
addFlag(Buffer, dwarf::DW_AT_GNU_vector);

Expand All @@ -1325,7 +1325,7 @@ void DwarfUnit::constructArrayTypeDIE(DIE &Buffer, DICompositeType CTy) {
}
}

void DwarfUnit::constructEnumTypeDIE(DIE &Buffer, DICompositeType CTy) {
void DwarfUnit::constructEnumTypeDIE(DIE &Buffer, const MDCompositeType *CTy) {
DIArray Elements = CTy->getElements();

// Add enumerators to enumeration type.
Expand Down Expand Up @@ -1361,10 +1361,7 @@ void DwarfUnit::constructContainingTypeDIEs() {
}
}

void DwarfUnit::constructMemberDIE(DIE &Buffer, DIDerivedType DT_) {
// Downcast to MDDerivedType.
const MDDerivedType *DT = cast<MDDerivedType>(DT_);

void DwarfUnit::constructMemberDIE(DIE &Buffer, const MDDerivedType *DT) {
DIE &MemberDie = createAndAddDIE(DT->getTag(), Buffer);
StringRef Name = DT->getName();
if (!Name.empty())
Expand Down Expand Up @@ -1452,8 +1449,7 @@ void DwarfUnit::constructMemberDIE(DIE &Buffer, DIDerivedType DT_) {
addFlag(MemberDie, dwarf::DW_AT_artificial);
}

DIE *DwarfUnit::getOrCreateStaticMemberDIE(DIDerivedType DT_) {
const MDDerivedType *DT = cast_or_null<MDDerivedType>(DT_);
DIE *DwarfUnit::getOrCreateStaticMemberDIE(const MDDerivedType *DT) {
if (!DT)
return nullptr;

Expand Down
14 changes: 7 additions & 7 deletions lib/CodeGen/AsmPrinter/DwarfUnit.h
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ class DwarfUnit {
DIE *getOrCreateTypeDIE(const MDNode *N);

/// \brief Get context owner's DIE.
DIE *createTypeDIE(DICompositeType Ty);
DIE *createTypeDIE(const MDCompositeType *Ty);

/// \brief Get context owner's DIE.
DIE *getOrCreateContextDIE(const MDScope *Context);
Expand Down Expand Up @@ -339,7 +339,7 @@ class DwarfUnit {

protected:
/// \brief Create new static data member DIE.
DIE *getOrCreateStaticMemberDIE(DIDerivedType DT);
DIE *getOrCreateStaticMemberDIE(const MDDerivedType *DT);

/// Look up the source ID with the given directory and source file names. If
/// none currently exists, create a new ID and insert it in the line table.
Expand All @@ -352,13 +352,13 @@ class DwarfUnit {
}

private:
void constructTypeDIE(DIE &Buffer, DIBasicType BTy);
void constructTypeDIE(DIE &Buffer, DIDerivedType DTy);
void constructTypeDIE(DIE &Buffer, const MDBasicType *BTy);
void constructTypeDIE(DIE &Buffer, const MDDerivedType *DTy);
void constructTypeDIE(DIE &Buffer, const MDSubroutineType *DTy);
void constructSubrangeDIE(DIE &Buffer, DISubrange SR, DIE *IndexTy);
void constructArrayTypeDIE(DIE &Buffer, DICompositeType CTy);
void constructEnumTypeDIE(DIE &Buffer, DICompositeType CTy);
void constructMemberDIE(DIE &Buffer, DIDerivedType DT);
void constructArrayTypeDIE(DIE &Buffer, const MDCompositeType *CTy);
void constructEnumTypeDIE(DIE &Buffer, const MDCompositeType *CTy);
void constructMemberDIE(DIE &Buffer, const MDDerivedType *DT);
void constructTemplateTypeParameterDIE(DIE &Buffer,
DITemplateTypeParameter TP);
void constructTemplateValueParameterDIE(DIE &Buffer,
Expand Down

0 comments on commit 92b3bf9

Please sign in to comment.