Refactor some common logic in DwarfUnit::constructVariableDIE and pass non-null DIE...
authorDavid Blaikie <dblaikie@gmail.com>
Fri, 25 Apr 2014 17:32:19 +0000 (17:32 +0000)
committerDavid Blaikie <dblaikie@gmail.com>
Fri, 25 Apr 2014 17:32:19 +0000 (17:32 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@207244 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/AsmPrinter/DwarfDebug.h
lib/CodeGen/AsmPrinter/DwarfUnit.cpp
lib/CodeGen/AsmPrinter/DwarfUnit.h

index 5e8ef28a8710cd280c13109f71a2b0e9b958544a..839a8a02535698a59bd9392505367a69958739ee 100644 (file)
@@ -83,7 +83,7 @@ public:
 
   // Accessors.
   DIVariable getVariable() const { return Var; }
-  void setDIE(DIE *D) { TheDIE = D; }
+  void setDIE(DIE &D) { TheDIE = &D; }
   DIE *getDIE() const { return TheDIE; }
   void setDotDebugLocOffset(unsigned O) { DotDebugLocOffset = O; }
   unsigned getDotDebugLocOffset() const { return DotDebugLocOffset; }
index 6a2cb6880ce0694368c8a5de10c02e837d863754..47d2157e4c649937e06776dd2575345dc07fe014 100644 (file)
@@ -1802,6 +1802,13 @@ void DwarfUnit::constructContainingTypeDIEs() {
 
 /// constructVariableDIE - Construct a DIE for the given DbgVariable.
 DIE *DwarfUnit::constructVariableDIE(DbgVariable &DV, bool isScopeAbstract) {
+  auto D = constructVariableDIEImpl(DV, isScopeAbstract);
+  DV.setDIE(*D);
+  return D;
+}
+
+DIE *DwarfUnit::constructVariableDIEImpl(const DbgVariable &DV,
+                                         bool isScopeAbstract) {
   StringRef Name = DV.getName();
 
   // Define variable debug information entry.
@@ -1820,17 +1827,14 @@ DIE *DwarfUnit::constructVariableDIE(DbgVariable &DV, bool isScopeAbstract) {
   if (DV.isArtificial())
     addFlag(VariableDie, dwarf::DW_AT_artificial);
 
-  if (isScopeAbstract) {
-    DV.setDIE(VariableDie);
+  if (isScopeAbstract)
     return VariableDie;
-  }
 
   // Add variable address.
 
   unsigned Offset = DV.getDotDebugLocOffset();
   if (Offset != ~0U) {
     addLocationList(VariableDie, dwarf::DW_AT_location, Offset);
-    DV.setDIE(VariableDie);
     return VariableDie;
   }
 
@@ -1854,21 +1858,19 @@ DIE *DwarfUnit::constructVariableDIE(DbgVariable &DV, bool isScopeAbstract) {
       addConstantValue(VariableDie, DVInsn->getOperand(0).getCImm(),
                        isUnsignedDIType(DD, DV.getType()));
 
-    DV.setDIE(VariableDie);
     return VariableDie;
-  } else {
-    // .. else use frame index.
-    int FI = DV.getFrameIndex();
-    if (FI != ~0) {
-      unsigned FrameReg = 0;
-      const TargetFrameLowering *TFI = Asm->TM.getFrameLowering();
-      int Offset = TFI->getFrameIndexReference(*Asm->MF, FI, FrameReg);
-      MachineLocation Location(FrameReg, Offset);
-      addVariableAddress(DV, VariableDie, Location);
-    }
   }
 
-  DV.setDIE(VariableDie);
+  // .. else use frame index.
+  int FI = DV.getFrameIndex();
+  if (FI != ~0) {
+    unsigned FrameReg = 0;
+    const TargetFrameLowering *TFI = Asm->TM.getFrameLowering();
+    int Offset = TFI->getFrameIndexReference(*Asm->MF, FI, FrameReg);
+    MachineLocation Location(FrameReg, Offset);
+    addVariableAddress(DV, VariableDie, Location);
+  }
+
   return VariableDie;
 }
 
index c3c9660d473306c44105b15df32e62efa605926b..3974775aa8e60ea5ae115c4cf61d7272f55887f0 100644 (file)
@@ -457,6 +457,10 @@ protected:
   virtual unsigned getOrCreateSourceID(StringRef File, StringRef Directory) = 0;
 
 private:
+  /// \brief Construct a DIE for the given DbgVariable without initializing the
+  /// DbgVariable's DIE reference.
+  DIE *constructVariableDIEImpl(const DbgVariable &DV, bool isScopeAbstract);
+
   /// constructTypeDIE - Construct basic type die from DIBasicType.
   void constructTypeDIE(DIE &Buffer, DIBasicType BTy);