Extract scope information from the variable itself, instead of relying on alloca...
authorDevang Patel <dpatel@apple.com>
Fri, 9 Oct 2009 22:42:28 +0000 (22:42 +0000)
committerDevang Patel <dpatel@apple.com>
Fri, 9 Oct 2009 22:42:28 +0000 (22:42 +0000)
While recording beginning of a function, use scope info from the first location entry instead of just relying on first location entry itself.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@83684 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/CodeGen/MachineModuleInfo.h
lib/CodeGen/AsmPrinter/DwarfDebug.cpp
lib/CodeGen/AsmPrinter/DwarfDebug.h
lib/CodeGen/SelectionDAG/FastISel.cpp
lib/CodeGen/SelectionDAG/SelectionDAGBuild.cpp

index b7b90198b1681c004e78eb2c00b4693d2e1ee6f3..3544074d1f16d9ad5d12501d514165f0845bd198 100644 (file)
@@ -42,6 +42,7 @@
 #include "llvm/CodeGen/MachineLocation.h"
 #include "llvm/GlobalValue.h"
 #include "llvm/Pass.h"
+#include "llvm/Metadata.h"
 
 namespace llvm {
 
@@ -147,7 +148,7 @@ class MachineModuleInfo : public ImmutablePass {
 public:
   static char ID; // Pass identification, replacement for typeid
 
-  typedef DenseMap<MDNode *, std::pair<MDNode *, unsigned> > VariableDbgInfoMapTy;
+  typedef SmallVector< std::pair< WeakMetadataVH, unsigned>, 4 > VariableDbgInfoMapTy;
   VariableDbgInfoMapTy VariableDbgInfo;
 
   MachineModuleInfo();
@@ -332,9 +333,8 @@ public:
 
   /// setVariableDbgInfo - Collect information used to emit debugging information
   /// of a variable.
-  void setVariableDbgInfo(MDNode *N, MDNode *L, unsigned S) {
-    if (N && L)
-      VariableDbgInfo[N] = std::make_pair(L, S);
+  void setVariableDbgInfo(MDNode *N, unsigned S) {
+    VariableDbgInfo.push_back(std::make_pair(N, S));
   }
 
   VariableDbgInfoMapTy &getVariableDbgInfo() {  return VariableDbgInfo;  }
index 86532e816d60282806903493af11ee8cd8d9f5b6..f0579fe588afd31b7dd6c511ab785b9ea7114679 100644 (file)
@@ -1784,23 +1784,19 @@ void DwarfDebug::EndModule() {
 }
 
 /// CollectVariableInfo - Populate DbgScope entries with variables' info.
-bool DwarfDebug::CollectVariableInfo() {
-  if (!MMI) return false;
-  bool ArgsCollected = false;
+void DwarfDebug::CollectVariableInfo() {
+  if (!MMI) return;
   MachineModuleInfo::VariableDbgInfoMapTy &VMap = MMI->getVariableDbgInfo();
   for (MachineModuleInfo::VariableDbgInfoMapTy::iterator VI = VMap.begin(),
          VE = VMap.end(); VI != VE; ++VI) {
-    MDNode *Var = VI->first;
+    MetadataBase *MB = VI->first;
+    MDNode *Var = dyn_cast_or_null<MDNode>(MB);
     DIVariable DV (Var);
     if (DV.isNull()) continue;
-    if (DV.getTag() == dwarf::DW_TAG_arg_variable)
-      ArgsCollected = true;
-    DILocation VLoc(VI->second.first);
-    unsigned VSlot = VI->second.second;
-    DbgScope *Scope = getDbgScope(VLoc.getScope().getNode(), NULL);
+    unsigned VSlot = VI->second;
+    DbgScope *Scope = getDbgScope(DV.getContext().getNode(),  NULL);
     Scope->AddVariable(new DbgVariable(DV, VSlot, false));
   }
-  return ArgsCollected;
 }
 
 /// SetDbgScopeBeginLabels - Update DbgScope begin labels for the scopes that
@@ -1911,7 +1907,7 @@ void DwarfDebug::BeginFunction(MachineFunction *MF) {
 #ifdef ATTACH_DEBUG_INFO_TO_AN_INSN
   if (!ExtractScopeInformation(MF))
     return;
-  bool ArgsCollected = CollectVariableInfo();
+  CollectVariableInfo();
 #endif
 
   // Begin accumulating function debug information.
@@ -1923,18 +1919,27 @@ void DwarfDebug::BeginFunction(MachineFunction *MF) {
   // Emit label for the implicitly defined dbg.stoppoint at the start of the
   // function.
 #ifdef ATTACH_DEBUG_INFO_TO_AN_INSN
-  if (!ArgsCollected) {
+  DebugLoc FDL = MF->getDefaultDebugLoc();
+  if (!FDL.isUnknown()) {
+    DebugLocTuple DLT = MF->getDebugLocTuple(FDL);
+    unsigned LabelID = 0;
+    DISubprogram SP(DLT.CompileUnit);
+    if (!SP.isNull())
+      LabelID = RecordSourceLine(SP.getLineNumber(), 0, DLT.CompileUnit);
+    else
+      LabelID = RecordSourceLine(DLT.Line, DLT.Col, DLT.CompileUnit);
+    Asm->printLabel(LabelID);
+    O << '\n';
+  }
 #else
-  if (1) {
-#endif
-    DebugLoc FDL = MF->getDefaultDebugLoc();
-    if (!FDL.isUnknown()) {
-      DebugLocTuple DLT = MF->getDebugLocTuple(FDL);
-      unsigned LabelID = RecordSourceLine(DLT.Line, DLT.Col, DLT.CompileUnit);
-      Asm->printLabel(LabelID);
-      O << '\n';
-    }
+  DebugLoc FDL = MF->getDefaultDebugLoc();
+  if (!FDL.isUnknown()) {
+    DebugLocTuple DLT = MF->getDebugLocTuple(FDL);
+    unsigned LabelID = RecordSourceLine(DLT.Line, DLT.Col, DLT.CompileUnit);
+    Asm->printLabel(LabelID);
+    O << '\n';
   }
+#endif
   if (TimePassesIsEnabled)
     DebugTimer->stopTimer();
 }
@@ -1947,6 +1952,10 @@ void DwarfDebug::EndFunction(MachineFunction *MF) {
   if (TimePassesIsEnabled)
     DebugTimer->startTimer();
 
+#ifdef ATTACH_DEBUG_INFO_TO_AN_INSN
+  if (DbgScopeMap.empty())
+    return;
+#endif
   // Define end label for subprogram.
   EmitLabel("func_end", SubprogramCount);
 
index 7e2f6be837d3631aa4cc0c67d94a2f2bb9a2a7c9..bd377c5593ccfdecec0e225e852a530225d09c5f 100644 (file)
@@ -556,7 +556,7 @@ public:
   bool ExtractScopeInformation(MachineFunction *MF);
 
   /// CollectVariableInfo - Populate DbgScope entries with variables' info.
-  bool CollectVariableInfo();
+  void CollectVariableInfo();
 
   /// SetDbgScopeBeginLabels - Update DbgScope begin labels for the scopes that
   /// start with this machine instruction.
index bccff160ce9a5865b7ad2a081bba63060c92a48d..e4ccbce471c0f1287350e791d94473e9252976c9 100644 (file)
@@ -417,14 +417,8 @@ bool FastISel::SelectCall(User *I) {
       StaticAllocaMap.find(AI);
     if (SI == StaticAllocaMap.end()) break; // VLAs.
     int FI = SI->second;
-    if (MMI) {
-      MetadataContext &TheMetadata = AI->getContext().getMetadata();
-      unsigned MDDbgKind = TheMetadata.getMDKind("dbg");
-      MDNode *AllocaLocation =
-        dyn_cast_or_null<MDNode>(TheMetadata.getMD(MDDbgKind, AI));
-      if (AllocaLocation)
-        MMI->setVariableDbgInfo(DI->getVariable(), AllocaLocation, FI);
-    }
+    if (MMI)
+      MMI->setVariableDbgInfo(DI->getVariable(), FI);
 #ifndef ATTACH_DEBUG_INFO_TO_AN_INSN
     DW->RecordVariable(DI->getVariable(), FI);
 #endif
index a27fbe68adc96475f13ba9f0b9a17d0cf4351dff..aa4ae733c25d3a789680be5161585a896e89cfc4 100644 (file)
@@ -3970,7 +3970,7 @@ SelectionDAGLowering::visitIntrinsicCall(CallInst &I, unsigned Intrinsic) {
     if (!isValidDebugInfoIntrinsic(DI, CodeGenOpt::None))
       return 0;
 
-    Value *Variable = DI.getVariable();
+    MDNode *Variable = DI.getVariable();
     Value *Address = DI.getAddress();
     if (BitCastInst *BCI = dyn_cast<BitCastInst>(Address))
       Address = BCI->getOperand(0);
@@ -3983,7 +3983,13 @@ SelectionDAGLowering::visitIntrinsicCall(CallInst &I, unsigned Intrinsic) {
     if (SI == FuncInfo.StaticAllocaMap.end()) 
       return 0; // VLAs.
     int FI = SI->second;
-    DW->RecordVariable(cast<MDNode>(Variable), FI);
+#ifdef ATTACH_DEBUG_INFO_TO_AN_INSN
+    MachineModuleInfo *MMI = DAG.getMachineModuleInfo();
+    if (MMI) 
+      MMI->setVariableDbgInfo(Variable, FI);
+#else
+    DW->RecordVariable(Variable, FI);
+#endif
     return 0;
   }
   case Intrinsic::eh_exception: {