Use DebugInfo interface to lower dbg_* intrinsics.



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@62127 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/CodeGen/SelectionDAG/SelectionDAGBuild.cpp b/lib/CodeGen/SelectionDAG/SelectionDAGBuild.cpp
index 294acd8..d786e5e 100644
--- a/lib/CodeGen/SelectionDAG/SelectionDAGBuild.cpp
+++ b/lib/CodeGen/SelectionDAG/SelectionDAGBuild.cpp
@@ -37,6 +37,8 @@
 #include "llvm/CodeGen/MachineRegisterInfo.h"
 #include "llvm/CodeGen/PseudoSourceValue.h"
 #include "llvm/CodeGen/SelectionDAG.h"
+#include "llvm/CodeGen/DwarfWriter.h"
+#include "llvm/Analysis/DebugInfo.h"
 #include "llvm/Target/TargetRegisterInfo.h"
 #include "llvm/Target/TargetData.h"
 #include "llvm/Target/TargetFrameInfo.h"
@@ -3742,67 +3744,65 @@
     return 0;
   }
   case Intrinsic::dbg_stoppoint: {
-    MachineModuleInfo *MMI = DAG.getMachineModuleInfo();
+    DwarfWriter *DW = DAG.getDwarfWriter();
     DbgStopPointInst &SPI = cast<DbgStopPointInst>(I);
-    if (MMI && SPI.getContext() && MMI->Verify(SPI.getContext())) {
-      DebugInfoDesc *DD = MMI->getDescFor(SPI.getContext());
-      assert(DD && "Not a debug information descriptor");
+    if (DW && SPI.getContext())
       DAG.setRoot(DAG.getDbgStopPoint(getRoot(),
                                       SPI.getLine(),
                                       SPI.getColumn(),
-                                      cast<CompileUnitDesc>(DD)));
-    }
-
+                                      SPI.getContext()));
     return 0;
   }
   case Intrinsic::dbg_region_start: {
-    MachineModuleInfo *MMI = DAG.getMachineModuleInfo();
+    DwarfWriter *DW = DAG.getDwarfWriter();
     DbgRegionStartInst &RSI = cast<DbgRegionStartInst>(I);
-    if (MMI && RSI.getContext() && MMI->Verify(RSI.getContext())) {
-      unsigned LabelID = MMI->RecordRegionStart(RSI.getContext());
+    if (DW && RSI.getContext()) {
+      unsigned LabelID = 
+        DW->RecordRegionStart(cast<GlobalVariable>(RSI.getContext()));
       DAG.setRoot(DAG.getLabel(ISD::DBG_LABEL, getRoot(), LabelID));
     }
 
     return 0;
   }
   case Intrinsic::dbg_region_end: {
-    MachineModuleInfo *MMI = DAG.getMachineModuleInfo();
+    DwarfWriter *DW = DAG.getDwarfWriter();
     DbgRegionEndInst &REI = cast<DbgRegionEndInst>(I);
-    if (MMI && REI.getContext() && MMI->Verify(REI.getContext())) {
-      unsigned LabelID = MMI->RecordRegionEnd(REI.getContext());
+    if (DW && REI.getContext()) {
+      unsigned LabelID = 
+        DW->RecordRegionEnd(cast<GlobalVariable>(REI.getContext()));
       DAG.setRoot(DAG.getLabel(ISD::DBG_LABEL, getRoot(), LabelID));
     }
 
     return 0;
   }
   case Intrinsic::dbg_func_start: {
-    MachineModuleInfo *MMI = DAG.getMachineModuleInfo();
-    if (!MMI) return 0;
+    DwarfWriter *DW = DAG.getDwarfWriter();
+    if (!DW) return 0;
     DbgFuncStartInst &FSI = cast<DbgFuncStartInst>(I);
     Value *SP = FSI.getSubprogram();
-    if (SP && MMI->Verify(SP)) {
+    if (SP) {
       // llvm.dbg.func.start implicitly defines a dbg_stoppoint which is
       // what (most?) gdb expects.
-      DebugInfoDesc *DD = MMI->getDescFor(SP);
-      assert(DD && "Not a debug information descriptor");
-      SubprogramDesc *Subprogram = cast<SubprogramDesc>(DD);
-      const CompileUnitDesc *CompileUnit = Subprogram->getFile();
-      unsigned SrcFile = MMI->RecordSource(CompileUnit);
+      DISubprogram Subprogram(cast<GlobalVariable>(SP));
+      DICompileUnit CompileUnit = Subprogram.getCompileUnit();
+      unsigned SrcFile = DW->RecordSource(CompileUnit.getDirectory(),
+                                          CompileUnit.getFilename());
       // Record the source line but does not create a label for the normal
       // function start. It will be emitted at asm emission time. However,
       // create a label if this is a beginning of inlined function.
-      unsigned LabelID = MMI->RecordSourceLine(Subprogram->getLine(), 0, SrcFile);
-      if (MMI->getSourceLines().size() != 1)
+      unsigned LabelID = 
+        DW->RecordSourceLine(Subprogram.getLineNumber(), 0, SrcFile);
+      if (DW->getRecordSourceLineCount() != 1)
         DAG.setRoot(DAG.getLabel(ISD::DBG_LABEL, getRoot(), LabelID));
     }
 
     return 0;
   }
   case Intrinsic::dbg_declare: {
-    MachineModuleInfo *MMI = DAG.getMachineModuleInfo();
+    DwarfWriter *DW = DAG.getDwarfWriter();
     DbgDeclareInst &DI = cast<DbgDeclareInst>(I);
     Value *Variable = DI.getVariable();
-    if (MMI && Variable && MMI->Verify(Variable))
+    if (DW && Variable)
       DAG.setRoot(DAG.getNode(ISD::DECLARE, MVT::Other, getRoot(),
                               getValue(DI.getAddress()), getValue(Variable)));
     return 0;