[DebugInfo/DWARF] [2/4] Type units no longer in a std::deque. NFC

This is patch 2 of 4 NFC refactorings to handle type units and compile
units more consistently and with less concern about the object-file
section that they came from.

Patch 2 takes the existing std::deque<DWARFUnitSection> for type units
and makes it a simple DWARFUnitSection, simplifying the handling of
type units and making it more consistent with compile units.

Differential Revision: https://reviews.llvm.org/D49742

llvm-svn: 338629
diff --git a/llvm/lib/DebugInfo/DWARF/DWARFContext.cpp b/llvm/lib/DebugInfo/DWARF/DWARFContext.cpp
index a26ebba0..79e463d 100644
--- a/llvm/lib/DebugInfo/DWARF/DWARFContext.cpp
+++ b/llvm/lib/DebugInfo/DWARF/DWARFContext.cpp
@@ -100,14 +100,12 @@
 // sort them by their starting offsets and remove duplicates.
 static ContributionCollection
 collectContributionData(DWARFContext::cu_iterator_range CUs,
-                        DWARFContext::tu_section_iterator_range TUSs) {
+                        DWARFContext::tu_iterator_range TUs) {
   ContributionCollection Contributions;
   for (const auto &CU : CUs)
     Contributions.push_back(CU->getStringOffsetsTableContribution());
-  for (const auto &TUS : TUSs)
-    for (const auto &TU : TUS)
-      Contributions.push_back(TU->getStringOffsetsTableContribution());
-
+  for (const auto &TU : TUs)
+    Contributions.push_back(TU->getStringOffsetsTableContribution());
   // Sort the contributions so that any invalid ones are placed at
   // the start of the contributions vector. This way they are reported
   // first.
@@ -136,9 +134,9 @@
 static void dumpDWARFv5StringOffsetsSection(
     raw_ostream &OS, StringRef SectionName, const DWARFObject &Obj,
     const DWARFSection &StringOffsetsSection, StringRef StringSection,
-    DWARFContext::cu_iterator_range CUs,
-    DWARFContext::tu_section_iterator_range TUSs, bool LittleEndian) {
-  auto Contributions = collectContributionData(CUs, TUSs);
+    DWARFContext::cu_iterator_range CUs, DWARFContext::tu_iterator_range TUs,
+    bool LittleEndian) {
+  auto Contributions = collectContributionData(CUs, TUs);
   DWARFDataExtractor StrOffsetExt(Obj, StringOffsetsSection, LittleEndian, 0);
   DataExtractor StrData(StringSection, LittleEndian, 0);
   uint64_t SectionSize = StringOffsetsSection.Data.size();
@@ -215,18 +213,19 @@
 // a header containing size and version number. Alternatively, it may be a
 // monolithic series of string offsets, as generated by the pre-DWARF v5
 // implementation of split DWARF.
-static void dumpStringOffsetsSection(
-    raw_ostream &OS, StringRef SectionName, const DWARFObject &Obj,
-    const DWARFSection &StringOffsetsSection, StringRef StringSection,
-    DWARFContext::cu_iterator_range CUs,
-    DWARFContext::tu_section_iterator_range TUSs, bool LittleEndian,
-    unsigned MaxVersion) {
+static void dumpStringOffsetsSection(raw_ostream &OS, StringRef SectionName,
+                                     const DWARFObject &Obj,
+                                     const DWARFSection &StringOffsetsSection,
+                                     StringRef StringSection,
+                                     DWARFContext::cu_iterator_range CUs,
+                                     DWARFContext::tu_iterator_range TUs,
+                                     bool LittleEndian, unsigned MaxVersion) {
   // If we have at least one (compile or type) unit with DWARF v5 or greater,
   // we assume that the section is formatted like a DWARF v5 string offsets
   // section.
   if (MaxVersion >= 5)
     dumpDWARFv5StringOffsetsSection(OS, SectionName, Obj, StringOffsetsSection,
-                                    StringSection, CUs, TUSs, LittleEndian);
+                                    StringSection, CUs, TUs, LittleEndian);
   else {
     DataExtractor strOffsetExt(StringOffsetsSection.Data, LittleEndian, 0);
     uint32_t offset = 0;
@@ -356,23 +355,21 @@
   dumpDebugInfo(ExplicitDWO, ".debug_info.dwo", DObj->getInfoDWOSection(),
                 dwo_compile_units());
 
-  auto dumpDebugType = [&](const char *Name,
-                           tu_section_iterator_range TUSections) {
+  auto dumpDebugType = [&](const char *Name, tu_iterator_range TUs) {
     OS << '\n' << Name << " contents:\n";
     DumpOffset = DumpOffsets[DIDT_ID_DebugTypes];
-    for (const auto &TUS : TUSections)
-      for (const auto &TU : TUS)
-        if (DumpOffset)
-          TU->getDIEForOffset(*DumpOffset)
-              .dump(OS, 0, DumpOpts.noImplicitRecursion());
-        else
-          TU->dump(OS, DumpOpts);
+    for (const auto &TU : TUs)
+      if (DumpOffset)
+        TU->getDIEForOffset(*DumpOffset)
+            .dump(OS, 0, DumpOpts.noImplicitRecursion());
+      else
+        TU->dump(OS, DumpOpts);
   };
   if ((DumpType & DIDT_DebugTypes)) {
     if (Explicit || getNumTypeUnits())
-      dumpDebugType(".debug_types", type_unit_sections());
+      dumpDebugType(".debug_types", type_units());
     if (ExplicitDWO || getNumDWOTypeUnits())
-      dumpDebugType(".debug_types.dwo", dwo_type_unit_sections());
+      dumpDebugType(".debug_types.dwo", dwo_type_units());
   }
 
   if (shouldDump(Explicit, ".debug_loc", DIDT_ID_DebugLoc,
@@ -430,7 +427,7 @@
     DWARFDataExtractor LineData(*DObj, DObj->getLineSection(), isLittleEndian(),
                                 0);
     DWARFDebugLine::SectionParser Parser(LineData, *this, compile_units(),
-                                         type_unit_sections());
+                                         type_units());
     DumpLineSection(Parser, DumpOpts);
   }
 
@@ -439,7 +436,7 @@
     DWARFDataExtractor LineData(*DObj, DObj->getLineDWOSection(),
                                 isLittleEndian(), 0);
     DWARFDebugLine::SectionParser Parser(LineData, *this, dwo_compile_units(),
-                                         dwo_type_unit_sections());
+                                         dwo_type_units());
     DumpLineSection(Parser, DumpOpts);
   }
 
@@ -547,16 +544,16 @@
 
   if (shouldDump(Explicit, ".debug_str_offsets", DIDT_ID_DebugStrOffsets,
                  DObj->getStringOffsetSection().Data))
-    dumpStringOffsetsSection(
-        OS, "debug_str_offsets", *DObj, DObj->getStringOffsetSection(),
-        DObj->getStringSection(), compile_units(), type_unit_sections(),
-        isLittleEndian(), getMaxVersion());
+    dumpStringOffsetsSection(OS, "debug_str_offsets", *DObj,
+                             DObj->getStringOffsetSection(),
+                             DObj->getStringSection(), compile_units(),
+                             type_units(), isLittleEndian(), getMaxVersion());
   if (shouldDump(ExplicitDWO, ".debug_str_offsets.dwo", DIDT_ID_DebugStrOffsets,
                  DObj->getStringOffsetDWOSection().Data))
     dumpStringOffsetsSection(
         OS, "debug_str_offsets.dwo", *DObj, DObj->getStringOffsetDWOSection(),
-        DObj->getStringDWOSection(), dwo_compile_units(),
-        dwo_type_unit_sections(), isLittleEndian(), getMaxVersion());
+        DObj->getStringDWOSection(), dwo_compile_units(), dwo_type_units(),
+        isLittleEndian(), getMaxVersion());
 
   if (shouldDump(Explicit, ".gnu_index", DIDT_ID_GdbIndex,
                  DObj->getGdbIndexSection())) {
@@ -584,7 +581,9 @@
 }
 
 DWARFCompileUnit *DWARFContext::getDWOCompileUnitForHash(uint64_t Hash) {
-  DWOCUs.parseDWO(*this, DObj->getInfoDWOSection(), DW_SECT_INFO, true);
+  if (DWOCUs.empty())
+    DWOCUs.addUnitsForDWOSection(*this, DObj->getInfoDWOSection(), DW_SECT_INFO,
+                                 true);
 
   if (const auto &CUI = getCUIndex()) {
     if (const auto *R = CUI.getFromHash(Hash))
@@ -844,28 +843,30 @@
 }
 
 void DWARFContext::parseCompileUnits() {
-  CUs.parse(*this, DObj->getInfoSection(), DW_SECT_INFO);
+  if (!CUs.empty())
+    return;
+  CUs.addUnitsForSection(*this, DObj->getInfoSection(), DW_SECT_INFO);
 }
 
 void DWARFContext::parseTypeUnits() {
   if (!TUs.empty())
     return;
   DObj->forEachTypesSections([&](const DWARFSection &S) {
-    TUs.emplace_back();
-    TUs.back().parse(*this, S, DW_SECT_TYPES);
+    TUs.addUnitsForSection(*this, S, DW_SECT_TYPES);
   });
 }
 
 void DWARFContext::parseDWOCompileUnits() {
-  DWOCUs.parseDWO(*this, DObj->getInfoDWOSection(), DW_SECT_INFO);
+  if (!DWOCUs.empty())
+    return;
+  DWOCUs.addUnitsForDWOSection(*this, DObj->getInfoDWOSection(), DW_SECT_INFO);
 }
 
 void DWARFContext::parseDWOTypeUnits() {
   if (!DWOTUs.empty())
     return;
   DObj->forEachTypesDWOSections([&](const DWARFSection &S) {
-    DWOTUs.emplace_back();
-    DWOTUs.back().parseDWO(*this, S, DW_SECT_TYPES);
+    DWOTUs.addUnitsForDWOSection(*this, S, DW_SECT_TYPES);
   });
 }