From 80608c5d42fe8998eddad5ad2bf16fe2a8515fb1 Mon Sep 17 00:00:00 2001 From: "Duncan P. N. Exon Smith" Date: Mon, 20 Apr 2015 21:04:33 +0000 Subject: [PATCH] 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 --- lib/CodeGen/AsmPrinter/DwarfDebug.cpp | 2 +- lib/CodeGen/AsmPrinter/DwarfUnit.cpp | 63 ++++++++++++++------------- lib/CodeGen/AsmPrinter/DwarfUnit.h | 3 +- 3 files changed, 36 insertions(+), 32 deletions(-) diff --git a/lib/CodeGen/AsmPrinter/DwarfDebug.cpp b/lib/CodeGen/AsmPrinter/DwarfDebug.cpp index 4599a8cec7c..ee126f441ac 100644 --- a/lib/CodeGen/AsmPrinter/DwarfDebug.cpp +++ b/lib/CodeGen/AsmPrinter/DwarfDebug.cpp @@ -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(CTy)); return; } diff --git a/lib/CodeGen/AsmPrinter/DwarfUnit.cpp b/lib/CodeGen/AsmPrinter/DwarfUnit.cpp index c6e759a7c4c..21257511772 100644 --- a/lib/CodeGen/AsmPrinter/DwarfUnit.cpp +++ b/lib/CodeGen/AsmPrinter/DwarfUnit.cpp @@ -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(Ty)); updateAcceleratorTables(Context, Ty, TyDIE); return &TyDIE; @@ -762,7 +762,9 @@ DIE *DwarfUnit::getOrCreateTypeDIE(const MDNode *TyNode) { if (auto *BT = dyn_cast(Ty)) constructTypeDIE(TyDIE, BT); - else if (DICompositeType CTy = dyn_cast(Ty)) { + else if (auto *STy = dyn_cast(Ty)) + constructTypeDIE(TyDIE, STy); + else if (auto *CTy = dyn_cast(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(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(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: { diff --git a/lib/CodeGen/AsmPrinter/DwarfUnit.h b/lib/CodeGen/AsmPrinter/DwarfUnit.h index 1f3bdf029c0..a92b30f4399 100644 --- a/lib/CodeGen/AsmPrinter/DwarfUnit.h +++ b/lib/CodeGen/AsmPrinter/DwarfUnit.h @@ -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); -- 2.34.1