If the front end has emitted llvm.dbg.cu and other debug info anchors (clang does it now) then use them directly. This saves one scan of entire module, to collect debug info, which in turns saves few machine cycles at compile time.

llvm-svn: 130759
This commit is contained in:
Devang Patel 2011-05-03 16:45:22 +00:00
parent 5066858bcd
commit e02e58528a
1 changed files with 49 additions and 27 deletions

View File

@ -1113,44 +1113,66 @@ void DwarfDebug::beginModule(Module *M) {
if (DisableDebugInfoPrinting) if (DisableDebugInfoPrinting)
return; return;
DebugInfoFinder DbgFinder;
DbgFinder.processModule(*M);
bool HasDebugInfo = false; bool HasDebugInfo = false;
// Scan all the compile-units to see if there are any marked as the main unit. // If module has named metadata anchors then use them, otherwise scan the module
// if not, we do not generate debug info. // using debug info finder to collect debug info.
for (DebugInfoFinder::iterator I = DbgFinder.compile_unit_begin(), NamedMDNode *CU_Nodes = M->getNamedMetadata("llvm.dbg.cu");
E = DbgFinder.compile_unit_end(); I != E; ++I) { if (CU_Nodes) {
if (DICompileUnit(*I).isMain()) { for (unsigned i = 0, e = CU_Nodes->getNumOperands(); i != e; ++i) {
HasDebugInfo = true; HasDebugInfo = true;
break; constructCompileUnit(CU_Nodes->getOperand(i));
} }
if (!HasDebugInfo)
return;
if (NamedMDNode *NMD = M->getNamedMetadata("llvm.dbg.gv"))
for (unsigned i = 0, e = NMD->getNumOperands(); i != e; ++i)
constructGlobalVariableDIE(NMD->getOperand(i));
if (NamedMDNode *NMD = M->getNamedMetadata("llvm.dbg.sp"))
for (unsigned i = 0, e = NMD->getNumOperands(); i != e; ++i)
constructSubprogramDIE(NMD->getOperand(i));
} else {
DebugInfoFinder DbgFinder;
DbgFinder.processModule(*M);
// Scan all the compile-units to see if there are any marked as the main unit.
// if not, we do not generate debug info.
for (DebugInfoFinder::iterator I = DbgFinder.compile_unit_begin(),
E = DbgFinder.compile_unit_end(); I != E; ++I) {
if (DICompileUnit(*I).isMain()) {
HasDebugInfo = true;
break;
}
}
// Create all the compile unit DIEs.
for (DebugInfoFinder::iterator I = DbgFinder.compile_unit_begin(),
E = DbgFinder.compile_unit_end(); I != E; ++I)
constructCompileUnit(*I);
// Create DIEs for each global variable.
for (DebugInfoFinder::iterator I = DbgFinder.global_variable_begin(),
E = DbgFinder.global_variable_end(); I != E; ++I)
constructGlobalVariableDIE(*I);
// Create DIEs for each subprogram.
for (DebugInfoFinder::iterator I = DbgFinder.subprogram_begin(),
E = DbgFinder.subprogram_end(); I != E; ++I)
constructSubprogramDIE(*I);
} }
if (!HasDebugInfo) return; if (!HasDebugInfo) return;
// Tell MMI that we have debug info. // Tell MMI that we have debug info.
MMI->setDebugInfoAvailability(true); MMI->setDebugInfoAvailability(true);
// Emit initial sections. // Emit initial sections.
EmitSectionLabels(); EmitSectionLabels();
// Create all the compile unit DIEs.
for (DebugInfoFinder::iterator I = DbgFinder.compile_unit_begin(),
E = DbgFinder.compile_unit_end(); I != E; ++I)
constructCompileUnit(*I);
// Create DIEs for each global variable.
for (DebugInfoFinder::iterator I = DbgFinder.global_variable_begin(),
E = DbgFinder.global_variable_end(); I != E; ++I)
constructGlobalVariableDIE(*I);
// Create DIEs for each subprogram.
for (DebugInfoFinder::iterator I = DbgFinder.subprogram_begin(),
E = DbgFinder.subprogram_end(); I != E; ++I)
constructSubprogramDIE(*I);
//getOrCreateTypeDIE //getOrCreateTypeDIE
if (NamedMDNode *NMD = M->getNamedMetadata("llvm.dbg.enum")) if (NamedMDNode *NMD = M->getNamedMetadata("llvm.dbg.enum"))
for (unsigned i = 0, e = NMD->getNumOperands(); i != e; ++i) { for (unsigned i = 0, e = NMD->getNumOperands(); i != e; ++i) {