diff --git a/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.h b/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.h --- a/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.h +++ b/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.h @@ -402,7 +402,7 @@ // FIXME: replace this with a map from comp_dir to table so that we // can emit multiple tables during LTO each of which uses directory // 0, referencing the comp_dir of all the type units that use it. - MCDwarfDwoLineTable SplitTypeUnitFileTable; + std::unique_ptr SplitUnitLineTable = nullptr; /// @} /// True iff there are multiple CUs in this module. @@ -421,8 +421,6 @@ // Identify a debugger for "tuning" the debug info. DebuggerKind DebuggerTuning = DebuggerKind::Default; - MCDwarfDwoLineTable *getDwoLineTable(const DwarfCompileUnit &); - const SmallVectorImpl> &getUnits() { return InfoHolder.getUnits(); } @@ -718,6 +716,12 @@ return EmitDebugEntryValues; } + void initDwoLineTable(const DwarfCompileUnit &); + + MCDwarfDwoLineTable *getSplitUnitLineTable() { + return SplitUnitLineTable.get(); + } + bool shareAcrossDWOCUs() const; /// Returns the Dwarf Version. diff --git a/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp b/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp --- a/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp +++ b/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp @@ -3069,9 +3069,10 @@ void DwarfDebug::emitDebugLineDWO() { assert(useSplitDwarf() && "No split dwarf?"); - SplitTypeUnitFileTable.Emit( - *Asm->OutStreamer, MCDwarfLineTableParams(), - Asm->getObjFileLowering().getDwarfLineDWOSection()); + if (SplitUnitLineTable) + SplitUnitLineTable->Emit( + *Asm->OutStreamer, MCDwarfLineTableParams(), + Asm->getObjFileLowering().getDwarfLineDWOSection()); } void DwarfDebug::emitStringOffsetsTableHeaderDWO() { @@ -3098,14 +3099,16 @@ AddrPool.emit(*Asm, Asm->getObjFileLowering().getDwarfAddrSection()); } -MCDwarfDwoLineTable *DwarfDebug::getDwoLineTable(const DwarfCompileUnit &CU) { +void DwarfDebug::initDwoLineTable(const DwarfCompileUnit &CU) { if (!useSplitDwarf()) - return nullptr; + return; + const DICompileUnit *DIUnit = CU.getCUNode(); - SplitTypeUnitFileTable.maybeSetRootFile( + if (!SplitUnitLineTable) + SplitUnitLineTable = std::make_unique(); + SplitUnitLineTable->maybeSetRootFile( DIUnit->getDirectory(), DIUnit->getFilename(), CU.getMD5AsBytes(DIUnit->getFile()), DIUnit->getSource()); - return &SplitTypeUnitFileTable; } uint64_t DwarfDebug::makeTypeSignature(StringRef Identifier) { @@ -3137,8 +3140,7 @@ bool TopLevelType = TypeUnitsUnderConstruction.empty(); AddrPool.resetUsedFlag(); - auto OwnedUnit = std::make_unique(CU, Asm, this, &InfoHolder, - getDwoLineTable(CU)); + auto OwnedUnit = std::make_unique(CU, Asm, this, &InfoHolder); DwarfTypeUnit &NewTU = *OwnedUnit; DIE &UnitDie = NewTU.getUnitDie(); TypeUnitsUnderConstruction.emplace_back(std::move(OwnedUnit), CTy); diff --git a/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.h b/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.h --- a/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.h +++ b/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.h @@ -343,7 +343,6 @@ uint64_t TypeSignature; const DIE *Ty; DwarfCompileUnit &CU; - MCDwarfDwoLineTable *SplitLineTable; bool UsedLineTable = false; unsigned getOrCreateSourceID(const DIFile *File) override; @@ -352,7 +351,7 @@ public: DwarfTypeUnit(DwarfCompileUnit &CU, AsmPrinter *A, DwarfDebug *DW, - DwarfFile *DWU, MCDwarfDwoLineTable *SplitLineTable = nullptr); + DwarfFile *DWU); void setTypeSignature(uint64_t Signature) { TypeSignature = Signature; } void setType(const DIE *Ty) { this->Ty = Ty; } diff --git a/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp b/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp --- a/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp +++ b/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp @@ -95,10 +95,9 @@ } DwarfTypeUnit::DwarfTypeUnit(DwarfCompileUnit &CU, AsmPrinter *A, - DwarfDebug *DW, DwarfFile *DWU, - MCDwarfDwoLineTable *SplitLineTable) - : DwarfUnit(dwarf::DW_TAG_type_unit, CU.getCUNode(), A, DW, DWU), CU(CU), - SplitLineTable(SplitLineTable) { + DwarfDebug *DW, DwarfFile *DWU) + : DwarfUnit(dwarf::DW_TAG_type_unit, CU.getCUNode(), A, DW, DWU), CU(CU) { + DW->initDwoLineTable(CU); } DwarfUnit::~DwarfUnit() { @@ -325,17 +324,17 @@ } unsigned DwarfTypeUnit::getOrCreateSourceID(const DIFile *File) { - if (!SplitLineTable) + if (!DD->getSplitUnitLineTable()) return getCU().getOrCreateSourceID(File); + if (!UsedLineTable) { UsedLineTable = true; // This is a split type unit that needs a line table. addSectionOffset(getUnitDie(), dwarf::DW_AT_stmt_list, 0); } - return SplitLineTable->getFile(File->getDirectory(), File->getFilename(), - getMD5AsBytes(File), - Asm->OutContext.getDwarfVersion(), - File->getSource()); + return DD->getSplitUnitLineTable()->getFile( + File->getDirectory(), File->getFilename(), getMD5AsBytes(File), + Asm->OutContext.getDwarfVersion(), File->getSource()); } void DwarfUnit::addOpAddress(DIELoc &Die, const MCSymbol *Sym) {