Blame SOURCES/rust-lang-llvm-pr53.patch

198b24
From 0d4331af6e01235479e44f9775b3fde9e19200a3 Mon Sep 17 00:00:00 2001
198b24
From: Keith Walker <kwalker@arm.com>
198b24
Date: Tue, 27 Sep 2016 16:46:07 +0000
198b24
Subject: [rust-lang/llvm#53 1/2] Propagate DBG_VALUE entries when there are
198b24
 unvisited predecessors
198b24
198b24
Variables are sometimes missing their debug location information in
198b24
blocks in which the variables should be available. This would occur
198b24
when one or more predecessor blocks had not yet been visited by the
198b24
routine which propagated the information from predecessor blocks.
198b24
198b24
This is addressed by only considering predecessor blocks which have
198b24
already been visited.
198b24
198b24
The solution to this problem was suggested by Daniel Berlin on the
198b24
LLVM developer mailing list.
198b24
198b24
Differential Revision: https://reviews.llvm.org/D24927
198b24
198b24
198b24
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@282506 91177308-0d34-0410-b5e6-96231b3b80d8
198b24
---
198b24
 lib/CodeGen/LiveDebugValues.cpp          |  34 ++--
198b24
 test/CodeGen/ARM/dbg-range-extension.mir | 282 +++++++++++++++++++++++++++++++
198b24
 2 files changed, 306 insertions(+), 10 deletions(-)
198b24
 create mode 100644 test/CodeGen/ARM/dbg-range-extension.mir
198b24
198b24
diff --git a/lib/CodeGen/LiveDebugValues.cpp b/lib/CodeGen/LiveDebugValues.cpp
198b24
index 4ff88d528108..4cadd5855ed5 100644
198b24
--- a/lib/CodeGen/LiveDebugValues.cpp
198b24
+++ b/lib/CodeGen/LiveDebugValues.cpp
198b24
@@ -201,7 +201,8 @@ private:
198b24
                 VarLocInMBB &OutLocs, VarLocMap &VarLocIDs);
198b24
 
198b24
   bool join(MachineBasicBlock &MBB, VarLocInMBB &OutLocs, VarLocInMBB &InLocs,
198b24
-            const VarLocMap &VarLocIDs);
198b24
+            const VarLocMap &VarLocIDs,
198b24
+            SmallPtrSet<const MachineBasicBlock *, 16> &Visited);
198b24
 
