LTO+Debug Info: revert r182791.

Since the testing case uses ref_addr, which requires version 3+ to work,
we will solve the dwarf version issue first.

This patch also causes failures in one of the bots. I will update the patch
accordingly in my next attempt.

rdar://13926659


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@182867 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/CodeGen/AsmPrinter/DwarfDebug.cpp b/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
index e764e36..2d42af8 100644
--- a/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
+++ b/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
@@ -190,7 +190,6 @@
       IsDarwinGDBCompat = false;
   } else
     IsDarwinGDBCompat = DarwinGDBCompat == Enable ? true : false;
-  UseRefAddr = false;
 
   if (DwarfAccelTables == Default) {
     if (IsDarwin)
@@ -370,8 +369,6 @@
     SPCU->addDIEEntry(SPDie, dwarf::DW_AT_abstract_origin,
                       InSameCU ? dwarf::DW_FORM_ref4 : dwarf::DW_FORM_ref_addr,
                       AbsSPDIE);
-    if (!InSameCU)
-      UseRefAddr = true;
     SPCU->addDie(SPDie);
   } else {
     DISubprogram SPDecl = SP.getFunctionDeclaration();
@@ -472,17 +469,6 @@
   return ScopeDIE;
 }
 
-DIE *DwarfDebug::findSPDieInAllCUs(const MDNode *N) {
-  for (DenseMap<const MDNode *, CompileUnit *>::iterator CUI = CUMap.begin(),
-         CUE = CUMap.end(); CUI != CUE; ++CUI) {
-    CompileUnit *TheCU = CUI->second;
-    DIE *SPDie = TheCU->getDIE(N);
-    if (SPDie)
-      return SPDie;
-  }
-  return 0;
-}
-
 // This scope represents inlined body of a function. Construct DIE to
 // represent this concrete inlined copy of the function.
 DIE *DwarfDebug::constructInlinedScopeDIE(CompileUnit *TheCU,
@@ -495,7 +481,7 @@
     return NULL;
   DIScope DS(Scope->getScopeNode());
   DISubprogram InlinedSP = getDISubprogram(DS);
-  DIE *OriginDIE = findSPDieInAllCUs(InlinedSP);
+  DIE *OriginDIE = TheCU->getDIE(InlinedSP);
   if (!OriginDIE) {
     DEBUG(dbgs() << "Unable to find original DIE for an inlined subprogram.");
     return NULL;
@@ -514,12 +500,8 @@
          "Invalid end label for an inlined scope!");
 
   DIE *ScopeDIE = new DIE(dwarf::DW_TAG_inlined_subroutine);
-  bool InSameCU = OriginDIE->getCompileUnit() == TheCU->getCUDie();
   TheCU->addDIEEntry(ScopeDIE, dwarf::DW_AT_abstract_origin,
-                     InSameCU ? dwarf::DW_FORM_ref4 : dwarf::DW_FORM_ref_addr,
-                     OriginDIE);
-  if (!InSameCU)
-    UseRefAddr = true;
+                     dwarf::DW_FORM_ref4, OriginDIE);
 
   if (Ranges.size() > 1) {
     // .debug_range section has not been laid out yet. Emit offset in
@@ -576,12 +558,9 @@
 
   DIScope DS(Scope->getScopeNode());
   // Early return to avoid creating dangling variable|scope DIEs.
-  DIE *AbstractSPDie = 0;
-  if (!Scope->getInlinedAt() && DS.isSubprogram() && Scope->isAbstractScope()) {
-    AbstractSPDie = findSPDieInAllCUs(DS);
-    if (!AbstractSPDie)
-      return NULL;
-  }
+  if (!Scope->getInlinedAt() && DS.isSubprogram() && Scope->isAbstractScope() &&
+      !TheCU->getDIE(DS))
+    return NULL;
 
   SmallVector<DIE *, 8> Children;
   DIE *ObjectPointer = NULL;
@@ -614,7 +593,7 @@
   else if (DS.isSubprogram()) {
     ProcessedSPNodes.insert(DS);
     if (Scope->isAbstractScope()) {
-      ScopeDIE = AbstractSPDie;
+      ScopeDIE = TheCU->getDIE(DS);
       // Note down abstract DIE.
       if (ScopeDIE)
         AbstractSPDies.insert(std::make_pair(DS, ScopeDIE));
@@ -1704,9 +1683,7 @@
       }
     }
     if (ProcessedSPNodes.count(AScope->getScopeNode()) == 0)
-      // Use the compile unit for the abstract scope to create scope DIEs and
-      // variable DIEs.
-      constructScopeDIE(SPMap.lookup(AScope->getScopeNode()), AScope);
+      constructScopeDIE(TheCU, AScope);
   }
 
   DIE *CurFnDIE = constructScopeDIE(TheCU, FnScope);
@@ -1996,8 +1973,7 @@
     Asm->OutStreamer.AddComment("Length of Compilation Unit Info");
     Asm->EmitInt32(ContentSize);
     Asm->OutStreamer.AddComment("DWARF version number");
-    Asm->EmitInt16((DD->getUseRefAddr() && dwarf::DWARF_VERSION < 3) ?
-                   3 : dwarf::DWARF_VERSION);
+    Asm->EmitInt16(dwarf::DWARF_VERSION);
     Asm->OutStreamer.AddComment("Offset Into Abbrev. Section");
     Asm->EmitSectionOffset(Asm->GetTempSymbol(ASection->getLabelBeginName()),
                            ASectionSym);
@@ -2238,8 +2214,7 @@
     Asm->OutStreamer.EmitLabel(Asm->GetTempSymbol("pubnames_begin", ID));
 
     Asm->OutStreamer.AddComment("DWARF Version");
-    Asm->EmitInt16((UseRefAddr && dwarf::DWARF_VERSION < 3) ?
-                   3 : dwarf::DWARF_VERSION);
+    Asm->EmitInt16(dwarf::DWARF_VERSION);
 
     Asm->OutStreamer.AddComment("Offset of Compilation Unit Info");
     Asm->EmitSectionOffset(Asm->GetTempSymbol(ISec->getLabelBeginName(), ID),
@@ -2286,8 +2261,7 @@
                                                   TheCU->getUniqueID()));
 
     if (Asm->isVerbose()) Asm->OutStreamer.AddComment("DWARF Version");
-    Asm->EmitInt16((UseRefAddr && dwarf::DWARF_VERSION < 3) ?
-                   3 : dwarf::DWARF_VERSION);
+    Asm->EmitInt16(dwarf::DWARF_VERSION);
 
     Asm->OutStreamer.AddComment("Offset of Compilation Unit Info");
     const MCSection *ISec = Asm->getObjFileLowering().getDwarfInfoSection();
@@ -2570,8 +2544,7 @@
   Asm->OutStreamer.EmitLabel(Asm->GetTempSymbol("debug_inlined_begin", 1));
 
   Asm->OutStreamer.AddComment("Dwarf Version");
-  Asm->EmitInt16((UseRefAddr && dwarf::DWARF_VERSION < 3) ?
-                 3 : dwarf::DWARF_VERSION);
+  Asm->EmitInt16(dwarf::DWARF_VERSION);
   Asm->OutStreamer.AddComment("Address Size (in bytes)");
   Asm->EmitInt8(Asm->getDataLayout().getPointerSize());