Pull some code out into functions to make rearranging them a bit easier.
authorEric Christopher <echristo@gmail.com>
Thu, 22 Nov 2012 00:59:49 +0000 (00:59 +0000)
committerEric Christopher <echristo@gmail.com>
Thu, 22 Nov 2012 00:59:49 +0000 (00:59 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@168481 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/AsmPrinter/DwarfDebug.cpp
lib/CodeGen/AsmPrinter/DwarfDebug.h

index 03ad0bf039e1095e2a7cf7aa31cd1e3dc479db7d..1240fc4384b725b8a2b5e30cf32c29c37e22c42e 100644 (file)
@@ -797,71 +797,83 @@ void DwarfDebug::beginModule() {
   SectionMap.insert(Asm->getObjFileLowering().getTextSection());
 }
 
-/// endModule - Emit all Dwarf sections that should come after the content.
-///
-void DwarfDebug::endModule() {
-
-  if (!FirstCU) return;
+// Attach DW_AT_inline attribute with inlined subprogram DIEs.
+void DwarfDebug::computeInlinedDIEs() {
+  // Attach DW_AT_inline attribute with inlined subprogram DIEs.
+  for (SmallPtrSet<DIE *, 4>::iterator AI = InlinedSubprogramDIEs.begin(),
+        AE = InlinedSubprogramDIEs.end(); AI != AE; ++AI) {
+    DIE *ISP = *AI;
+    FirstCU->addUInt(ISP, dwarf::DW_AT_inline, 0, dwarf::DW_INL_inlined);
+  }
+  for (DenseMap<const MDNode *, DIE *>::iterator AI = AbstractSPDies.begin(),
+        AE = AbstractSPDies.end(); AI != AE; ++AI) {
+    DIE *ISP = AI->second;
+    if (InlinedSubprogramDIEs.count(ISP))
+      continue;
+    FirstCU->addUInt(ISP, dwarf::DW_AT_inline, 0, dwarf::DW_INL_inlined);
+  }
+}
 
+// Collect info for variables that were optimized out.
+void DwarfDebug::collectDeadVariables() {
   const Module *M = MMI->getModule();
   DenseMap<const MDNode *, LexicalScope *> DeadFnScopeMap;
 
-  // Collect info for variables that were optimized out.
   if (NamedMDNode *CU_Nodes = M->getNamedMetadata("llvm.dbg.cu")) {
     for (unsigned i = 0, e = CU_Nodes->getNumOperands(); i != e; ++i) {
       DICompileUnit TheCU(CU_Nodes->getOperand(i));
       DIArray Subprograms = TheCU.getSubprograms();
       for (unsigned i = 0, e = Subprograms.getNumElements(); i != e; ++i) {
-        DISubprogram SP(Subprograms.getElement(i));
-        if (ProcessedSPNodes.count(SP) != 0) continue;
-        if (!SP.Verify()) continue;
-        if (!SP.isDefinition()) continue;
-        DIArray Variables = SP.getVariables();
-        if (Variables.getNumElements() == 0) continue;
-
-        LexicalScope *Scope =
-          new LexicalScope(NULL, DIDescriptor(SP), NULL, false);
-        DeadFnScopeMap[SP] = Scope;
-
-        // Construct subprogram DIE and add variables DIEs.
-        CompileUnit *SPCU = CUMap.lookup(TheCU);
-        assert(SPCU && "Unable to find Compile Unit!");
-        constructSubprogramDIE(SPCU, SP);
-        DIE *ScopeDIE = SPCU->getDIE(SP);
-        for (unsigned vi = 0, ve = Variables.getNumElements(); vi != ve; ++vi) {
-          DIVariable DV(Variables.getElement(vi));
-          if (!DV.Verify()) continue;
-          DbgVariable *NewVar = new DbgVariable(DV, NULL);
-          if (DIE *VariableDIE =
-              SPCU->constructVariableDIE(NewVar, Scope->isAbstractScope()))
-            ScopeDIE->addChild(VariableDIE);
-        }
+       DISubprogram SP(Subprograms.getElement(i));
+       if (ProcessedSPNodes.count(SP) != 0) continue;
+       if (!SP.Verify()) continue;
+       if (!SP.isDefinition()) continue;
+       DIArray Variables = SP.getVariables();
+       if (Variables.getNumElements() == 0) continue;
+
+       LexicalScope *Scope =
+         new LexicalScope(NULL, DIDescriptor(SP), NULL, false);
+       DeadFnScopeMap[SP] = Scope;
+
+       // Construct subprogram DIE and add variables DIEs.
+       CompileUnit *SPCU = CUMap.lookup(TheCU);
+       assert(SPCU && "Unable to find Compile Unit!");
+       constructSubprogramDIE(SPCU, SP);
+       DIE *ScopeDIE = SPCU->getDIE(SP);
+       for (unsigned vi = 0, ve = Variables.getNumElements(); vi != ve; ++vi) {
+         DIVariable DV(Variables.getElement(vi));
+         if (!DV.Verify()) continue;
+         DbgVariable *NewVar = new DbgVariable(DV, NULL);
+         if (DIE *VariableDIE =
+             SPCU->constructVariableDIE(NewVar, Scope->isAbstractScope()))
+           ScopeDIE->addChild(VariableDIE);
+       }
       }
     }
   }
+  DeleteContainerSeconds(DeadFnScopeMap);
+}
+
+void DwarfDebug::finalizeModuleInfo() {
+  // Collect info for variables that were optimized out.
+  collectDeadVariables();
 
   // Attach DW_AT_inline attribute with inlined subprogram DIEs.
-  for (SmallPtrSet<DIE *, 4>::iterator AI = InlinedSubprogramDIEs.begin(),
-         AE = InlinedSubprogramDIEs.end(); AI != AE; ++AI) {
-    DIE *ISP = *AI;
-    FirstCU->addUInt(ISP, dwarf::DW_AT_inline, 0, dwarf::DW_INL_inlined);
-  }
-  for (DenseMap<const MDNode *, DIE *>::iterator AI = AbstractSPDies.begin(),
-         AE = AbstractSPDies.end(); AI != AE; ++AI) {
-    DIE *ISP = AI->second;
-    if (InlinedSubprogramDIEs.count(ISP))
-      continue;
-    FirstCU->addUInt(ISP, dwarf::DW_AT_inline, 0, dwarf::DW_INL_inlined);
-  }
+  computeInlinedDIEs();
 
   // Emit DW_AT_containing_type attribute to connect types with their
   // vtable holding type.
   for (DenseMap<const MDNode *, CompileUnit *>::iterator CUI = CUMap.begin(),
-         CUE = CUMap.end(); CUI != CUE; ++CUI) {
+        CUE = CUMap.end(); CUI != CUE; ++CUI) {
     CompileUnit *TheCU = CUI->second;
     TheCU->constructContainingTypeDIEs();
   }
 
+   // Compute DIE offsets and sizes.
+  computeSizeAndOffsets();
+}
+
+void DwarfDebug::endSections() {
   // Standard sections final addresses.
   Asm->OutStreamer.SwitchSection(Asm->getObjFileLowering().getTextSection());
   Asm->OutStreamer.EmitLabel(Asm->GetTempSymbol("text_end"));
@@ -873,9 +885,20 @@ void DwarfDebug::endModule() {
     Asm->OutStreamer.SwitchSection(SectionMap[I]);
     Asm->OutStreamer.EmitLabel(Asm->GetTempSymbol("section_end", I+1));
   }
+}
 
-  // Compute DIE offsets and sizes.
-  computeSizeAndOffsets();
+/// endModule - Emit all Dwarf sections that should come after the content.
+///
+void DwarfDebug::endModule() {
+
+  if (!FirstCU) return;
+
+  // End any existing sections.
+  // TODO: Does this need to happen?
+  endSections();
+
+  // Finalize the debug info for the module.
+  finalizeModuleInfo();
 
   // Emit initial sections.
   emitSectionLabels();
@@ -923,7 +946,6 @@ void DwarfDebug::endModule() {
   emitDebugStr();
 
   // clean up.
-  DeleteContainerSeconds(DeadFnScopeMap);
   SPMap.clear();
   for (DenseMap<const MDNode *, CompileUnit *>::iterator I = CUMap.begin(),
          E = CUMap.end(); I != E; ++I)
index d51dfc4b641e28d399cae1f1e0942d452800e429..cf4be75b123f0891581ff2daee613fdebf1f0af8 100644 (file)
@@ -367,6 +367,21 @@ private:
   ///
   void computeSizeAndOffsets();
 
+  /// computeInlinedDIEs - Attach DW_AT_inline attribute with inlined
+  /// subprogram DIEs.
+  void computeInlinedDIEs();
+
+  /// collectDeadVariables - Collect info for variables that were optimized out.
+  void collectDeadVariables();
+
+  /// finalizeModuleInfo - Finish off debug information after all functions
+  /// have been processed.
+  void finalizeModuleInfo();
+
+  /// endSections - Emit labels to close any remaining sections that have
+  /// been left open.
+  void endSections();
+
   /// EmitDebugInfo - Emit the debug info section.
   ///
   void emitDebugInfo();