198b24
   bool ExtendRanges(MachineFunction &MF;;
198b24
 
198b24
@@ -368,7 +369,8 @@ bool LiveDebugValues::transfer(MachineInstr &MI, OpenRangesSet &OpenRanges,
198b24
 /// inserting a new DBG_VALUE instruction at the start of the @MBB - if the same
198b24
 /// source variable in all the predecessors of @MBB reside in the same location.
198b24
 bool LiveDebugValues::join(MachineBasicBlock &MBB, VarLocInMBB &OutLocs,
198b24
-                           VarLocInMBB &InLocs, const VarLocMap &VarLocIDs) {
198b24
+                           VarLocInMBB &InLocs, const VarLocMap &VarLocIDs,
198b24
+                           SmallPtrSet<const MachineBasicBlock *, 16> &Visited) {
198b24
   DEBUG(dbgs() << "join MBB: " << MBB.getName() << "\n");
198b24
   bool Changed = false;
198b24
 
198b24
@@ -376,21 +378,32 @@ bool LiveDebugValues::join(MachineBasicBlock &MBB, VarLocInMBB &OutLocs,
198b24
 
198b24
   // For all predecessors of this MBB, find the set of VarLocs that
198b24
   // can be joined.
198b24
+  int NumVisited = 0;
198b24
   for (auto p : MBB.predecessors()) {
198b24
+    // Ignore unvisited predecessor blocks.  As we are processing
198b24
+    // the blocks in reverse post-order any unvisited block can
198b24
+    // be considered to not remove any incoming values.
198b24
+    if (!Visited.count(p))
198b24
+      continue;
198b24
     auto OL = OutLocs.find(p);
198b24
     // Join is null in case of empty OutLocs from any of the pred.
198b24
     if (OL == OutLocs.end())
198b24
       return false;
198b24
 
198b24
-    // Just copy over the Out locs to incoming locs for the first predecessor.
198b24
-    if (p == *MBB.pred_begin()) {
198b24
+    // Just copy over the Out locs to incoming locs for the first visited
198b24
+    // predecessor, and for all other predecessors join the Out locs.
198b24
+    if (!NumVisited)
198b24
       InLocsT = OL->second;
198b24
-      continue;
198b24
-    }
198b24
-    // Join with this predecessor.
198b24
-    InLocsT &= OL->second;
198b24
+    else
198b24
+      InLocsT &= OL->second;
198b24
+    NumVisited++;
198b24
   }
198b24
 
198b24
+  // As we are processing blocks in reverse post-order we
198b24
+  // should have processed at least one predecessor, unless it
198b24
+  // is the entry block which has no predecessor.
198b24
+  assert((NumVisited || MBB.pred_empty()) &&
198b24
+         "Should have processed at least one predecessor");
198b24
   if (InLocsT.empty())
198b24
     return false;
198b24
 
198b24
@@ -463,6 +476,7 @@ bool LiveDebugValues::ExtendRanges(MachineFunction &MF) {
198b24
   // To solve it, we perform join() and transfer() using the two worklist method
198b24
   // until the ranges converge.
198b24
   // Ranges have converged when both worklists are empty.
198b24
+  SmallPtrSet<const MachineBasicBlock *, 16> Visited;
198b24
   while (!Worklist.empty() || !Pending.empty()) {
198b24
     // We track what is on the pending worklist to avoid inserting the same
198b24
     // thing twice.  We could avoid this with a custom priority queue, but this
198b24
@@ -471,8 +485,8 @@ bool LiveDebugValues::ExtendRanges(MachineFunction &MF) {
198b24
     while (!Worklist.empty()) {
198b24
       MachineBasicBlock *MBB = OrderToBB[Worklist.top()];
198b24
       Worklist.pop();
198b24
-      MBBJoined = join(*MBB, OutLocs, InLocs, VarLocIDs);
198b24
-
198b24
+      MBBJoined = join(*MBB, OutLocs, InLocs, VarLocIDs, Visited);
198b24
+      Visited.insert(MBB);
198b24
       if (MBBJoined) {
198b24
         MBBJoined = false;
198b24
         Changed = true;
198b24
-- 
198b24
2.7.4
198b24
198b24
From 8a0fc26559123bb6eab3ceae93d5a2c94943614b Mon Sep 17 00:00:00 2001
198b24
From: Adrian Prantl <aprantl@apple.com>
198b24
Date: Wed, 28 Sep 2016 17:51:14 +0000
198b24
Subject: [rust-lang/llvm#53 2/2] Teach LiveDebugValues about lexical scopes.
198b24
198b24
This addresses PR26055 LiveDebugValues is very slow.
198b24
198b24
Contrary to the old LiveDebugVariables pass LiveDebugValues currently
198b24
doesn't look at the lexical scopes before inserting a DBG_VALUE
198b24
intrinsic. This means that we often propagate DBG_VALUEs much further
198b24
down than necessary. This is especially noticeable in large C++
198b24
functions with many inlined method calls that all use the same
198b24
"this"-pointer.
198b24
198b24
For example, in the following code it makes no sense to propagate the
198b24
inlined variable a from the first inlined call to f() into any of the
198b24
subsequent basic blocks, because the variable will always be out of
198b24
scope:
198b24
198b24
void sink(int a);
198b24
void __attribute((always_inline)) f(int a) { sink(a); }
198b24
void foo(int i) {
198b24
   f(i);
198b24
   if (i)
198b24
     f(i);
198b24
   f(i);
198b24
}
198b24
198b24
This patch reuses the LexicalScopes infrastructure we have for
198b24
LiveDebugVariables to take this into account.
198b24
198b24
The effect on compile time and memory consumption is quite noticeable:
198b24
I tested a benchmark that is a large C++ source with an enormous
198b24
amount of inlined "this"-pointers that would previously eat >24GiB
198b24
(most of them for DBG_VALUE intrinsics) and whose compile time was
198b24
dominated by LiveDebugValues. With this patch applied the memory
198b24
consumption is 1GiB and 1.7% of the time is spent in LiveDebugValues.
198b24
198b24
https://reviews.llvm.org/D24994
198b24
Thanks to Daniel Berlin and Keith Walker for reviewing!
198b24
198b24
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@282611 91177308-0d34-0410-b5e6-96231b3b80d8
198b24
---
198b24
 lib/CodeGen/LiveDebugValues.cpp                  |  51 ++++-
198b24
 test/CodeGen/ARM/dbg-range-extension.mir         |   1 -
198b24
 test/DebugInfo/COFF/register-variables.ll        |   8 +-
198b24
 test/DebugInfo/MIR/X86/livedebugvalues-limit.mir | 228 +++++++++++++++++++++++
198b24
 test/DebugInfo/X86/fission-ranges.ll             |   6 +-
198b24
 5 files changed, 278 insertions(+), 16 deletions(-)
198b24
 create mode 100644 test/DebugInfo/MIR/X86/livedebugvalues-limit.mir
198b24
198b24
diff --git a/lib/CodeGen/LiveDebugValues.cpp b/lib/CodeGen/LiveDebugValues.cpp
198b24
index 4cadd5855ed5..969944eb24a2 100644
198b24
--- a/lib/CodeGen/LiveDebugValues.cpp
198b24
+++ b/lib/CodeGen/LiveDebugValues.cpp
198b24
@@ -23,6 +23,7 @@
198b24
 #include "llvm/ADT/SparseBitVector.h"
198b24
 #include "llvm/ADT/Statistic.h"
198b24
 #include "llvm/ADT/UniqueVector.h"
198b24
+#include "llvm/CodeGen/LexicalScopes.h"
198b24
 #include "llvm/CodeGen/MachineFunction.h"
198b24
 #include "llvm/CodeGen/MachineFunctionPass.h"
198b24
 #include "llvm/CodeGen/MachineInstrBuilder.h"
198b24
@@ -60,6 +61,26 @@ class LiveDebugValues : public MachineFunctionPass {
198b24
 private:
198b24
   const TargetRegisterInfo *TRI;
198b24
   const TargetInstrInfo *TII;
198b24
+  LexicalScopes LS;
198b24
+
198b24
+  /// Keeps track of lexical scopes associated with a user value's source
198b24
+  /// location.
198b24
+  class UserValueScopes {
198b24
+    DebugLoc DL;
198b24
+    LexicalScopes &LS;
198b24
+    SmallPtrSet<const MachineBasicBlock *, 4> LBlocks;
198b24
+
198b24
+  public:
198b24
+    UserValueScopes(DebugLoc D, LexicalScopes &L) : DL(std::move(D)), LS(L) {}
198b24
+
198b24
+    /// Return true if current scope dominates at least one machine
198b24
+    /// instruction in a given machine basic block.
198b24
+    bool dominates(MachineBasicBlock *MBB) {
198b24
+      if (LBlocks.empty())
198b24
+        LS.getMachineBasicBlocks(DL, LBlocks);
198b24
+      return LBlocks.count(MBB) != 0 || LS.dominates(DL, MBB);
198b24
+    }
198b24
+  };
198b24
 
198b24
   /// Based on std::pair so it can be used as an index into a DenseMap.
198b24
   typedef std::pair<const DILocalVariable *, const DILocation *>
198b24
@@ -83,7 +104,7 @@ private:
198b24
   struct VarLoc {
198b24
     const DebugVariable Var;
198b24
     const MachineInstr &MI; ///< Only used for cloning a new DBG_VALUE.
198b24
-
198b24
+    mutable UserValueScopes UVS;
198b24
     enum { InvalidKind = 0, RegisterKind } Kind;
198b24
 
198b24
     /// The value location. Stored separately to avoid repeatedly
198b24
@@ -96,9 +117,9 @@ private:
198b24
       uint64_t Hash;
198b24
     } Loc;
198b24
 
198b24
-    VarLoc(const MachineInstr &MI)
198b24
+    VarLoc(const MachineInstr &MI, LexicalScopes &LS)
198b24
         : Var(MI.getDebugVariable(), MI.getDebugLoc()->getInlinedAt()), MI(MI),
198b24
-          Kind(InvalidKind) {
198b24
+          UVS(MI.getDebugLoc(), LS), Kind(InvalidKind) {
198b24
       static_assert((sizeof(Loc) == sizeof(uint64_t)),
198b24
                     "hash does not cover all members of Loc");
198b24
       assert(MI.isDebugValue() && "not a DBG_VALUE");
198b24
@@ -125,6 +146,10 @@ private:
198b24
       return 0;
198b24
     }
198b24
 
198b24
+    /// Determine whether the lexical scope of this value's debug location
198b24
+    /// dominates MBB.
198b24
+    bool dominates(MachineBasicBlock &MBB) const { return UVS.dominates(&MBB); }
198b24
+
198b24
     void dump() const { MI.dump(); }
198b24
 
198b24
     bool operator==(const VarLoc &Other) const {
198b24
@@ -229,6 +254,7 @@ public:
198b24
   /// Calculate the liveness information for the given machine function.
198b24
   bool runOnMachineFunction(MachineFunction &MF) override;
198b24
 };
198b24
+
198b24
 } // namespace
198b24
 
198b24
 //===----------------------------------------------------------------------===//
198b24
@@ -295,7 +321,7 @@ void LiveDebugValues::transferDebugValue(const MachineInstr &MI,
198b24
   // Add the VarLoc to OpenRanges from this DBG_VALUE.
198b24
   // TODO: Currently handles DBG_VALUE which has only reg as location.
198b24
   if (isDbgValueDescribedByReg(MI)) {
198b24
-    VarLoc VL(MI);
198b24
+    VarLoc VL(MI, LS);
198b24
     unsigned ID = VarLocIDs.insert(VL);
198b24
     OpenRanges.insert(ID, VL.Var);
198b24
   }
198b24
@@ -399,6 +425,13 @@ bool LiveDebugValues::join(MachineBasicBlock &MBB, VarLocInMBB &OutLocs,
198b24
     NumVisited++;
198b24
   }
198b24
 
198b24
+  // Filter out DBG_VALUES that are out of scope.
198b24
+  VarLocSet KillSet;
198b24
+  for (auto ID : InLocsT)
198b24
+    if (!VarLocIDs[ID].dominates(MBB))
198b24
+      KillSet.set(ID);
198b24
+  InLocsT.intersectWithComplement(KillSet);
198b24
+
198b24
   // As we are processing blocks in reverse post-order we
198b24
   // should have processed at least one predecessor, unless it
198b24
   // is the entry block which has no predecessor.
198b24
@@ -519,12 +552,14 @@ bool LiveDebugValues::ExtendRanges(MachineFunction &MF) {
198b24
 }
198b24
 
198b24
 bool LiveDebugValues::runOnMachineFunction(MachineFunction &MF) {
198b24
+  if (!MF.getFunction()->getSubprogram())
198b24
+    // LiveDebugValues will already have removed all DBG_VALUEs.
198b24
+    return false;
198b24
+
198b24
   TRI = MF.getSubtarget().getRegisterInfo();
198b24
   TII = MF.getSubtarget().getInstrInfo();
198b24
+  LS.initialize(MF);
198b24
 
198b24
-  bool Changed = false;
198b24
-
198b24
-  Changed |= ExtendRanges(MF);
198b24
-
198b24
+  bool Changed = ExtendRanges(MF);
198b24
   return Changed;
198b24
 }
198b24
diff --git a/test/DebugInfo/COFF/register-variables.ll b/test/DebugInfo/COFF/register-variables.ll
198b24
index 9bb782853a3d..08246fef9603 100644
198b24
--- a/test/DebugInfo/COFF/register-variables.ll
198b24
+++ b/test/DebugInfo/COFF/register-variables.ll
198b24
@@ -37,8 +37,8 @@
198b24
 ; ASM:         #DEBUG_VALUE: c <- %EAX
198b24
 ; ASM:         testl   %esi, %esi
198b24
 ; ASM:         je      .LBB0_2
198b24
+; ASM: [[after_je:\.Ltmp.*]]:
198b24
 ; ASM: # BB#1:                                 # %if.then
198b24
-; ASM-DAG:     #DEBUG_VALUE: c <- %EAX
198b24
 ; ASM-DAG:     #DEBUG_VALUE: inlineinc:a <- %EAX
198b24
 ; ASM-DAG:     #DEBUG_VALUE: a <- %EAX
198b24
 ; ASM-DAG:     #DEBUG_VALUE: f:p <- %ESI
198b24
@@ -65,7 +65,7 @@
198b24
 ; ASM:         .cv_def_range    [[after_getint]] [[after_inc_eax]], "A\021\021\000\000\000"
198b24
 ; ASM:         .short  4414                    # Record kind: S_LOCAL
198b24
 ; ASM:         .asciz  "c"
198b24
-; ASM:         .cv_def_range    [[after_getint]] [[after_inc_eax]], "A\021\021\000\000\000"
198b24
+; ASM:         .cv_def_range    [[after_getint]] [[after_je]], "A\021\021\000\000\000"
198b24
 ; ASM:         .short  4414                    # Record kind: S_LOCAL
198b24
 ; ASM:         .asciz  "b"
198b24
 ; ASM:         .cv_def_range    [[after_inc_eax]] [[after_if]], "A\021\021\000\000\000"
198b24
@@ -132,7 +132,7 @@
198b24
 ; OBJ:     LocalVariableAddrRange {
198b24
 ; OBJ:       OffsetStart: .text+0xC
198b24
 ; OBJ:       ISectStart: 0x0
198b24
-; OBJ:       Range: 0x6
198b24
+; OBJ:       Range: 0x4
198b24
 ; OBJ:     }
198b24
 ; OBJ:   }
198b24
 ; OBJ:   Local {
198b24
@@ -143,7 +143,7 @@
198b24
 ; OBJ:   }
198b24
 ; OBJ:   DefRangeRegister {
198b24
 ; OBJ:     Register: 17
198b24
-; OBJ:     LocalVariableAddrRange {
198b24
+; OBJ:     MayHaveNoName: 0
198b24
 ; OBJ:       OffsetStart: .text+0x12
198b24
 ; OBJ:       ISectStart: 0x0
198b24
 ; OBJ:       Range: 0x6
198b24
diff --git a/test/DebugInfo/X86/fission-ranges.ll b/test/DebugInfo/X86/fission-ranges.ll
198b24
index 3c05f223ee79..0dfb13ab66b7 100644
198b24
--- a/test/DebugInfo/X86/fission-ranges.ll
198b24
+++ b/test/DebugInfo/X86/fission-ranges.ll
198b24
@@ -32,13 +32,13 @@
198b24
 ; CHECK-NEXT:                    Length: 25
198b24
 ; CHECK-NEXT:      Location description: 50 93 04
198b24
 ; CHECK: [[E]]: Beginning address index: 4
198b24
-; CHECK-NEXT:                    Length: 23
198b24
+; CHECK-NEXT:                    Length: 19
198b24
 ; CHECK-NEXT:      Location description: 50 93 04
198b24
 ; CHECK: [[B]]: Beginning address index: 5
198b24
-; CHECK-NEXT:                    Length: 21
198b24
+; CHECK-NEXT:                    Length: 17
198b24
 ; CHECK-NEXT:      Location description: 50 93 04
198b24
 ; CHECK: [[D]]: Beginning address index: 6
198b24
-; CHECK-NEXT:                    Length: 21
198b24
+; CHECK-NEXT:                    Length: 17
198b24
 ; CHECK-NEXT:      Location description: 50 93 04
198b24
 
198b24
 ; Make sure we don't produce any relocations in any .dwo section (though in particular, debug_info.dwo)
198b24
-- 
198b24
2.7.4
198b24