<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Feb 10, 2015 at 3:18 PM, Adrian Prantl <span dir="ltr"><<a href="mailto:aprantl@apple.com" target="_blank">aprantl@apple.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: adrian<br>
Date: Tue Feb 10 17:18:28 2015<br>
New Revision: 228764<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=228764&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=228764&view=rev</a><br>
Log:<br>
Debug Info: Support variables that are described by more than one MMI<br>
table entry. This happens when SROA splits up an alloca and the resulting<br>
allocas cannot be lowered to SSA values because their address is passed<br>
to a function.<br></blockquote><div><br>Forgot to git add the test case, perhaps? (& given the description, I hope the test case can be a bit cleaner/simpler than the reduced reproductions we were looking at earlier, but I realize that might not be the case)<br> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
Fixes PR22502.<br>
<br>
Modified:<br>
    llvm/trunk/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp<br>
    llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp<br>
    llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.h<br>
    llvm/trunk/lib/CodeGen/AsmPrinter/DwarfFile.cpp<br>
    llvm/trunk/lib/CodeGen/AsmPrinter/DwarfFile.h<br>
<br>
Modified: llvm/trunk/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp?rev=228764&r1=228763&r2=228764&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp?rev=228764&r1=228763&r2=228764&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp (original)<br>
+++ llvm/trunk/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp Tue Feb 10 17:18:28 2015<br>
@@ -516,15 +516,21 @@ DwarfCompileUnit::constructVariableDIEIm<br>
   }<br>
<br>
   // .. else use frame index.<br>
-  int FI = DV.getFrameIndex();<br>
-  if (FI != ~0) {<br>
+  if (DV.getFrameIndex().back() == ~0)<br>
+    return VariableDie;<br>
+<br>
+  auto Expr = DV.getExpression().begin();<br>
+  DIELoc *Loc = new (DIEValueAllocator) DIELoc();<br>
+  DIEDwarfExpression DwarfExpr(*Asm, *this, *Loc);<br>
+  for (auto FI : DV.getFrameIndex()) {<br>
     unsigned FrameReg = 0;<br>
     const TargetFrameLowering *TFI =<br>
         Asm->TM.getSubtargetImpl()->getFrameLowering();<br>
     int Offset = TFI->getFrameIndexReference(*Asm->MF, FI, FrameReg);<br>
-    MachineLocation Location(FrameReg, Offset);<br>
-    addVariableAddress(DV, *VariableDie, Location);<br>
+    DwarfExpr.AddMachineRegIndirect(FrameReg, Offset);<br>
+    DwarfExpr.AddExpression(*(Expr++));<br>
   }<br>
+  addBlock(*VariableDie, dwarf::DW_AT_location, Loc);<br>
<br>
   return VariableDie;<br>
 }<br>
