Pull some code out into functions to make rearranging them a bit easier.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@168481 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Eric Christopher
2012-11-22 00:59:49 +00:00
parent 72a2c0622a
commit 4117bec41b
2 changed files with 86 additions and 49 deletions

View File

@@ -797,16 +797,28 @@ void DwarfDebug::beginModule() {
SectionMap.insert(Asm->getObjFileLowering().getTextSection()); SectionMap.insert(Asm->getObjFileLowering().getTextSection());
} }
/// endModule - Emit all Dwarf sections that should come after the content. // Attach DW_AT_inline attribute with inlined subprogram DIEs.
/// void DwarfDebug::computeInlinedDIEs() {
void DwarfDebug::endModule() { // Attach DW_AT_inline attribute with inlined subprogram DIEs.
for (SmallPtrSet<DIE *, 4>::iterator AI = InlinedSubprogramDIEs.begin(),
if (!FirstCU) return; 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(); const Module *M = MMI->getModule();
DenseMap<const MDNode *, LexicalScope *> DeadFnScopeMap; DenseMap<const MDNode *, LexicalScope *> DeadFnScopeMap;
// Collect info for variables that were optimized out.
if (NamedMDNode *CU_Nodes = M->getNamedMetadata("llvm.dbg.cu")) { if (NamedMDNode *CU_Nodes = M->getNamedMetadata("llvm.dbg.cu")) {
for (unsigned i = 0, e = CU_Nodes->getNumOperands(); i != e; ++i) { for (unsigned i = 0, e = CU_Nodes->getNumOperands(); i != e; ++i) {
DICompileUnit TheCU(CU_Nodes->getOperand(i)); DICompileUnit TheCU(CU_Nodes->getOperand(i));
@@ -839,20 +851,15 @@ void DwarfDebug::endModule() {
} }
} }
} }
DeleteContainerSeconds(DeadFnScopeMap);
}
void DwarfDebug::finalizeModuleInfo() {
// Collect info for variables that were optimized out.
collectDeadVariables();
// Attach DW_AT_inline attribute with inlined subprogram DIEs. // Attach DW_AT_inline attribute with inlined subprogram DIEs.
for (SmallPtrSet<DIE *, 4>::iterator AI = InlinedSubprogramDIEs.begin(), computeInlinedDIEs();
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);
}
// Emit DW_AT_containing_type attribute to connect types with their // Emit DW_AT_containing_type attribute to connect types with their
// vtable holding type. // vtable holding type.
@@ -862,6 +869,11 @@ void DwarfDebug::endModule() {
TheCU->constructContainingTypeDIEs(); TheCU->constructContainingTypeDIEs();
} }
// Compute DIE offsets and sizes.
computeSizeAndOffsets();
}
void DwarfDebug::endSections() {
// Standard sections final addresses. // Standard sections final addresses.
Asm->OutStreamer.SwitchSection(Asm->getObjFileLowering().getTextSection()); Asm->OutStreamer.SwitchSection(Asm->getObjFileLowering().getTextSection());
Asm->OutStreamer.EmitLabel(Asm->GetTempSymbol("text_end")); Asm->OutStreamer.EmitLabel(Asm->GetTempSymbol("text_end"));
@@ -873,9 +885,20 @@ void DwarfDebug::endModule() {
Asm->OutStreamer.SwitchSection(SectionMap[I]); Asm->OutStreamer.SwitchSection(SectionMap[I]);
Asm->OutStreamer.EmitLabel(Asm->GetTempSymbol("section_end", I+1)); Asm->OutStreamer.EmitLabel(Asm->GetTempSymbol("section_end", I+1));
} }
}
// Compute DIE offsets and sizes. /// endModule - Emit all Dwarf sections that should come after the content.
computeSizeAndOffsets(); ///
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. // Emit initial sections.
emitSectionLabels(); emitSectionLabels();
@@ -923,7 +946,6 @@ void DwarfDebug::endModule() {
emitDebugStr(); emitDebugStr();
// clean up. // clean up.
DeleteContainerSeconds(DeadFnScopeMap);
SPMap.clear(); SPMap.clear();
for (DenseMap<const MDNode *, CompileUnit *>::iterator I = CUMap.begin(), for (DenseMap<const MDNode *, CompileUnit *>::iterator I = CUMap.begin(),
E = CUMap.end(); I != E; ++I) E = CUMap.end(); I != E; ++I)

View File

@@ -367,6 +367,21 @@ private:
/// ///
void computeSizeAndOffsets(); 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. /// EmitDebugInfo - Emit the debug info section.
/// ///
void emitDebugInfo(); void emitDebugInfo();