[llvm-commits] [llvm] r103798 - in /llvm/trunk: include/llvm/Analysis/DebugInfo.h lib/Analysis/DebugInfo.cpp lib/CodeGen/AsmPrinter/DwarfDebug.cpp lib/CodeGen/AsmPrinter/DwarfDebug.h

Devang Patel dpatel at apple.com
Fri May 14 14:19:19 PDT 2010


On May 14, 2010, at 2:15 PM, Evan Cheng wrote:

> Hi Devang,
> 
> Would it be better if the caller of CreateVariable() create the llvm.dbg.lv metadata instead? This solution seems to polluting the interface. 

Technically caller of CreateVariable(), the front end, does not know how variables' debug info is encoded in llvm IR. DebugInfo interface is responsible to encapsulate this detail.

-
Devang

> 
> Evan
> 
> On May 14, 2010, at 2:01 PM, Devang Patel wrote:
> 
>> 
>> Modified: llvm/trunk/lib/Analysis/DebugInfo.cpp
>> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/DebugInfo.cpp?rev=103798&r1=103797&r2=103798&view=diff
>> ==============================================================================
>> --- llvm/trunk/lib/Analysis/DebugInfo.cpp (original)
>> +++ llvm/trunk/lib/Analysis/DebugInfo.cpp Fri May 14 16:01:35 2010
>> @@ -1028,7 +1028,7 @@
>>                                     StringRef Name,
>>                                     DIFile F,
>>                                     unsigned LineNo,
>> -                                     DIType Ty) {
>> +                                     DIType Ty, bool OptimizedBuild) {
>>  Value *Elts[] = {
>>    GetTagConstant(Tag),
>>    Context,
>> @@ -1037,7 +1037,12 @@
>>    ConstantInt::get(Type::getInt32Ty(VMContext), LineNo),
>>    Ty,
>>  };
>> -  return DIVariable(MDNode::get(VMContext, &Elts[0], 6));
>> +  MDNode *Node = MDNode::get(VMContext, &Elts[0], 6);
>> +  if (OptimizedBuild) {
>> +    NamedMDNode *NMD = M.getOrInsertNamedMetadata("llvm.dbg.lv");
>> +    NMD->addOperand(Node);
>> +  }
>> +  return DIVariable(Node);
>> }
>> 
>> 
>> 
>> Modified: llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
>> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp?rev=103798&r1=103797&r2=103798&view=diff
>> ==============================================================================
>> --- llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp (original)
>> +++ llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp Fri May 14 16:01:35 2010
>> @@ -193,6 +193,9 @@
>>  DbgVariable *getAbstractVariable() const { return AbstractVar; }
>>  void setDIE(DIE *D)                      { TheDIE = D; }
>>  DIE *getDIE()                      const { return TheDIE; }
>> +  bool hasLocation()                       { 
>> +    return DbgValueMInsn || FrameIndex != ~0U; 
>> +  }
>> };
>> 
>> //===----------------------------------------------------------------------===//
>> @@ -1632,16 +1635,18 @@
>>      MachineLocation Location;
>>      unsigned FrameReg;
>>      const TargetRegisterInfo *RI = Asm->TM.getRegisterInfo();
>> -      int Offset = RI->getFrameIndexReference(*Asm->MF, DV->getFrameIndex(),
>> -                                              FrameReg);
>> -      Location.set(FrameReg, Offset);
>> -      
>> -      if (VD.hasComplexAddress())
>> -        addComplexAddress(DV, VariableDie, dwarf::DW_AT_location, Location);
>> -      else if (VD.isBlockByrefVariable())
>> -        addBlockByrefAddress(DV, VariableDie, dwarf::DW_AT_location, Location);
>> -      else
>> -        addAddress(VariableDie, dwarf::DW_AT_location, Location);
>> +      if (DV->hasLocation()) {
>> +        int Offset = RI->getFrameIndexReference(*Asm->MF, DV->getFrameIndex(),
>> +                                                FrameReg);
>> +        Location.set(FrameReg, Offset);
>> +        
>> +        if (VD.hasComplexAddress())
>> +          addComplexAddress(DV, VariableDie, dwarf::DW_AT_location, Location);
>> +        else if (VD.isBlockByrefVariable())
>> +          addBlockByrefAddress(DV, VariableDie, dwarf::DW_AT_location, Location);
>> +        else
>> +          addAddress(VariableDie, dwarf::DW_AT_location, Location);
>> +      }
>>    }
>>  }
>> 
>> @@ -2122,14 +2127,15 @@
>> }
>> 
>> /// collectVariableInfo - Populate DbgScope entries with variables' info.
>> -void DwarfDebug::collectVariableInfo() {
>> +void DwarfDebug::collectVariableInfo(const MachineFunction *MF) {
>>  const LLVMContext &Ctx = Asm->MF->getFunction()->getContext();
>> -
>> +  SmallPtrSet<const MDNode *, 16> Processed;
>>  MachineModuleInfo::VariableDbgInfoMapTy &VMap = MMI->getVariableDbgInfo();
>>  for (MachineModuleInfo::VariableDbgInfoMapTy::iterator VI = VMap.begin(),
>>         VE = VMap.end(); VI != VE; ++VI) {
>>    const MDNode *Var = VI->first;
>>    if (!Var) continue;
>> +    Processed.insert(Var);
>>    DIVariable DV(Var);
>>    const std::pair<unsigned, DebugLoc> &VP = VI->second;
>> 
>> @@ -2184,12 +2190,27 @@
>>      if (Scope == 0)
>>        continue;
>> 
>> +      Processed.insert(DV);
>>      DbgVariable *AbsDbgVariable = findAbstractVariable(DV, MInsn, DL);
>>      DbgVariable *RegVar = new DbgVariable(DV, MInsn, AbsDbgVariable);
>>      DbgValueStartMap[MInsn] = RegVar;
>>      Scope->addVariable(RegVar);
>>    }
>>  }
>> +
>> +  // Collect info for variables that were optimized out.
>> +  if (NamedMDNode *NMD = 
>> +      MF->getFunction()->getParent()->getNamedMetadata("llvm.dbg.lv")) {
>> +    for (unsigned i = 0, e = NMD->getNumOperands(); i != e; ++i) {
>> +      DIVariable DV(cast_or_null<MDNode>(NMD->getOperand(i)));
>> +      if (!Processed.insert(DV))
>> +        continue;
>> +      DbgScope *Scope = DbgScopeMap.lookup(DV.getContext());
>> +      if (Scope)
>> +        Scope->addVariable(new DbgVariable(DV, ~0U, NULL));
>> +    }
>> +  }
>> +
>> }
>> 
>> /// beginScope - Process beginning of a scope.
>> @@ -2542,7 +2563,7 @@
>>  if (!MMI->hasDebugInfo()) return;
>>  if (!extractScopeInformation()) return;
>> 
>> -  collectVariableInfo();
>> +  collectVariableInfo(MF);
>> 
>>  FunctionBeginSym = Asm->GetTempSymbol("func_begin",
>>                                        Asm->getFunctionNumber());
>> 
>> Modified: llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.h
>> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.h?rev=103798&r1=103797&r2=103798&view=diff
>> ==============================================================================
>> --- llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.h (original)
>> +++ llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.h Fri May 14 16:01:35 2010
>> @@ -545,7 +545,7 @@
>>  bool extractScopeInformation();
>> 
>>  /// collectVariableInfo - Populate DbgScope entries with variables' info.
>> -  void collectVariableInfo();
>> +  void collectVariableInfo(const MachineFunction *);
>> 
>> public:
>>  //===--------------------------------------------------------------------===//
>> 
>> 
>> _______________________________________________
>> llvm-commits mailing list
>> llvm-commits at cs.uiuc.edu
>> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
> 





More information about the llvm-commits mailing list