diff --git a/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp b/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp index fb4d66cde10b3c7746e53377594cf323bc059d4c..902b152c8e7496470befb7a75c8ff426c8963ed5 100644 --- a/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp +++ b/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp @@ -2077,10 +2077,12 @@ DbgVariable *DwarfDebug::findAbstractVariable(DIVariable &Var, return AbsDbgVariable; } -/// collectVariableInfo - Populate DbgScope entries with variables' info. -void DwarfDebug::collectVariableInfo(const MachineFunction *MF) { +/// collectVariableInfoFromMMITable - Collect variable information from +/// side table maintained by MMI. +void +DwarfDebug::collectVariableInfoFromMMITable(const MachineFunction * MF, + SmallPtrSet &Processed) { const LLVMContext &Ctx = Asm->MF->getFunction()->getContext(); - SmallPtrSet Processed; MachineModuleInfo::VariableDbgInfoMapTy &VMap = MMI->getVariableDbgInfo(); for (MachineModuleInfo::VariableDbgInfoMapTy::iterator VI = VMap.begin(), VE = VMap.end(); VI != VE; ++VI) { @@ -2109,10 +2111,19 @@ void DwarfDebug::collectVariableInfo(const MachineFunction *MF) { VarToAbstractVarMap[RegVar] = AbsDbgVariable; } } +} + +/// collectVariableInfo - Populate DbgScope entries with variables' info. +void DwarfDebug::collectVariableInfo(const MachineFunction *MF) { + SmallPtrSet Processed; + + /// collection info from MMI table. + collectVariableInfoFromMMITable(MF, Processed); + SmallVector DbgValues; // Collect variable information from DBG_VALUE machine instructions; for (MachineFunction::const_iterator I = Asm->MF->begin(), E = Asm->MF->end(); - I != E; ++I) { + I != E; ++I) for (MachineBasicBlock::const_iterator II = I->begin(), IE = I->end(); II != IE; ++II) { const MachineInstr *MInsn = II; @@ -2123,41 +2134,41 @@ void DwarfDebug::collectVariableInfo(const MachineFunction *MF) { if (MInsn->getOperand(0).isReg() && !MInsn->getOperand(0).getReg()) continue; - DIVariable DV( - const_cast(MInsn->getOperand(MInsn->getNumOperands() - 1) - .getMetadata())); - if (DV.getTag() == dwarf::DW_TAG_arg_variable) { - // FIXME Handle inlined subroutine arguments. - DbgVariable *ArgVar = new DbgVariable(DV); - CurrentFnDbgScope->addVariable(ArgVar); - DbgValueStartMap[MInsn] = ArgVar; - DbgVariableToDbgInstMap[ArgVar] = MInsn; - Processed.insert(DV); - continue; - } + DbgValues.push_back(MInsn); + } - DebugLoc DL = MInsn->getDebugLoc(); - if (DL.isUnknown()) continue; - DbgScope *Scope = 0; - if (const MDNode *IA = DL.getInlinedAt(Ctx)) - Scope = ConcreteScopes.lookup(IA); - if (Scope == 0) - Scope = DbgScopeMap.lookup(DL.getScope(Ctx)); - - // If variable scope is not found then skip this variable. - if (Scope == 0) - continue; + for(SmallVector::iterator I = DbgValues.begin(), + E = DbgValues.end(); I != E; ++I) { + const MachineInstr *MInsn = *I; + + DIVariable DV(MInsn->getOperand(MInsn->getNumOperands() - 1).getMetadata()); + if (Processed.count(DV) != 0) + continue; + if (DV.getTag() == dwarf::DW_TAG_arg_variable) { + // FIXME Handle inlined subroutine arguments. + DbgVariable *ArgVar = new DbgVariable(DV); + CurrentFnDbgScope->addVariable(ArgVar); + DbgValueStartMap[MInsn] = ArgVar; + DbgVariableToDbgInstMap[ArgVar] = MInsn; Processed.insert(DV); - DbgVariable *AbsDbgVariable = findAbstractVariable(DV, DL); - DbgVariable *RegVar = new DbgVariable(DV); - DbgValueStartMap[MInsn] = RegVar; - DbgVariableToDbgInstMap[RegVar] = MInsn; - Scope->addVariable(RegVar); - if (AbsDbgVariable) { - DbgVariableToDbgInstMap[AbsDbgVariable] = MInsn; - VarToAbstractVarMap[RegVar] = AbsDbgVariable; - } + continue; + } + + DbgScope *Scope = findDbgScope(MInsn); + // If variable scope is not found then skip this variable. + if (Scope == 0) + continue; + + Processed.insert(DV); + DbgVariable *AbsDbgVariable = findAbstractVariable(DV, MInsn->getDebugLoc()); + DbgVariable *RegVar = new DbgVariable(DV); + DbgValueStartMap[MInsn] = RegVar; + DbgVariableToDbgInstMap[RegVar] = MInsn; + Scope->addVariable(RegVar); + if (AbsDbgVariable) { + DbgVariableToDbgInstMap[AbsDbgVariable] = MInsn; + VarToAbstractVarMap[RegVar] = AbsDbgVariable; } } @@ -2166,7 +2177,7 @@ void DwarfDebug::collectVariableInfo(const MachineFunction *MF) { MF->getFunction()->getParent()->getNamedMetadata("llvm.dbg.lv")) { for (unsigned i = 0, e = NMD->getNumOperands(); i != e; ++i) { DIVariable DV(cast_or_null(NMD->getOperand(i))); - if (!Processed.insert(DV)) + if (!DV || !Processed.insert(DV)) continue; DbgScope *Scope = DbgScopeMap.lookup(DV.getContext()); if (Scope) @@ -2639,6 +2650,26 @@ const MCSymbol *DwarfDebug::findVariableLabel(const DbgVariable *V) { else return I->second; } +/// findDbgScope - Find DbgScope for the debug loc attached with an +/// instruction. +DbgScope *DwarfDebug::findDbgScope(const MachineInstr *MInsn) { + DbgScope *Scope = NULL; + LLVMContext &Ctx = + MInsn->getParent()->getParent()->getFunction()->getContext(); + DebugLoc DL = MInsn->getDebugLoc(); + + if (DL.isUnknown()) + return Scope; + + if (const MDNode *IA = DL.getInlinedAt(Ctx)) + Scope = ConcreteScopes.lookup(IA); + if (Scope == 0) + Scope = DbgScopeMap.lookup(DL.getScope(Ctx)); + + return Scope; +} + + /// recordSourceLine - Register a source line with debug info. Returns the /// unique label that was emitted and which provides correspondence to /// the source line list. diff --git a/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.h b/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.h index 82a6cdbb3796fc5ead45fa0d434ce182d068921b..6728199c5eb94f60095168eea789c06b05e930bf 100644 --- a/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.h +++ b/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.h @@ -558,6 +558,10 @@ private: /// findVariableLabel - Find MCSymbol for the variable. const MCSymbol *findVariableLabel(const DbgVariable *V); + /// findDbgScope - Find DbgScope for the debug loc attached with an + /// instruction. + DbgScope *findDbgScope(const MachineInstr *MI); + /// identifyScopeMarkers() - Indentify instructions that are marking /// beginning of or end of a scope. void identifyScopeMarkers(); @@ -569,6 +573,10 @@ private: /// collectVariableInfo - Populate DbgScope entries with variables' info. void collectVariableInfo(const MachineFunction *); + /// collectVariableInfoFromMMITable - Collect variable information from + /// side table maintained by MMI. + void collectVariableInfoFromMMITable(const MachineFunction * MF, + SmallPtrSet &P); public: //===--------------------------------------------------------------------===// // Main entry points.