DwarfDebug: Avoid creating new DebugLocs in the backend
[oota-llvm.git] / lib / IR / DebugInfoMetadata.cpp
index 754740a34ee8fb6932ae993939ee1d4ef77c07a9..8dd4c2f5f037759895c4a43dc6176c3bdb610a8b 100644 (file)
@@ -238,6 +238,12 @@ MDCompileUnit *MDCompileUnit::getImpl(
       (SourceLanguage, IsOptimized, RuntimeVersion, EmissionKind), Ops);
 }
 
+MDSubprogram *MDLocalScope::getSubprogram() const {
+  if (auto *Block = dyn_cast<MDLexicalBlockBase>(this))
+    return Block->getScope()->getSubprogram();
+  return const_cast<MDSubprogram *>(cast<MDSubprogram>(this));
+}
+
 MDSubprogram *MDSubprogram::getImpl(
     LLVMContext &Context, Metadata *Scope, MDString *Name,
     MDString *LinkageName, Metadata *File, unsigned Line, Metadata *Type,