Make DebugLoc independent of DwarfWriter.

-Replace DebugLocTuple's Source ID with CompileUnit's GlobalVariable*
-Remove DwarfWriter::getOrCreateSourceID
-Make necessary changes for the above (fix callsites, etc.)


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@70520 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/CodeGen/AsmPrinter/DwarfWriter.cpp b/lib/CodeGen/AsmPrinter/DwarfWriter.cpp
index 499f800..bfac3b6 100644
--- a/lib/CodeGen/AsmPrinter/DwarfWriter.cpp
+++ b/lib/CodeGen/AsmPrinter/DwarfWriter.cpp
@@ -1103,7 +1103,7 @@
 public:
   SrcLineInfo(unsigned L, unsigned C, unsigned S, unsigned I)
     : Line(L), Column(C), SourceID(S), LabelID(I) {}
-  
+
   // Accessors
   unsigned getLine()     const { return Line; }
   unsigned getColumn()   const { return Column; }
@@ -3426,10 +3426,13 @@
   /// RecordSourceLine - Records location information and associates it with a 
   /// label. Returns a unique label ID used to generate a label and provide
   /// correspondence to the source line list.
-  unsigned RecordSourceLine(unsigned Line, unsigned Col, unsigned Src) {
+  unsigned RecordSourceLine(unsigned Line, unsigned Col, DICompileUnit CU) {
     if (TimePassesIsEnabled)
       DebugTimer->startTimer();
 
+    std::string Dir, Fn;
+    unsigned Src = GetOrCreateSourceID(CU.getDirectory(Dir),
+                                       CU.getFilename(Fn));
     unsigned ID = MMI->NextLabelID();
     Lines.push_back(SrcLineInfo(Line, Col, Src, ID));
 
@@ -3529,10 +3532,13 @@
 
   //// RecordInlinedFnStart - Indicate the start of inlined subroutine.
   void RecordInlinedFnStart(Instruction *FSI, DISubprogram &SP, unsigned LabelID,
-                            unsigned Src, unsigned Line, unsigned Col) {
+                            DICompileUnit CU, unsigned Line, unsigned Col) {
     if (!TAI->doesDwarfUsesInlineInfoSection())
       return;
 
+    std::string Dir, Fn;
+    unsigned Src = GetOrCreateSourceID(CU.getDirectory(Dir),
+                                       CU.getFilename(Fn));
     DbgScope *Scope = createInlinedSubroutineScope(SP, Src, Line, Col);
     Scope->setStartLabelID(LabelID);
     MMI->RecordUsedDbgLabel(LabelID);
@@ -4739,17 +4745,8 @@
 /// label. Returns a unique label ID used to generate a label and provide
 /// correspondence to the source line list.
 unsigned DwarfWriter::RecordSourceLine(unsigned Line, unsigned Col, 
-                                       unsigned Src) {
-  return DD->RecordSourceLine(Line, Col, Src);
-}
-
-/// getOrCreateSourceID - Look up the source id with the given directory and
-/// source file names. If none currently exists, create a new id and insert it
-/// in the SourceIds map. This can update DirectoryNames and SourceFileNames maps
-/// as well.
-unsigned DwarfWriter::getOrCreateSourceID(const std::string &DirName,
-                                          const std::string &FileName) {
-  return DD->getOrCreateSourceID(DirName, FileName);
+                                       DICompileUnit CU) {
+  return DD->RecordSourceLine(Line, Col, CU);
 }
 
 /// RecordRegionStart - Indicate the start of a region.
@@ -4783,9 +4780,9 @@
 //// RecordInlinedFnStart - Global variable GV is inlined at the location marked
 //// by LabelID label.
 void DwarfWriter::RecordInlinedFnStart(Instruction *I, DISubprogram &SP, 
-                                       unsigned LabelID, unsigned Src, 
+                                       unsigned LabelID, DICompileUnit CU,
                                        unsigned Line, unsigned Col) {
-  DD->RecordInlinedFnStart(I, SP, LabelID, Src, Line, Col);
+  DD->RecordInlinedFnStart(I, SP, LabelID, CU, Line, Col);
 }
 
 /// RecordInlinedFnEnd - Indicate the end of inlined subroutine.
diff --git a/lib/CodeGen/MachineFunction.cpp b/lib/CodeGen/MachineFunction.cpp
index e0cdad77..5135308 100644
--- a/lib/CodeGen/MachineFunction.cpp
+++ b/lib/CodeGen/MachineFunction.cpp
@@ -398,9 +398,9 @@
 /// getOrCreateDebugLocID - Look up the DebugLocTuple index with the given
 /// source file, line, and column. If none currently exists, create a new
 /// DebugLocTuple, and insert it into the DebugIdMap.
-unsigned MachineFunction::getOrCreateDebugLocID(unsigned Src, unsigned Line,
-                                                unsigned Col) {
-  DebugLocTuple Tuple(Src, Line, Col);
+unsigned MachineFunction::getOrCreateDebugLocID(GlobalVariable *CompileUnit,
+                                                unsigned Line, unsigned Col) {
+  DebugLocTuple Tuple(CompileUnit, Line, Col);
   DenseMap<DebugLocTuple, unsigned>::iterator II
     = DebugLocInfo.DebugIdMap.find(Tuple);
   if (II != DebugLocInfo.DebugIdMap.end())
diff --git a/lib/CodeGen/MachineInstr.cpp b/lib/CodeGen/MachineInstr.cpp
index 9cfff82..b8c8563 100644
--- a/lib/CodeGen/MachineInstr.cpp
+++ b/lib/CodeGen/MachineInstr.cpp
@@ -22,6 +22,7 @@
 #include "llvm/Target/TargetInstrInfo.h"
 #include "llvm/Target/TargetInstrDesc.h"
 #include "llvm/Target/TargetRegisterInfo.h"
+#include "llvm/Analysis/DebugInfo.h"
 #include "llvm/Support/LeakDetector.h"
 #include "llvm/Support/MathExtras.h"
 #include "llvm/Support/Streams.h"
@@ -979,8 +980,10 @@
   if (!debugLoc.isUnknown()) {
     const MachineFunction *MF = getParent()->getParent();
     DebugLocTuple DLT = MF->getDebugLocTuple(debugLoc);
+    DICompileUnit CU(DLT.CompileUnit);
+    std::string Dir, Fn;
     OS << " [dbg: "
-       << DLT.Src  << ","
+       << CU.getDirectory(Dir) << '/' << CU.getFilename(Fn) << ","
        << DLT.Line << ","
        << DLT.Col  << "]";
   }
diff --git a/lib/CodeGen/SelectionDAG/FastISel.cpp b/lib/CodeGen/SelectionDAG/FastISel.cpp
index 09ac586..58e8490 100644
--- a/lib/CodeGen/SelectionDAG/FastISel.cpp
+++ b/lib/CodeGen/SelectionDAG/FastISel.cpp
@@ -329,13 +329,10 @@
     DbgStopPointInst *SPI = cast<DbgStopPointInst>(I);
     if (DW && DW->ValidDebugInfo(SPI->getContext(), CodeGenOpt::None)) {
       DICompileUnit CU(cast<GlobalVariable>(SPI->getContext()));
-      std::string Dir, FN;
-      unsigned SrcFile = DW->getOrCreateSourceID(CU.getDirectory(Dir),
-                                                 CU.getFilename(FN));
       unsigned Line = SPI->getLine();
       unsigned Col = SPI->getColumn();
-      unsigned ID = DW->RecordSourceLine(Line, Col, SrcFile);
-      unsigned Idx = MF.getOrCreateDebugLocID(SrcFile, Line, Col);
+      unsigned ID = DW->RecordSourceLine(Line, Col, CU);
+      unsigned Idx = MF.getOrCreateDebugLocID(CU.getGV(), Line, Col);
       setCurDebugLoc(DebugLoc::get(Idx));
       const TargetInstrDesc &II = TII.get(TargetInstrInfo::DBG_LABEL);
       BuildMI(MBB, DL, II).addImm(ID);
@@ -386,9 +383,6 @@
       DebugLoc PrevLoc = DL;
       DISubprogram Subprogram(cast<GlobalVariable>(SP));
       DICompileUnit CompileUnit = Subprogram.getCompileUnit();
-      std::string Dir, FN;
-      unsigned SrcFile = DW->getOrCreateSourceID(CompileUnit.getDirectory(Dir),
-                                                 CompileUnit.getFilename(FN));
 
       if (!Subprogram.describes(MF.getFunction())) {
         // This is a beginning of an inlined function.
@@ -400,21 +394,23 @@
           return true;
         // Record the source line.
         unsigned Line = Subprogram.getLineNumber();
-        unsigned LabelID = DW->RecordSourceLine(Line, 0, SrcFile);
-        setCurDebugLoc(DebugLoc::get(MF.getOrCreateDebugLocID(SrcFile, Line, 0)));
+        unsigned LabelID = DW->RecordSourceLine(Line, 0, CompileUnit);
+        setCurDebugLoc(DebugLoc::get(MF.getOrCreateDebugLocID(
+                                                CompileUnit.getGV(), Line, 0)));
 
         const TargetInstrDesc &II = TII.get(TargetInstrInfo::DBG_LABEL);
         BuildMI(MBB, DL, II).addImm(LabelID);
         DebugLocTuple PrevLocTpl = MF.getDebugLocTuple(PrevLoc);
         DW->RecordInlinedFnStart(FSI, Subprogram, LabelID, 
-                                 PrevLocTpl.Src,
+                                 DICompileUnit(PrevLocTpl.CompileUnit),
                                  PrevLocTpl.Line,
                                  PrevLocTpl.Col);
       } else {
         // Record the source line.
         unsigned Line = Subprogram.getLineNumber();
-        setCurDebugLoc(DebugLoc::get(MF.getOrCreateDebugLocID(SrcFile, Line, 0)));
-        DW->RecordSourceLine(Line, 0, SrcFile);
+        setCurDebugLoc(DebugLoc::get(MF.getOrCreateDebugLocID(
+                                                CompileUnit.getGV(), Line, 0)));
+        DW->RecordSourceLine(Line, 0, CompileUnit);
         // llvm.dbg.func_start also defines beginning of function scope.
         DW->RecordRegionStart(cast<GlobalVariable>(FSI->getSubprogram()));
       }
diff --git a/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp b/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp
index 9c43065..9d66609 100644
--- a/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp
+++ b/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp
@@ -1269,9 +1269,6 @@
       GlobalVariable *CU_GV = cast<GlobalVariable>(DSP->getCompileUnit());
       if (DW && (useDEBUG_LOC || useLABEL) && !CU_GV->isDeclaration()) {
         DICompileUnit CU(cast<GlobalVariable>(DSP->getCompileUnit()));
-        std::string Dir, FN;
-        unsigned SrcFile = DW->getOrCreateSourceID(CU.getDirectory(Dir),
-                                                   CU.getFilename(FN));
 
         unsigned Line = DSP->getLine();
         unsigned Col = DSP->getColumn();
@@ -1282,10 +1279,10 @@
           if (useDEBUG_LOC) {
             SDValue Ops[] = { Tmp1, DAG.getConstant(Line, MVT::i32),
                               DAG.getConstant(Col, MVT::i32),
-                              DAG.getConstant(SrcFile, MVT::i32) };
+                              DAG.getSrcValue(CU.getGV()) };
             Result = DAG.getNode(ISD::DEBUG_LOC, dl, MVT::Other, Ops, 4);
           } else {
-            unsigned ID = DW->RecordSourceLine(Line, Col, SrcFile);
+            unsigned ID = DW->RecordSourceLine(Line, Col, CU);
             Result = DAG.getLabel(ISD::DBG_LABEL, dl, Tmp1, ID);
           }
         } else {
diff --git a/lib/CodeGen/SelectionDAG/SelectionDAGBuild.cpp b/lib/CodeGen/SelectionDAG/SelectionDAGBuild.cpp
index 71f5d81..aecfbb4 100644
--- a/lib/CodeGen/SelectionDAG/SelectionDAGBuild.cpp
+++ b/lib/CodeGen/SelectionDAG/SelectionDAGBuild.cpp
@@ -337,10 +337,7 @@
             if (DW && DW->ValidDebugInfo(SPI->getContext(),
                                          CodeGenOpt::Default)) {
               DICompileUnit CU(cast<GlobalVariable>(SPI->getContext()));
-              std::string Dir, FN;
-              unsigned SrcFile = DW->getOrCreateSourceID(CU.getDirectory(Dir),
-                                                         CU.getFilename(FN));
-              unsigned idx = MF->getOrCreateDebugLocID(SrcFile,
+              unsigned idx = MF->getOrCreateDebugLocID(CU.getGV(),
                                                        SPI->getLine(),
                                                        SPI->getColumn());
               DL = DebugLoc::get(idx);
@@ -357,11 +354,9 @@
               if (DW->ValidDebugInfo(SP, CodeGenOpt::Default)) {
                 DISubprogram Subprogram(cast<GlobalVariable>(SP));
                 DICompileUnit CU(Subprogram.getCompileUnit());
-                std::string Dir, FN;
-                unsigned SrcFile = DW->getOrCreateSourceID(CU.getDirectory(Dir),
-                                                           CU.getFilename(FN));
                 unsigned Line = Subprogram.getLineNumber();
-                DL = DebugLoc::get(MF->getOrCreateDebugLocID(SrcFile, Line, 0));
+                DL = DebugLoc::get(MF->getOrCreateDebugLocID(CU.getGV(),
+                                                             Line, 0));
               }
             }
 
@@ -3905,10 +3900,7 @@
                                         SPI.getColumn(),
                                         SPI.getContext()));
       DICompileUnit CU(cast<GlobalVariable>(SPI.getContext()));
-      std::string Dir, FN;
-      unsigned SrcFile = DW->getOrCreateSourceID(CU.getDirectory(Dir),
-                                                 CU.getFilename(FN));
-      unsigned idx = MF.getOrCreateDebugLocID(SrcFile,
+      unsigned idx = MF.getOrCreateDebugLocID(CU.getGV(),
                                               SPI.getLine(), SPI.getColumn());
       setCurDebugLoc(DebugLoc::get(idx));
     }
@@ -3974,9 +3966,6 @@
         DebugLoc PrevLoc = CurDebugLoc;
         DISubprogram Subprogram(cast<GlobalVariable>(SP));
         DICompileUnit CompileUnit = Subprogram.getCompileUnit();
-        std::string Dir, FN;
-        unsigned SrcFile = DW->getOrCreateSourceID(CompileUnit.getDirectory(Dir),
-                                                   CompileUnit.getFilename(FN));
         
         if (!Subprogram.describes(MF.getFunction())) {
           // This is a beginning of an inlined function.
@@ -3989,21 +3978,23 @@
 
           // Record the source line.
           unsigned Line = Subprogram.getLineNumber();
-          unsigned LabelID = DW->RecordSourceLine(Line, 0, SrcFile);
-          setCurDebugLoc(DebugLoc::get(MF.getOrCreateDebugLocID(SrcFile, Line, 0)));
+          unsigned LabelID = DW->RecordSourceLine(Line, 0, CompileUnit);
+          setCurDebugLoc(DebugLoc::get(
+                       MF.getOrCreateDebugLocID(CompileUnit.getGV(), Line, 0)));
 
           DAG.setRoot(DAG.getLabel(ISD::DBG_LABEL, getCurDebugLoc(),
                                    getRoot(), LabelID));
           DebugLocTuple PrevLocTpl = MF.getDebugLocTuple(PrevLoc);
           DW->RecordInlinedFnStart(&FSI, Subprogram, LabelID, 
-                                   PrevLocTpl.Src,
+                                   DICompileUnit(PrevLocTpl.CompileUnit),
                                    PrevLocTpl.Line,
                                    PrevLocTpl.Col);
         } else {
           // Record the source line.
           unsigned Line = Subprogram.getLineNumber();
-          setCurDebugLoc(DebugLoc::get(MF.getOrCreateDebugLocID(SrcFile, Line, 0)));
-          DW->RecordSourceLine(Line, 0, SrcFile);
+          setCurDebugLoc(DebugLoc::get(
+                       MF.getOrCreateDebugLocID(CompileUnit.getGV(), Line, 0)));
+          DW->RecordSourceLine(Line, 0, CompileUnit);
           // llvm.dbg.func_start also defines beginning of function scope.
           DW->RecordRegionStart(cast<GlobalVariable>(FSI.getSubprogram()));
         }
@@ -4022,15 +4013,13 @@
         // llvm.dbg.func.start implicitly defines a dbg_stoppoint which is
         // what (most?) gdb expects.
         DICompileUnit CompileUnit = Subprogram.getCompileUnit();
-        std::string Dir, FN;
-        unsigned SrcFile = DW->getOrCreateSourceID(CompileUnit.getDirectory(Dir),
-                                                   CompileUnit.getFilename(FN));
         
         // 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 Line = Subprogram.getLineNumber();
-        setCurDebugLoc(DebugLoc::get(MF.getOrCreateDebugLocID(SrcFile, Line, 0)));
+        setCurDebugLoc(DebugLoc::get(
+                       MF.getOrCreateDebugLocID(CompileUnit.getGV(), Line, 0)));
         // FIXME -  Start new region because llvm.dbg.func_start also defines 
         // beginning of function scope.
       }