@@ -767,7 +773,8 @@ void DwarfCompileUnit::addComplexAddress<br>
                                          const MachineLocation &Location) {<br>
   DIELoc *Loc = new (DIEValueAllocator) DIELoc();<br>
   DIEDwarfExpression DwarfExpr(*Asm, *this, *Loc);<br>
-  DIExpression Expr = DV.getExpression();<br>
+  assert(DV.getExpression().size() == 1);<br>
+  DIExpression Expr = DV.getExpression().back();<br>
   bool ValidReg;<br>
   if (Location.getOffset()) {<br>
     ValidReg = DwarfExpr.AddMachineRegIndirect(Location.getReg(),<br>
<br>
Modified: llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp?rev=228764&r1=228763&r2=228764&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp?rev=228764&r1=228763&r2=228764&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp (original)<br>
+++ llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp Tue Feb 10 17:18:28 2015<br>
@@ -783,10 +783,9 @@ void DwarfDebug::collectVariableInfoFrom<br>
     DIVariable DV(VI.Var);<br>
     DIExpression Expr(VI.Expr);<br>
     ensureAbstractVariableIsCreatedIfScoped(DV, Scope->getScopeNode());<br>
-    ConcreteVariables.push_back(make_unique<DbgVariable>(DV, Expr, this));<br>
-    DbgVariable *RegVar = ConcreteVariables.back().get();<br>
-    RegVar->setFrameIndex(VI.Slot);<br>
-    InfoHolder.addScopeVariable(Scope, RegVar);<br>
+    auto RegVar = make_unique<DbgVariable>(DV, Expr, this, VI.Slot);<br>
+    if (InfoHolder.addScopeVariable(Scope, RegVar.get()))<br>
+      ConcreteVariables.push_back(std::move(RegVar));<br>
   }<br>
 }<br>
<br>
<br>
Modified: llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.h?rev=228764&r1=228763&r2=228764&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.h?rev=228764&r1=228763&r2=228764&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.h (original)<br>
+++ llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.h Tue Feb 10 17:18:28 2015<br>
@@ -67,41 +67,66 @@ public:<br>
<br>
 //===----------------------------------------------------------------------===//<br>
 /// \brief This class is used to track local variable information.<br>
+///<br>
+/// - Variables whose location changes over time have a DotDebugLocOffset and the<br>
+///   other fields are not used.<br>
+///<br>
+/// - Variables that are described by multiple MMI table entries have multiple<br>
+///   expressions and frame indices.<br>
 class DbgVariable {<br>
-  DIVariable Var;             // Variable Descriptor.<br>
-  DIExpression Expr;          // Complex address location expression.<br>
-  DIE *TheDIE;                // Variable DIE.<br>
-  unsigned DotDebugLocOffset; // Offset in DotDebugLocEntries.<br>
-  const MachineInstr *MInsn;  // DBG_VALUE instruction of the variable.<br>
-  int FrameIndex;<br>
+  DIVariable Var;             /// Variable Descriptor.<br>
+  SmallVector<DIExpression, 1> Expr; /// Complex address location expression.<br>
+  DIE *TheDIE;                /// Variable DIE.<br>
+  unsigned DotDebugLocOffset; /// Offset in DotDebugLocEntries.<br>
+  const MachineInstr *MInsn;  /// DBG_VALUE instruction of the variable.<br>
+  SmallVector<int, 1> FrameIndex; /// Frame index of the variable.<br>
   DwarfDebug *DD;<br>
<br>
 public:<br>
   /// Construct a DbgVariable from a DIVariable.<br>
-  DbgVariable(DIVariable V, DIExpression E, DwarfDebug *DD)<br>
-      : Var(V), Expr(E), TheDIE(nullptr), DotDebugLocOffset(~0U),<br>
-        MInsn(nullptr), FrameIndex(~0), DD(DD) {<br>
-    assert(Var.Verify() && Expr.Verify());<br>
+    DbgVariable(DIVariable V, DIExpression E, DwarfDebug *DD, int FI = ~0)<br>
+    : Var(V), Expr(1, E), TheDIE(nullptr), DotDebugLocOffset(~0U),<br>
+      MInsn(nullptr), DD(DD) {<br>
+    FrameIndex.push_back(FI);<br>
+    assert(Var.Verify() && E.Verify());<br>
   }<br>
<br>
   /// Construct a DbgVariable from a DEBUG_VALUE.<br>
   /// AbstractVar may be NULL.<br>
   DbgVariable(const MachineInstr *DbgValue, DwarfDebug *DD)<br>
-      : Var(DbgValue->getDebugVariable()), Expr(DbgValue->getDebugExpression()),<br>
-        TheDIE(nullptr), DotDebugLocOffset(~0U), MInsn(DbgValue),<br>
-        FrameIndex(~0), DD(DD) {}<br>
+    : Var(DbgValue->getDebugVariable()), Expr(1, DbgValue->getDebugExpression()),<br>
+        TheDIE(nullptr), DotDebugLocOffset(~0U), MInsn(DbgValue), DD(DD) {<br>
+    FrameIndex.push_back(~0);<br>
+  }<br>
<br>
   // Accessors.<br>
   DIVariable getVariable() const { return Var; }<br>
-  DIExpression getExpression() const { return Expr; }<br>
+  const ArrayRef<DIExpression> getExpression() const { return Expr; }<br>
   void setDIE(DIE &D) { TheDIE = &D; }<br>
   DIE *getDIE() const { return TheDIE; }<br>
   void setDotDebugLocOffset(unsigned O) { DotDebugLocOffset = O; }<br>
   unsigned getDotDebugLocOffset() const { return DotDebugLocOffset; }<br>
   StringRef getName() const { return Var.getName(); }<br>
   const MachineInstr *getMInsn() const { return MInsn; }<br>
-  int getFrameIndex() const { return FrameIndex; }<br>
-  void setFrameIndex(int FI) { FrameIndex = FI; }<br>
+  const ArrayRef<int> getFrameIndex() const { return FrameIndex; }<br>
+<br>
+  void addMMIEntry(const DbgVariable &V) {<br>
+    assert(  DotDebugLocOffset == ~0U &&   !MInsn && "not an MMI entry");<br>
+    assert(V.DotDebugLocOffset == ~0U && !V.MInsn && "not an MMI entry");<br>
+    assert(V.Var == Var && "conflicting DIVariable");<br>
+<br>
+    if (V.getFrameIndex().back() != ~0) {<br>
+      auto E = V.getExpression();<br>
+      auto FI = V.getFrameIndex();<br>
+      Expr.append(E.begin(), E.end());<br>
+      FrameIndex.append(FI.begin(), FI.end());<br>
+    }<br>
+    assert(Expr.size() > 1<br>
+           ? std::all_of(Expr.begin(), Expr.end(),<br>
+                         [](DIExpression &E) { return E.isBitPiece(); })<br>
+           : (true && "conflicting locations for variable"));<br>
+  }<br>
+<br>
   // Translate tag to proper Dwarf tag.<br>
   dwarf::Tag getTag() const {<br>
     if (Var.getTag() == dwarf::DW_TAG_arg_variable)<br>
@@ -128,14 +153,11 @@ public:<br>
<br>
   bool variableHasComplexAddress() const {<br>
     assert(Var.isVariable() && "Invalid complex DbgVariable!");<br>
-    return Expr.getNumElements() > 0;<br>
+    assert(Expr.size() == 1 &&<br>
+           "variableHasComplexAddress() invoked on multi-FI variable");<br>
+    return Expr.back().getNumElements() > 0;<br>
   }<br>
   bool isBlockByrefVariable() const;<br>
-  unsigned getNumAddrElements() const {<br>
-    assert(Var.isVariable() && "Invalid complex DbgVariable!");<br>
-    return Expr.getNumElements();<br>
-  }<br>
-  uint64_t getAddrElement(unsigned i) const { return Expr.getElement(i); }<br>
   DIType getType() const;<br>
<br>
 private:<br>
<br>
Modified: llvm/trunk/lib/CodeGen/AsmPrinter/DwarfFile.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DwarfFile.cpp?rev=228764&r1=228763&r2=228764&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DwarfFile.cpp?rev=228764&r1=228763&r2=228764&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/lib/CodeGen/AsmPrinter/DwarfFile.cpp (original)<br>
+++ llvm/trunk/lib/CodeGen/AsmPrinter/DwarfFile.cpp Tue Feb 10 17:18:28 2015<br>
@@ -146,7 +146,7 @@ void DwarfFile::emitStrings(const MCSect<br>
   StrPool.emit(*Asm, StrSection, OffsetSection);<br>
 }<br>
<br>
-void DwarfFile::addScopeVariable(LexicalScope *LS, DbgVariable *Var) {<br>
+bool DwarfFile::addScopeVariable(LexicalScope *LS, DbgVariable *Var) {<br>
   SmallVectorImpl<DbgVariable *> &Vars = ScopeVariables[LS];<br>
   DIVariable DV = Var->getVariable();<br>
   // Variables with positive arg numbers are parameters.<br>
@@ -168,13 +168,17 @@ void DwarfFile::addScopeVariable(Lexical<br>
       // A later indexed parameter has been found, insert immediately before it.<br>
       if (CurNum > ArgNum)<br>
         break;<br>
-      assert(CurNum != ArgNum && "Duplicate argument");<br>
+      if (CurNum == ArgNum) {<br>
+        (*I)->addMMIEntry(*Var);<br>
+        return false;<br>
+      }<br>
       ++I;<br>
     }<br>
     Vars.insert(I, Var);<br>
-    return;<br>
+    return true;<br>
   }<br>
<br>
   Vars.push_back(Var);<br>
+  return true;<br>
 }<br>
 }<br>
<br>
Modified: llvm/trunk/lib/CodeGen/AsmPrinter/DwarfFile.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DwarfFile.h?rev=228764&r1=228763&r2=228764&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DwarfFile.h?rev=228764&r1=228763&r2=228764&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/lib/CodeGen/AsmPrinter/DwarfFile.h (original)<br>
+++ llvm/trunk/lib/CodeGen/AsmPrinter/DwarfFile.h Tue Feb 10 17:18:28 2015<br>
@@ -95,7 +95,8 @@ public:<br>
   /// \brief Returns the string pool.<br>
   DwarfStringPool &getStringPool() { return StrPool; }<br>
<br>
-  void addScopeVariable(LexicalScope *LS, DbgVariable *Var);<br>
+  /// \returns false if the variable was merged with a previous one.<br>
+  bool addScopeVariable(LexicalScope *LS, DbgVariable *Var);<br>
<br>
   DenseMap<LexicalScope *, SmallVector<DbgVariable *, 8>> &getScopeVariables() {<br>
     return ScopeVariables;<br>
<br>
<br>
_______________________________________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@cs.uiuc.edu">llvm-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</a><br>
</blockquote></div><br></div></div>