DwarfUnit: Split MDSubroutineType version of constructTypeDIE()

The version of `constructTypeDIE()` for `MDSubroutineType` is unrelated
to (and has different callers than) the `MDCompositeType`.  Split the
two in half.

This simplifies an upcoming patch to delete `DICompositeType`.  There
shouldn't be any real functionality change here.  `createTypeDIE()` is
`cast<>`'ing where it didn't need to before, but that function in turn
is only called for true `MDCompositeType`s.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@235349 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Duncan P. N. Exon Smith 2015-04-20 21:04:33 +00:00
parent 302f000bf4
commit 80608c5d42
3 changed files with 36 additions and 32 deletions

View File

@ -1961,7 +1961,7 @@ void DwarfDebug::addDwarfTypeUnitType(DwarfCompileUnit &CU,
// This is inefficient because all the dependent types will be rebuilt
// from scratch, including building them in type units, discovering that
// they depend on addresses, throwing them out and rebuilding them.
CU.constructTypeDIE(RefDie, CTy);
CU.constructTypeDIE(RefDie, cast<MDCompositeType>(CTy));
return;
}

View File

@ -727,7 +727,7 @@ DIE *DwarfUnit::createTypeDIE(DICompositeType Ty) {
// Create new type.
DIE &TyDIE = createAndAddDIE(Ty->getTag(), *ContextDIE, Ty);
constructTypeDIE(TyDIE, Ty);
constructTypeDIE(TyDIE, cast<MDCompositeType>(Ty));
updateAcceleratorTables(Context, Ty, TyDIE);
return &TyDIE;
@ -762,7 +762,9 @@ DIE *DwarfUnit::getOrCreateTypeDIE(const MDNode *TyNode) {
if (auto *BT = dyn_cast<MDBasicType>(Ty))
constructTypeDIE(TyDIE, BT);
else if (DICompositeType CTy = dyn_cast<MDCompositeTypeBase>(Ty)) {
else if (auto *STy = dyn_cast<MDSubroutineType>(Ty))
constructTypeDIE(TyDIE, STy);
else if (auto *CTy = dyn_cast<MDCompositeType>(Ty)) {
if (GenerateDwarfTypeUnits && !Ty->isForwardDecl())
if (MDString *TypeId = CTy->getRawIdentifier()) {
DD->addDwarfTypeUnitType(getCU(), TypeId->getString(), TyDIE, CTy);
@ -913,7 +915,35 @@ void DwarfUnit::constructSubprogramArguments(DIE &Buffer, DITypeArray Args) {
}
}
void DwarfUnit::constructTypeDIE(DIE &Buffer, DICompositeType CTy) {
void DwarfUnit::constructTypeDIE(DIE &Buffer, const MDSubroutineType *CTy) {
// Add return type. A void return won't have a type.
auto Elements = cast<MDSubroutineType>(CTy)->getTypeArray();
if (Elements.size())
if (auto RTy = resolve(Elements[0]))
addType(Buffer, RTy);
bool isPrototyped = true;
if (Elements.size() == 2 && !Elements[1])
isPrototyped = false;
constructSubprogramArguments(Buffer, Elements);
// Add prototype flag if we're dealing with a C language and the function has
// been prototyped.
uint16_t Language = getLanguage();
if (isPrototyped &&
(Language == dwarf::DW_LANG_C89 || Language == dwarf::DW_LANG_C99 ||
Language == dwarf::DW_LANG_ObjC))
addFlag(Buffer, dwarf::DW_AT_prototyped);
if (CTy->isLValueReference())
addFlag(Buffer, dwarf::DW_AT_reference);
if (CTy->isRValueReference())
addFlag(Buffer, dwarf::DW_AT_rvalue_reference);
}
void DwarfUnit::constructTypeDIE(DIE &Buffer, const MDCompositeType *CTy) {
// Add name if not anonymous or intermediate type.
StringRef Name = CTy->getName();
@ -927,33 +957,6 @@ void DwarfUnit::constructTypeDIE(DIE &Buffer, DICompositeType CTy) {
case dwarf::DW_TAG_enumeration_type:
constructEnumTypeDIE(Buffer, CTy);
break;
case dwarf::DW_TAG_subroutine_type: {
// Add return type. A void return won't have a type.
auto Elements = cast<MDSubroutineType>(CTy)->getTypeArray();
if (Elements.size())
if (auto RTy = resolve(Elements[0]))
addType(Buffer, RTy);
bool isPrototyped = true;
if (Elements.size() == 2 && !Elements[1])
isPrototyped = false;
constructSubprogramArguments(Buffer, Elements);
// Add prototype flag if we're dealing with a C language and the
// function has been prototyped.
uint16_t Language = getLanguage();
if (isPrototyped &&
(Language == dwarf::DW_LANG_C89 || Language == dwarf::DW_LANG_C99 ||
Language == dwarf::DW_LANG_ObjC))
addFlag(Buffer, dwarf::DW_AT_prototyped);
if (CTy->isLValueReference())
addFlag(Buffer, dwarf::DW_AT_reference);
if (CTy->isRValueReference())
addFlag(Buffer, dwarf::DW_AT_rvalue_reference);
} break;
case dwarf::DW_TAG_structure_type:
case dwarf::DW_TAG_union_type:
case dwarf::DW_TAG_class_type: {

View File

@ -335,7 +335,7 @@ public:
virtual DwarfCompileUnit &getCU() = 0;
void constructTypeDIE(DIE &Buffer, DICompositeType CTy);
void constructTypeDIE(DIE &Buffer, const MDCompositeType *CTy);
protected:
/// \brief Create new static data member DIE.
@ -354,6 +354,7 @@ protected:
private:
void constructTypeDIE(DIE &Buffer, DIBasicType BTy);
void constructTypeDIE(DIE &Buffer, DIDerivedType 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);