From 494ae8db19a035bcf01ce43e7623a145491abbd4 Mon Sep 17 00:00:00 2001 From: "Duncan P. N. Exon Smith" Date: Mon, 30 Mar 2015 21:32:28 +0000 Subject: [PATCH] DwarfDebug: Avoid creating new DebugLocs in the backend Don't use `DebugLoc::getFnDebugLoc()`, which creates new `MDLocation`s, in the backend. We just want to grab the subprogram here anyway. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@233601 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/IR/DebugInfoMetadata.h | 6 ++++++ lib/CodeGen/AsmPrinter/DwarfDebug.cpp | 8 +++----- lib/IR/DebugInfoMetadata.cpp | 6 ++++++ 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/include/llvm/IR/DebugInfoMetadata.h b/include/llvm/IR/DebugInfoMetadata.h index a1e229e3743..ce6e88496b6 100644 --- a/include/llvm/IR/DebugInfoMetadata.h +++ b/include/llvm/IR/DebugInfoMetadata.h @@ -889,6 +889,12 @@ protected: ~MDLocalScope() {} public: + /// \brief Get the subprogram for this scope. + /// + /// Return this if it's an \a MDSubprogram; otherwise, look up the scope + /// chain. + MDSubprogram *getSubprogram() const; + static bool classof(const Metadata *MD) { return MD->getMetadataID() == MDSubprogramKind || MD->getMetadataID() == MDLexicalBlockKind || diff --git a/lib/CodeGen/AsmPrinter/DwarfDebug.cpp b/lib/CodeGen/AsmPrinter/DwarfDebug.cpp index 2d9c311029a..9303865d7ca 100644 --- a/lib/CodeGen/AsmPrinter/DwarfDebug.cpp +++ b/lib/CodeGen/AsmPrinter/DwarfDebug.cpp @@ -1168,13 +1168,11 @@ void DwarfDebug::beginFunction(const MachineFunction *MF) { // Record beginning of function. PrologEndLoc = findPrologueEndLoc(MF); - if (PrologEndLoc) { - DebugLoc FnStartDL = PrologEndLoc.getFnDebugLoc(); - + if (MDLocation *L = PrologEndLoc) { // We'd like to list the prologue as "not statements" but GDB behaves // poorly if we do that. Revisit this with caution/GDB (7.5+) testing. - recordSourceLine(FnStartDL.getLine(), FnStartDL.getCol(), - FnStartDL.getScope(), DWARF2_FLAG_IS_STMT); + auto *SP = L->getInlinedAtScope()->getSubprogram(); + recordSourceLine(SP->getScopeLine(), 0, SP, DWARF2_FLAG_IS_STMT); } } diff --git a/lib/IR/DebugInfoMetadata.cpp b/lib/IR/DebugInfoMetadata.cpp index 754740a34ee..8dd4c2f5f03 100644 --- a/lib/IR/DebugInfoMetadata.cpp +++ b/lib/IR/DebugInfoMetadata.cpp @@ -238,6 +238,12 @@ MDCompileUnit *MDCompileUnit::getImpl( (SourceLanguage, IsOptimized, RuntimeVersion, EmissionKind), Ops); } +MDSubprogram *MDLocalScope::getSubprogram() const { + if (auto *Block = dyn_cast(this)) + return Block->getScope()->getSubprogram(); + return const_cast(cast(this)); +} + MDSubprogram *MDSubprogram::getImpl( LLVMContext &Context, Metadata *Scope, MDString *Name, MDString *LinkageName, Metadata *File, unsigned Line, Metadata *Type, -- 2.34.1