diff --git a/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp b/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp index b1c78f0faac4ef..48134f1fd77473 100644 --- a/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp +++ b/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp @@ -1141,21 +1141,6 @@ sortGlobalExprs(SmallVectorImpl &GVEs) { return GVEs; } -/// Create a DIE for \p Ty if it doesn't already exist. If type units are -/// enabled, try to emit a type unit without a CU skeleton DIE. -static void createMaybeUnusedType(DwarfDebug &DD, DwarfCompileUnit &CU, - DIType &Ty) { - // Try to generate a type unit without creating a skeleton DIE in this CU. - if (DICompositeType const *CTy = dyn_cast(&Ty)) { - MDString const *TypeId = CTy->getRawIdentifier(); - if (DD.generateTypeUnits() && TypeId && !Ty.isForwardDecl()) - if (DD.getOrCreateDwarfTypeUnit(CU, TypeId->getString(), CTy)) - return; - } - // We couldn't or shouldn't add a type unit so create the DIE normally. - CU.getOrCreateTypeDIE(&Ty); -} - // Emit all Dwarf sections that should come prior to the content. Create // global DIEs and emit initial debug info sections. This is invoked by // the target AsmPrinter. @@ -1239,17 +1224,15 @@ void DwarfDebug::beginModule(Module *M) { CU.getOrCreateGlobalVariableDIE(GV, sortGlobalExprs(GVMap[GV])); } - for (auto *Ty : CUNode->getEnumTypes()) { - // The enum types array by design contains pointers to - // MDNodes rather than DIRefs. Unique them here. - createMaybeUnusedType(*this, CU, *Ty); - } + for (auto *Ty : CUNode->getEnumTypes()) + CU.getOrCreateTypeDIE(cast(Ty)); + for (auto *Ty : CUNode->getRetainedTypes()) { // The retained types array by design contains pointers to // MDNodes rather than DIRefs. Unique them here. if (DIType *RT = dyn_cast(Ty)) // There is no point in force-emitting a forward declaration. - createMaybeUnusedType(*this, CU, *RT); + CU.getOrCreateTypeDIE(RT); } // Emit imported_modules last so that the relevant context is already // available. @@ -1420,7 +1403,6 @@ void DwarfDebug::finalizeModuleInfo() { SkeletonHolder.computeSizeAndOffsets(); } - // Emit all Dwarf sections that should come after the content. void DwarfDebug::endModule() { // Terminate the pending line table. @@ -3384,30 +3366,17 @@ uint64_t DwarfDebug::makeTypeSignature(StringRef Identifier) { void DwarfDebug::addDwarfTypeUnitType(DwarfCompileUnit &CU, StringRef Identifier, DIE &RefDie, const DICompositeType *CTy) { - bool TopLevelType = TypeUnitsUnderConstruction.empty(); - if (auto Signature = getOrCreateDwarfTypeUnit(CU, Identifier, CTy)) { - CU.addDIETypeSignature(RefDie, *Signature); - } else if (TopLevelType) { - // Construct this type in the CU directly. - // 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, cast(CTy)); - } -} - -Optional -DwarfDebug::getOrCreateDwarfTypeUnit(DwarfCompileUnit &CU, StringRef Identifier, - const DICompositeType *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. if (!TypeUnitsUnderConstruction.empty() && AddrPool.hasBeenUsed()) - return None; + return; auto Ins = TypeSignatures.insert(std::make_pair(CTy, 0)); - if (!Ins.second) - return Ins.first->second; + if (!Ins.second) { + CU.addDIETypeSignature(RefDie, Ins.first->second); + return; + } bool TopLevelType = TypeUnitsUnderConstruction.empty(); AddrPool.resetUsedFlag(); @@ -3461,7 +3430,13 @@ DwarfDebug::getOrCreateDwarfTypeUnit(DwarfCompileUnit &CU, StringRef Identifier, // the type that used an address. for (const auto &TU : TypeUnitsToAdd) TypeSignatures.erase(TU.second); - return None; + + // Construct this type in the CU directly. + // 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, cast(CTy)); + return; } // If the type wasn't dependent on fission addresses, finish adding the type @@ -3471,7 +3446,7 @@ DwarfDebug::getOrCreateDwarfTypeUnit(DwarfCompileUnit &CU, StringRef Identifier, InfoHolder.emitUnit(TU.first.get(), useSplitDwarf()); } } - return Signature; + CU.addDIETypeSignature(RefDie, Signature); } DwarfDebug::NonTypeUnitContext::NonTypeUnitContext(DwarfDebug *DD) diff --git a/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.h b/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.h index ff2589b3c953f8..4e1a1b1e068df6 100644 --- a/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.h +++ b/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.h @@ -667,12 +667,6 @@ class DwarfDebug : public DebugHandlerBase { void addDwarfTypeUnitType(DwarfCompileUnit &CU, StringRef Identifier, DIE &Die, const DICompositeType *CTy); - /// Return the type unit signature of \p CTy after finding or creating its - /// type unit. Return None if a type unit cannot be created for \p CTy. - Optional getOrCreateDwarfTypeUnit(DwarfCompileUnit &CU, - StringRef Identifier, - const DICompositeType *CTy); - class NonTypeUnitContext { DwarfDebug *DD; decltype(DwarfDebug::TypeUnitsUnderConstruction) TypeUnitsUnderConstruction; diff --git a/llvm/test/DebugInfo/X86/type-units-maybe-unused-types.ll b/llvm/test/DebugInfo/Generic/type-units-maybe-unused-types.ll similarity index 98% rename from llvm/test/DebugInfo/X86/type-units-maybe-unused-types.ll rename to llvm/test/DebugInfo/Generic/type-units-maybe-unused-types.ll index 6bfc1e881de7f5..589cd1b337ad09 100644 --- a/llvm/test/DebugInfo/X86/type-units-maybe-unused-types.ll +++ b/llvm/test/DebugInfo/Generic/type-units-maybe-unused-types.ll @@ -1,4 +1,4 @@ -; RUN: llc %s -mtriple=x86_64-linux-gnu -generate-type-units -o - -filetype=obj \ +; RUN: %llc_dwarf %s -generate-type-units -o - -filetype=obj \ ; RUN: | llvm-dwarfdump -o - - \ ; RUN: | FileCheck %s