[llvm] r255759 - Recommit LiveDebugValues pass after fixing a couple of minor issues.

Vikram TV via llvm-commits llvm-commits at lists.llvm.org
Wed Dec 16 03:09:48 PST 2015


Author: tvvikram
Date: Wed Dec 16 05:09:48 2015
New Revision: 255759

URL: http://llvm.org/viewvc/llvm-project?rev=255759&view=rev
Log:
Recommit LiveDebugValues pass after fixing a couple of minor issues.

Added:
    llvm/trunk/lib/CodeGen/LiveDebugValues.cpp
    llvm/trunk/test/DebugInfo/MIR/X86/lit.local.cfg
    llvm/trunk/test/DebugInfo/MIR/X86/live-debug-values-3preds.mir
    llvm/trunk/test/DebugInfo/MIR/X86/live-debug-values.mir
    llvm/trunk/test/DebugInfo/MIR/lit.local.cfg
    llvm/trunk/test/DebugInfo/live-debug-values.ll
Modified:
    llvm/trunk/include/llvm/CodeGen/Passes.h
    llvm/trunk/include/llvm/InitializePasses.h
    llvm/trunk/lib/CodeGen/CMakeLists.txt
    llvm/trunk/lib/CodeGen/CodeGen.cpp
    llvm/trunk/lib/CodeGen/Passes.cpp
    llvm/trunk/test/DebugInfo/X86/array.ll
    llvm/trunk/test/DebugInfo/X86/fission-ranges.ll
    llvm/trunk/test/DebugInfo/X86/pieces-3.ll

Modified: llvm/trunk/include/llvm/CodeGen/Passes.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CodeGen/Passes.h?rev=255759&r1=255758&r2=255759&view=diff
==============================================================================
--- llvm/trunk/include/llvm/CodeGen/Passes.h (original)
+++ llvm/trunk/include/llvm/CodeGen/Passes.h Wed Dec 16 05:09:48 2015
@@ -640,6 +640,9 @@ namespace llvm {
   /// the intrinsic for later emission to the StackMap.
   extern char &StackMapLivenessID;
 
+  /// LiveDebugValues pass
+  extern char &LiveDebugValuesID;
+
   /// createJumpInstrTables - This pass creates jump-instruction tables.
   ModulePass *createJumpInstrTablesPass();
 

Modified: llvm/trunk/include/llvm/InitializePasses.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/InitializePasses.h?rev=255759&r1=255758&r2=255759&view=diff
==============================================================================
--- llvm/trunk/include/llvm/InitializePasses.h (original)
+++ llvm/trunk/include/llvm/InitializePasses.h Wed Dec 16 05:09:48 2015
@@ -292,6 +292,7 @@ void initializeBBVectorizePass(PassRegis
 void initializeMachineFunctionPrinterPassPass(PassRegistry&);
 void initializeMIRPrintingPassPass(PassRegistry&);
 void initializeStackMapLivenessPass(PassRegistry&);
+void initializeLiveDebugValuesPass(PassRegistry&);
 void initializeMachineCombinerPass(PassRegistry &);
 void initializeLoadCombinePass(PassRegistry&);
 void initializeRewriteSymbolsPass(PassRegistry&);

Modified: llvm/trunk/lib/CodeGen/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/CMakeLists.txt?rev=255759&r1=255758&r2=255759&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/CMakeLists.txt (original)
+++ llvm/trunk/lib/CodeGen/CMakeLists.txt Wed Dec 16 05:09:48 2015
@@ -25,6 +25,7 @@ add_llvm_library(LLVMCodeGen
   ExecutionDepsFix.cpp
   ExpandISelPseudos.cpp
   ExpandPostRAPseudos.cpp
+  LiveDebugValues.cpp
   FaultMaps.cpp
   FuncletLayout.cpp
   GCMetadata.cpp

Modified: llvm/trunk/lib/CodeGen/CodeGen.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/CodeGen.cpp?rev=255759&r1=255758&r2=255759&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/CodeGen.cpp (original)
+++ llvm/trunk/lib/CodeGen/CodeGen.cpp Wed Dec 16 05:09:48 2015
@@ -67,6 +67,7 @@ void llvm::initializeCodeGen(PassRegistr
   initializeSlotIndexesPass(Registry);
   initializeStackColoringPass(Registry);
   initializeStackMapLivenessPass(Registry);
+  initializeLiveDebugValuesPass(Registry);
   initializeStackProtectorPass(Registry);
   initializeStackSlotColoringPass(Registry);
   initializeTailDuplicatePassPass(Registry);

Added: llvm/trunk/lib/CodeGen/LiveDebugValues.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/LiveDebugValues.cpp?rev=255759&view=auto
==============================================================================
--- llvm/trunk/lib/CodeGen/LiveDebugValues.cpp (added)
+++ llvm/trunk/lib/CodeGen/LiveDebugValues.cpp Wed Dec 16 05:09:48 2015
@@ -0,0 +1,405 @@
+//===------ LiveDebugValues.cpp - Tracking Debug Value MIs ----------------===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+///
+/// This pass implements a data flow analysis that propagates debug location
+/// information by inserting additional DBG_VALUE instructions into the machine
+/// instruction stream. The pass internally builds debug location liveness
+/// ranges to determine the points where additional DBG_VALUEs need to be
+/// inserted.
+///
+/// This is a separate pass from DbgValueHistoryCalculator to facilitate
+/// testing and improve modularity.
+///
+//===----------------------------------------------------------------------===//
+
+#include "llvm/ADT/Statistic.h"
+#include "llvm/ADT/SmallVector.h"
+#include "llvm/CodeGen/MachineFunction.h"
+#include "llvm/CodeGen/MachineFunctionPass.h"
+#include "llvm/CodeGen/MachineInstrBuilder.h"
+#include "llvm/CodeGen/Passes.h"
+#include "llvm/Support/CommandLine.h"
+#include "llvm/Support/Debug.h"
+#include "llvm/Support/raw_ostream.h"
+#include "llvm/Target/TargetInstrInfo.h"
+#include "llvm/Target/TargetRegisterInfo.h"
+#include "llvm/Target/TargetSubtargetInfo.h"
+#include <deque>
+#include <list>
+
+using namespace llvm;
+
+#define DEBUG_TYPE "live-debug-values"
+
+STATISTIC(NumInserted, "Number of DBG_VALUE instructions inserted");
+
+namespace {
+
+class LiveDebugValues : public MachineFunctionPass {
+
+private:
+  const TargetRegisterInfo *TRI;
+  const TargetInstrInfo *TII;
+
+  typedef std::pair<const DILocalVariable *, const DILocation *>
+      InlinedVariable;
+
+  /// A potentially inlined instance of a variable.
+  struct DebugVariable {
+    const DILocalVariable *Var;
+    const DILocation *InlinedAt;
+
+    DebugVariable(const DILocalVariable *_var, const DILocation *_inlinedAt)
+        : Var(_var), InlinedAt(_inlinedAt) {}
+
+    bool operator==(const DebugVariable &DV) const {
+      return (Var == DV.Var) && (InlinedAt == DV.InlinedAt);
+    }
+  };
+
+  /// Member variables and functions for Range Extension across basic blocks.
+  struct VarLoc {
+    DebugVariable Var;
+    const MachineInstr *MI; // MachineInstr should be a DBG_VALUE instr.
+
+    VarLoc(DebugVariable _var, const MachineInstr *_mi) : Var(_var), MI(_mi) {}
+
+    bool operator==(const VarLoc &V) const;
+  };
+
+  typedef std::list<VarLoc> VarLocList;
+  typedef SmallDenseMap<const MachineBasicBlock *, VarLocList> VarLocInMBB;
+
+  bool OLChanged; // OutgoingLocs got changed for this bb.
+  bool MBBJoined; // The MBB was joined.
+
+  void transferDebugValue(MachineInstr &MI, VarLocList &OpenRanges);
+  void transferRegisterDef(MachineInstr &MI, VarLocList &OpenRanges);
+  void transferTerminatorInst(MachineInstr &MI, VarLocList &OpenRanges,
+                              VarLocInMBB &OutLocs);
+  void transfer(MachineInstr &MI, VarLocList &OpenRanges, VarLocInMBB &OutLocs);
+
+  void join(MachineBasicBlock &MBB, VarLocInMBB &OutLocs, VarLocInMBB &InLocs);
+
+  bool ExtendRanges(MachineFunction &MF);
+
+public:
+  static char ID;
+
+  /// Default construct and initialize the pass.
+  LiveDebugValues();
+
+  /// Tell the pass manager which passes we depend on and what
+  /// information we preserve.
+  void getAnalysisUsage(AnalysisUsage &AU) const override;
+
+  /// Print to ostream with a message.
+  void printVarLocInMBB(const VarLocInMBB &V, const char *msg,
+                        raw_ostream &Out) const;
+
+  /// Calculate the liveness information for the given machine function.
+  bool runOnMachineFunction(MachineFunction &MF) override;
+};
+} // namespace
+
+//===----------------------------------------------------------------------===//
+//            Implementation
+//===----------------------------------------------------------------------===//
+
+char LiveDebugValues::ID = 0;
+char &llvm::LiveDebugValuesID = LiveDebugValues::ID;
+INITIALIZE_PASS(LiveDebugValues, "livedebugvalues", "Live DEBUG_VALUE analysis",
+                false, false)
+
+/// Default construct and initialize the pass.
+LiveDebugValues::LiveDebugValues() : MachineFunctionPass(ID) {
+  initializeLiveDebugValuesPass(*PassRegistry::getPassRegistry());
+}
+
+/// Tell the pass manager which passes we depend on and what information we
+/// preserve.
+void LiveDebugValues::getAnalysisUsage(AnalysisUsage &AU) const {
+  MachineFunctionPass::getAnalysisUsage(AU);
+}
+
+// \brief If @MI is a DBG_VALUE with debug value described by a defined
+// register, returns the number of this register. In the other case, returns 0.
+static unsigned isDescribedByReg(const MachineInstr &MI) {
+  assert(MI.isDebugValue());
+  assert(MI.getNumOperands() == 4);
+  // If location of variable is described using a register (directly or
+  // indirecltly), this register is always a first operand.
+  return MI.getOperand(0).isReg() ? MI.getOperand(0).getReg() : 0;
+}
+
+// \brief This function takes two DBG_VALUE instructions and returns true
+// if their offsets are equal; otherwise returns false.
+static bool areOffsetsEqual(const MachineInstr &MI1, const MachineInstr &MI2) {
+  assert(MI1.isDebugValue());
+  assert(MI1.getNumOperands() == 4);
+
+  assert(MI2.isDebugValue());
+  assert(MI2.getNumOperands() == 4);
+
+  if (!MI1.isIndirectDebugValue() && !MI2.isIndirectDebugValue())
+    return true;
+
+  // Check if both MIs are indirect and they are equal.
+  if (MI1.isIndirectDebugValue() && MI2.isIndirectDebugValue())
+    return MI1.getOperand(1).getImm() == MI2.getOperand(1).getImm();
+
+  return false;
+}
+
+//===----------------------------------------------------------------------===//
+//            Debug Range Extension Implementation
+//===----------------------------------------------------------------------===//
+
+void LiveDebugValues::printVarLocInMBB(const VarLocInMBB &V, const char *msg,
+                                       raw_ostream &Out) const {
+  Out << "Printing " << msg << ":\n";
+  for (const auto &L : V) {
+    Out << "MBB: " << L.first->getName() << ":\n";
+    for (const auto &VLL : L.second) {
+      Out << " Var: " << VLL.Var.Var->getName();
+      Out << " MI: ";
+      (*VLL.MI).dump();
+      Out << "\n";
+    }
+  }
+  Out << "\n";
+}
+
+bool LiveDebugValues::VarLoc::operator==(const VarLoc &V) const {
+  return (Var == V.Var) && (isDescribedByReg(*MI) == isDescribedByReg(*V.MI)) &&
+         (areOffsetsEqual(*MI, *V.MI));
+}
+
+/// End all previous ranges related to @MI and start a new range from @MI
+/// if it is a DBG_VALUE instr.
+void LiveDebugValues::transferDebugValue(MachineInstr &MI,
+                                         VarLocList &OpenRanges) {
+  if (!MI.isDebugValue())
+    return;
+  const DILocalVariable *RawVar = MI.getDebugVariable();
+  assert(RawVar->isValidLocationForIntrinsic(MI.getDebugLoc()) &&
+         "Expected inlined-at fields to agree");
+  DebugVariable Var(RawVar, MI.getDebugLoc()->getInlinedAt());
+
+  // End all previous ranges of Var.
+  OpenRanges.erase(
+      std::remove_if(OpenRanges.begin(), OpenRanges.end(),
+                     [&](const VarLoc &V) { return (Var == V.Var); }),
+      OpenRanges.end());
+
+  // Add Var to OpenRanges from this DBG_VALUE.
+  // TODO: Currently handles DBG_VALUE which has only reg as location.
+  if (isDescribedByReg(MI)) {
+    VarLoc V(Var, &MI);
+    OpenRanges.push_back(std::move(V));
+  }
+}
+
+/// A definition of a register may mark the end of a range.
+void LiveDebugValues::transferRegisterDef(MachineInstr &MI,
+                                          VarLocList &OpenRanges) {
+  for (const MachineOperand &MO : MI.operands()) {
+    if (!(MO.isReg() && MO.isDef() && MO.getReg() &&
+          TRI->isPhysicalRegister(MO.getReg())))
+      continue;
+    // Remove ranges of all aliased registers.
+    for (MCRegAliasIterator RAI(MO.getReg(), TRI, true); RAI.isValid(); ++RAI)
+      OpenRanges.erase(std::remove_if(OpenRanges.begin(), OpenRanges.end(),
+                                      [&](const VarLoc &V) {
+                                        return (*RAI ==
+                                                isDescribedByReg(*V.MI));
+                                      }),
+                       OpenRanges.end());
+  }
+}
+
+/// Terminate all open ranges at the end of the current basic block.
+void LiveDebugValues::transferTerminatorInst(MachineInstr &MI,
+                                             VarLocList &OpenRanges,
+                                             VarLocInMBB &OutLocs) {
+  const MachineBasicBlock *CurMBB = MI.getParent();
+  if (!(MI.isTerminator() || (&MI == &CurMBB->instr_back())))
+    return;
+
+  if (OpenRanges.empty())
+    return;
+
+  if (OutLocs.find(CurMBB) == OutLocs.end()) {
+    // Create space for new Outgoing locs entries.
+    VarLocList VLL;
+    OutLocs.insert(std::make_pair(CurMBB, std::move(VLL)));
+  }
+  auto OL = OutLocs.find(CurMBB);
+  assert(OL != OutLocs.end());
+  VarLocList &VLL = OL->second;
+
+  for (auto OR : OpenRanges) {
+    // Copy OpenRanges to OutLocs, if not already present.
+    assert(OR.MI->isDebugValue());
+    DEBUG(dbgs() << "Add to OutLocs: "; OR.MI->dump(););
+    if (std::find_if(VLL.begin(), VLL.end(),
+                     [&](const VarLoc &V) { return (OR == V); }) == VLL.end()) {
+      VLL.push_back(std::move(OR));
+      OLChanged = true;
+    }
+  }
+  OpenRanges.clear();
+}
+
+/// This routine creates OpenRanges and OutLocs.
+void LiveDebugValues::transfer(MachineInstr &MI, VarLocList &OpenRanges,
+                               VarLocInMBB &OutLocs) {
+  transferDebugValue(MI, OpenRanges);
+  transferRegisterDef(MI, OpenRanges);
+  transferTerminatorInst(MI, OpenRanges, OutLocs);
+}
+
+/// This routine joins the analysis results of all incoming edges in @MBB by
+/// inserting a new DBG_VALUE instruction at the start of the @MBB - if the same
+/// source variable in all the predecessors of @MBB reside in the same location.
+void LiveDebugValues::join(MachineBasicBlock &MBB, VarLocInMBB &OutLocs,
+                           VarLocInMBB &InLocs) {
+  DEBUG(dbgs() << "join MBB: " << MBB.getName() << "\n");
+
+  MBBJoined = false;
+
+  VarLocList InLocsT; // Temporary incoming locations.
+
+  // For all predecessors of this MBB, find the set of VarLocs that can be
+  // joined.
+  for (auto p : MBB.predecessors()) {
+    auto OL = OutLocs.find(p);
+    // Join is null in case of empty OutLocs from any of the pred.
+    if (OL == OutLocs.end())
+      return;
+
+    // Just copy over the Out locs to incoming locs for the first predecessor.
+    if (p == *MBB.pred_begin()) {
+      InLocsT = OL->second;
+      continue;
+    }
+
+    // Join with this predecessor.
+    VarLocList &VLL = OL->second;
+    InLocsT.erase(std::remove_if(InLocsT.begin(), InLocsT.end(),
+                                 [&](VarLoc &ILT) {
+                                   return (std::find_if(VLL.begin(), VLL.end(),
+                                                        [&](const VarLoc &V) {
+                                                          return (ILT == V);
+                                                        }) == VLL.end());
+                                 }),
+                  InLocsT.end());
+  }
+
+  if (InLocsT.empty())
+    return;
+
+  if (InLocs.find(&MBB) == InLocs.end()) {
+    // Create space for new Incoming locs entries.
+    VarLocList VLL;
+    InLocs.insert(std::make_pair(&MBB, std::move(VLL)));
+  }
+  auto IL = InLocs.find(&MBB);
+  assert(IL != InLocs.end());
+  VarLocList &ILL = IL->second;
+
+  // Insert DBG_VALUE instructions, if not already inserted.
+  for (auto ILT : InLocsT) {
+    if (std::find_if(ILL.begin(), ILL.end(), [&](const VarLoc &I) {
+          return (ILT == I);
+        }) == ILL.end()) {
+      // This VarLoc is not found in InLocs i.e. it is not yet inserted. So, a
+      // new range is started for the var from the mbb's beginning by inserting
+      // a new DBG_VALUE. transfer() will end this range however appropriate.
+      const MachineInstr *DMI = ILT.MI;
+      MachineInstr *MI =
+          BuildMI(MBB, MBB.instr_begin(), DMI->getDebugLoc(), DMI->getDesc(),
+                  DMI->isIndirectDebugValue(), DMI->getOperand(0).getReg(), 0,
+                  DMI->getDebugVariable(), DMI->getDebugExpression());
+      if (DMI->isIndirectDebugValue())
+        MI->getOperand(1).setImm(DMI->getOperand(1).getImm());
+      DEBUG(dbgs() << "Inserted: "; MI->dump(););
+      ++NumInserted;
+      MBBJoined = true; // rerun transfer().
+
+      VarLoc V(ILT.Var, MI);
+      ILL.push_back(std::move(V));
+    }
+  }
+}
+
+/// Calculate the liveness information for the given machine function and
+/// extend ranges across basic blocks.
+bool LiveDebugValues::ExtendRanges(MachineFunction &MF) {
+
+  DEBUG(dbgs() << "\nDebug Range Extension\n");
+
+  bool Changed = false;
+  OLChanged = MBBJoined = false;
+
+  VarLocList OpenRanges; // Ranges that are open until end of bb.
+  VarLocInMBB OutLocs;   // Ranges that exist beyond bb.
+  VarLocInMBB InLocs;    // Ranges that are incoming after joining.
+
+  std::deque<MachineBasicBlock *> BBWorklist;
+
+  // Initialize every mbb with OutLocs.
+  for (auto &MBB : MF)
+    for (auto &MI : MBB)
+      transfer(MI, OpenRanges, OutLocs);
+  DEBUG(printVarLocInMBB(OutLocs, "OutLocs after initialization", dbgs()));
+
+  // Construct a worklist of MBBs.
+  for (auto &MBB : MF)
+    BBWorklist.push_back(&MBB);
+
+  // Perform join() and transfer() using the worklist until the ranges converge
+  // Ranges have converged when the worklist is empty.
+  while (!BBWorklist.empty()) {
+    MachineBasicBlock *MBB = BBWorklist.front();
+    BBWorklist.pop_front();
+
+    join(*MBB, OutLocs, InLocs);
+
+    if (MBBJoined) {
+      Changed = true;
+      for (auto &MI : *MBB)
+        transfer(MI, OpenRanges, OutLocs);
+      DEBUG(printVarLocInMBB(OutLocs, "OutLocs after propagating", dbgs()));
+      DEBUG(printVarLocInMBB(InLocs, "InLocs after propagating", dbgs()));
+
+      if (OLChanged) {
+        OLChanged = false;
+        for (auto s : MBB->successors())
+          if (std::find(BBWorklist.begin(), BBWorklist.end(), s) ==
+              BBWorklist.end()) // add if not already present.
+            BBWorklist.push_back(s);
+      }
+    }
+  }
+  DEBUG(printVarLocInMBB(OutLocs, "Final OutLocs", dbgs()));
+  DEBUG(printVarLocInMBB(InLocs, "Final InLocs", dbgs()));
+  return Changed;
+}
+
+bool LiveDebugValues::runOnMachineFunction(MachineFunction &MF) {
+  TRI = MF.getSubtarget().getRegisterInfo();
+  TII = MF.getSubtarget().getInstrInfo();
+
+  bool Changed = false;
+
+  Changed |= ExtendRanges(MF);
+
+  return Changed;
+}

Modified: llvm/trunk/lib/CodeGen/Passes.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/Passes.cpp?rev=255759&r1=255758&r2=255759&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/Passes.cpp (original)
+++ llvm/trunk/lib/CodeGen/Passes.cpp Wed Dec 16 05:09:48 2015
@@ -600,6 +600,7 @@ void TargetPassConfig::addMachinePasses(
   addPass(&FuncletLayoutID, false);
 
   addPass(&StackMapLivenessID, false);
+  addPass(&LiveDebugValuesID, false);
 
   AddingMachinePasses = false;
 }

Added: llvm/trunk/test/DebugInfo/MIR/X86/lit.local.cfg
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/DebugInfo/MIR/X86/lit.local.cfg?rev=255759&view=auto
==============================================================================
--- llvm/trunk/test/DebugInfo/MIR/X86/lit.local.cfg (added)
+++ llvm/trunk/test/DebugInfo/MIR/X86/lit.local.cfg Wed Dec 16 05:09:48 2015
@@ -0,0 +1,2 @@
+if not 'X86' in config.root.targets:
+    config.unsupported = True

Added: llvm/trunk/test/DebugInfo/MIR/X86/live-debug-values-3preds.mir
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/DebugInfo/MIR/X86/live-debug-values-3preds.mir?rev=255759&view=auto
==============================================================================
--- llvm/trunk/test/DebugInfo/MIR/X86/live-debug-values-3preds.mir (added)
+++ llvm/trunk/test/DebugInfo/MIR/X86/live-debug-values-3preds.mir Wed Dec 16 05:09:48 2015
@@ -0,0 +1,299 @@
+# RUN: llc -run-pass=livedebugvalues -march=x86-64 -o /dev/null %s | FileCheck %s
+
+# Test the extension of debug ranges from 3 predecessors.
+# Generated from the source file LiveDebugValues-3preds.c:
+# #include <stdio.h>
+# int add(int x, int y, int z, int a) {
+#  int i;
+#  for (i = 0; i < x * y; i++) {
+#    if (i < x) {
+#      a = a * x;
+#      break;
+#    }
+#    if (i < y) {
+#      a = a * y;
+#      break;
+#    }
+#    if (i < z) {
+#      a = a * z;
+#      break;
+#    }
+#  }
+#  return a;
+# }
+# with clang -g -O1 -c -emit-llvm LiveDebugValues-3preds.c -S -o live-debug-values-3preds.ll
+# then llc -stop-after stackmap-liveness live-debug-values-3preds.ll -o /dev/null > live-debug-values-3preds.mir
+
+# DBG_VALUE for variables "x", "y" and "z" are extended into BB#9 from its
+# predecessors BB#0, BB#2 and BB#8.
+# CHECK:      bb.9.for.end:
+# CHECK:      DBG_VALUE debug-use %edx, debug-use _, !11, !17, debug-location !21
+# CHECK-NEXT: DBG_VALUE debug-use %esi, debug-use _, !10, !17, debug-location !19
+# CHECK-NEXT: DBG_VALUE debug-use %edi, debug-use _, !9, !17, debug-location !18
+
+
+--- |
+  ; ModuleID = 'live-debug-values-3preds.ll'
+  target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
+  target triple = "x86_64-unknown-linux-gnu"
+  
+  ; Function Attrs: norecurse nounwind readnone uwtable
+  define i32 @add(i32 %x, i32 %y, i32 %z, i32 %a) #0 !dbg !4 {
+  entry:
+    tail call void @llvm.dbg.value(metadata i32 %x, i64 0, metadata !9, metadata !17), !dbg !18
+    tail call void @llvm.dbg.value(metadata i32 %y, i64 0, metadata !10, metadata !17), !dbg !19
+    tail call void @llvm.dbg.value(metadata i32 %z, i64 0, metadata !11, metadata !17), !dbg !21
+    tail call void @llvm.dbg.value(metadata i32 %a, i64 0, metadata !12, metadata !17), !dbg !23
+    tail call void @llvm.dbg.value(metadata i32 0, i64 0, metadata !13, metadata !17), !dbg !25
+    %mul = mul nsw i32 %y, %x, !dbg !26
+    %cmp.24 = icmp sgt i32 %mul, 0, !dbg !30
+    br i1 %cmp.24, label %for.body.preheader, label %for.end, !dbg !31
+  
+  for.body.preheader:                               ; preds = %entry
+    br label %for.body, !dbg !32
+  
+  for.cond:                                         ; preds = %if.end.6
+    %cmp = icmp slt i32 %inc, %mul, !dbg !30
+    br i1 %cmp, label %for.body, label %for.end, !dbg !31
+  
+  for.body:                                         ; preds = %for.cond, %for.body.preheader
+    %i.025 = phi i32 [ %inc, %for.cond ], [ 0, %for.body.preheader ]
+    %0 = icmp sgt i32 %x, 0
+    br i1 %0, label %if.then, label %if.end, !dbg !35
+  
+  if.then:                                          ; preds = %for.body
+    %mul2 = mul nsw i32 %a, %x, !dbg !36
+    tail call void @llvm.dbg.value(metadata i32 %mul2, i64 0, metadata !12, metadata !17), !dbg !23
+    br label %for.end, !dbg !38
+  
+  if.end:                                           ; preds = %for.body
+    %1 = icmp sgt i32 %y, 0
+    br i1 %1, label %if.then.4, label %if.end.6, !dbg !39
+  
+  if.then.4:                                        ; preds = %if.end
+    %mul5 = mul nsw i32 %a, %y, !dbg !40
+    tail call void @llvm.dbg.value(metadata i32 %mul5, i64 0, metadata !12, metadata !17), !dbg !23
+    br label %for.end, !dbg !43
+  
+  if.end.6:                                         ; preds = %if.end
+    %2 = icmp sgt i32 %z, 0
+    %inc = add nuw nsw i32 %i.025, 1, !dbg !44
+    tail call void @llvm.dbg.value(metadata i32 %inc, i64 0, metadata !13, metadata !17), !dbg !25
+    br i1 %2, label %if.then.8, label %for.cond, !dbg !45
+  
+  if.then.8:                                        ; preds = %if.end.6
+    %mul9 = mul nsw i32 %a, %z, !dbg !46
+    tail call void @llvm.dbg.value(metadata i32 %mul9, i64 0, metadata !12, metadata !17), !dbg !23
+    br label %for.end, !dbg !49
+  
+  for.end:                                          ; preds = %for.cond, %if.then.8, %if.then.4, %if.then, %entry
+    %a.addr.0 = phi i32 [ %mul2, %if.then ], [ %mul5, %if.then.4 ], [ %mul9, %if.then.8 ], [ %a, %entry ], [ %a, %for.cond ]
+    ret i32 %a.addr.0, !dbg !50
+  }
+  
+  ; Function Attrs: nounwind readnone
+  declare void @llvm.dbg.value(metadata, i64, metadata, metadata) #1
+  
+  attributes #0 = { norecurse nounwind readnone uwtable }
+  attributes #1 = { nounwind readnone }
+  
+  !llvm.dbg.cu = !{!0}
+  !llvm.module.flags = !{!14, !15}
+  !llvm.ident = !{!16}
+  
+  !0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 3.8.0 (trunk 253049) ", isOptimized: true, runtimeVersion: 0, emissionKind: 1, enums: !2, subprograms: !3)
+  !1 = !DIFile(filename: "LiveDebugValues-3preds.c", directory: "/home/vt/julia/test/tvvikram")
+  !2 = !{}
+  !3 = !{!4}
+  !4 = distinct !DISubprogram(name: "add", scope: !1, file: !1, line: 1, type: !5, isLocal: false, isDefinition: true, scopeLine: 1, flags: DIFlagPrototyped, isOptimized: true, variables: !8)
+  !5 = !DISubroutineType(types: !6)
+  !6 = !{!7, !7, !7, !7, !7}
+  !7 = !DIBasicType(name: "int", size: 32, align: 32, encoding: DW_ATE_signed)
+  !8 = !{!9, !10, !11, !12, !13}
+  !9 = !DILocalVariable(name: "x", arg: 1, scope: !4, file: !1, line: 1, type: !7)
+  !10 = !DILocalVariable(name: "y", arg: 2, scope: !4, file: !1, line: 1, type: !7)
+  !11 = !DILocalVariable(name: "z", arg: 3, scope: !4, file: !1, line: 1, type: !7)
+  !12 = !DILocalVariable(name: "a", arg: 4, scope: !4, file: !1, line: 1, type: !7)
+  !13 = !DILocalVariable(name: "i", scope: !4, file: !1, line: 2, type: !7)
+  !14 = !{i32 2, !"Dwarf Version", i32 4}
+  !15 = !{i32 2, !"Debug Info Version", i32 3}
+  !16 = !{!"clang version 3.8.0 (trunk 253049) "}
+  !17 = !DIExpression()
+  !18 = !DILocation(line: 1, column: 13, scope: !4)
+  !19 = !DILocation(line: 1, column: 20, scope: !20)
+  !20 = !DILexicalBlockFile(scope: !4, file: !1, discriminator: 1)
+  !21 = !DILocation(line: 1, column: 27, scope: !22)
+  !22 = !DILexicalBlockFile(scope: !4, file: !1, discriminator: 2)
+  !23 = !DILocation(line: 1, column: 34, scope: !24)
+  !24 = !DILexicalBlockFile(scope: !4, file: !1, discriminator: 3)
+  !25 = !DILocation(line: 2, column: 7, scope: !20)
+  !26 = !DILocation(line: 3, column: 21, scope: !27)
+  !27 = !DILexicalBlockFile(scope: !28, file: !1, discriminator: 1)
+  !28 = distinct !DILexicalBlock(scope: !29, file: !1, line: 3, column: 3)
+  !29 = distinct !DILexicalBlock(scope: !4, file: !1, line: 3, column: 3)
+  !30 = !DILocation(line: 3, column: 17, scope: !27)
+  !31 = !DILocation(line: 3, column: 3, scope: !27)
+  !32 = !DILocation(line: 4, column: 11, scope: !33)
+  !33 = distinct !DILexicalBlock(scope: !34, file: !1, line: 4, column: 9)
+  !34 = distinct !DILexicalBlock(scope: !28, file: !1, line: 3, column: 31)
+  !35 = !DILocation(line: 4, column: 9, scope: !34)
+  !36 = !DILocation(line: 5, column: 13, scope: !37)
+  !37 = distinct !DILexicalBlock(scope: !33, file: !1, line: 4, column: 16)
+  !38 = !DILocation(line: 6, column: 7, scope: !37)
+  !39 = !DILocation(line: 8, column: 9, scope: !34)
+  !40 = !DILocation(line: 9, column: 13, scope: !41)
+  !41 = distinct !DILexicalBlock(scope: !42, file: !1, line: 8, column: 16)
+  !42 = distinct !DILexicalBlock(scope: !34, file: !1, line: 8, column: 9)
+  !43 = !DILocation(line: 10, column: 7, scope: !41)
+  !44 = !DILocation(line: 3, column: 27, scope: !28)
+  !45 = !DILocation(line: 12, column: 9, scope: !34)
+  !46 = !DILocation(line: 13, column: 13, scope: !47)
+  !47 = distinct !DILexicalBlock(scope: !48, file: !1, line: 12, column: 16)
+  !48 = distinct !DILexicalBlock(scope: !34, file: !1, line: 12, column: 9)
+  !49 = !DILocation(line: 14, column: 7, scope: !47)
+  !50 = !DILocation(line: 17, column: 3, scope: !4)
+
+...
+---
+name:            add
+alignment:       4
+exposesReturnsTwice: false
+hasInlineAsm:    false
+isSSA:           false
+tracksRegLiveness: true
+tracksSubRegLiveness: false
+liveins:         
+  - { reg: '%edi' }
+  - { reg: '%esi' }
+  - { reg: '%edx' }
+  - { reg: '%ecx' }
+frameInfo:       
+  isFrameAddressTaken: false
+  isReturnAddressTaken: false
+  hasStackMap:     false
+  hasPatchPoint:   false
+  stackSize:       0
+  offsetAdjustment: 0
+  maxAlignment:    0
+  adjustsStack:    false
+  hasCalls:        false
+  maxCallFrameSize: 0
+  hasOpaqueSPAdjustment: false
+  hasVAStart:      false
+  hasMustTailInVarArgFunc: false
+body:             |
+  bb.0.entry:
+    successors: %bb.1.for.body.preheader(20), %bb.9.for.end(12)
+    liveins: %ecx, %edi, %edx, %esi
+  
+    DBG_VALUE debug-use %edi, debug-use _, !9, !17, debug-location !18
+    DBG_VALUE debug-use %esi, debug-use _, !10, !17, debug-location !19
+    DBG_VALUE debug-use %edx, debug-use _, !11, !17, debug-location !21
+    DBG_VALUE debug-use %ecx, debug-use _, !12, !17, debug-location !23
+    DBG_VALUE 0, 0, !13, !17, debug-location !25
+    %r8d = MOV32rr %esi, debug-location !26
+    %r8d = IMUL32rr killed %r8d, %edi, implicit-def dead %eflags, debug-location !26
+    TEST32rr %r8d, %r8d, implicit-def %eflags, debug-location !31
+    JLE_1 %bb.9.for.end, implicit %eflags
+  
+  bb.1.for.body.preheader:
+    successors: %bb.3.for.body(0)
+    liveins: %ecx, %edi, %edx, %esi, %r8d
+  
+    DBG_VALUE debug-use %edi, debug-use _, !9, !17, debug-location !18
+    DBG_VALUE debug-use %esi, debug-use _, !10, !17, debug-location !19
+    DBG_VALUE debug-use %edx, debug-use _, !11, !17, debug-location !21
+    DBG_VALUE debug-use %ecx, debug-use _, !12, !17, debug-location !23
+    DBG_VALUE 0, 0, !13, !17, debug-location !25
+    %eax = XOR32rr undef %eax, undef %eax, implicit-def dead %eflags
+  
+  bb.3.for.body (align 4):
+    successors: %bb.4.if.then(4), %bb.5.if.end(124)
+    liveins: %eax, %ecx, %edi, %edx, %esi, %r8d
+  
+    DBG_VALUE debug-use %edi, debug-use _, !9, !17, debug-location !18
+    DBG_VALUE debug-use %esi, debug-use _, !10, !17, debug-location !19
+    DBG_VALUE debug-use %edx, debug-use _, !11, !17, debug-location !21
+    DBG_VALUE debug-use %ecx, debug-use _, !12, !17, debug-location !23
+    DBG_VALUE 0, 0, !13, !17, debug-location !25
+    TEST32rr %edi, %edi, implicit-def %eflags, debug-location !35
+    JG_1 %bb.4.if.then, implicit %eflags
+  
+  bb.5.if.end:
+    successors: %bb.6.if.then.4(4), %bb.7.if.end.6(124)
+    liveins: %eax, %ecx, %edi, %edx, %esi, %r8d
+  
+    DBG_VALUE debug-use %edi, debug-use _, !9, !17, debug-location !18
+    DBG_VALUE debug-use %esi, debug-use _, !10, !17, debug-location !19
+    DBG_VALUE debug-use %edx, debug-use _, !11, !17, debug-location !21
+    DBG_VALUE debug-use %ecx, debug-use _, !12, !17, debug-location !23
+    DBG_VALUE 0, 0, !13, !17, debug-location !25
+    TEST32rr %esi, %esi, implicit-def %eflags, debug-location !39
+    JG_1 %bb.6.if.then.4, implicit %eflags
+  
+  bb.7.if.end.6:
+    successors: %bb.8.if.then.8(4), %bb.2.for.cond(124)
+    liveins: %eax, %ecx, %edi, %edx, %esi, %r8d
+  
+    DBG_VALUE debug-use %edi, debug-use _, !9, !17, debug-location !18
+    DBG_VALUE debug-use %esi, debug-use _, !10, !17, debug-location !19
+    DBG_VALUE debug-use %edx, debug-use _, !11, !17, debug-location !21
+    DBG_VALUE debug-use %ecx, debug-use _, !12, !17, debug-location !23
+    DBG_VALUE 0, 0, !13, !17, debug-location !25
+    TEST32rr %edx, %edx, implicit-def %eflags, debug-location !45
+    JG_1 %bb.8.if.then.8, implicit %eflags
+  
+  bb.2.for.cond:
+    successors: %bb.3.for.body(124), %bb.9.for.end(4)
+    liveins: %eax, %ecx, %edi, %edx, %esi, %r8d
+  
+    DBG_VALUE debug-use %edi, debug-use _, !9, !17, debug-location !18
+    DBG_VALUE debug-use %esi, debug-use _, !10, !17, debug-location !19
+    DBG_VALUE debug-use %edx, debug-use _, !11, !17, debug-location !21
+    DBG_VALUE debug-use %ecx, debug-use _, !12, !17, debug-location !23
+    DBG_VALUE 0, 0, !13, !17, debug-location !25
+    %eax = INC32r killed %eax, implicit-def dead %eflags, debug-location !44
+    DBG_VALUE debug-use %eax, debug-use _, !13, !17, debug-location !25
+    CMP32rr %eax, %r8d, implicit-def %eflags, debug-location !31
+    JL_1 %bb.3.for.body, implicit %eflags
+    JMP_1 %bb.9.for.end
+  
+  bb.4.if.then:
+    liveins: %ecx, %edi
+  
+    DBG_VALUE debug-use %edi, debug-use _, !9, !17, debug-location !18
+    DBG_VALUE debug-use %ecx, debug-use _, !12, !17, debug-location !23
+    DBG_VALUE 0, 0, !13, !17, debug-location !25
+    %ecx = IMUL32rr killed %ecx, killed %edi, implicit-def dead %eflags, debug-location !36
+    DBG_VALUE 0, 0, !13, !17, debug-location !25
+    %eax = MOV32rr killed %ecx, debug-location !50
+    RETQ %eax, debug-location !50
+  
+  bb.6.if.then.4:
+    liveins: %ecx, %esi
+  
+    DBG_VALUE debug-use %esi, debug-use _, !10, !17, debug-location !19
+    DBG_VALUE debug-use %ecx, debug-use _, !12, !17, debug-location !23
+    DBG_VALUE 0, 0, !13, !17, debug-location !25
+    %ecx = IMUL32rr killed %ecx, killed %esi, implicit-def dead %eflags, debug-location !40
+    DBG_VALUE 0, 0, !13, !17, debug-location !25
+    %eax = MOV32rr killed %ecx, debug-location !50
+    RETQ %eax, debug-location !50
+  
+  bb.8.if.then.8:
+    successors: %bb.9.for.end(0)
+    liveins: %ecx, %edx
+  
+    DBG_VALUE debug-use %edx, debug-use _, !11, !17, debug-location !21
+    DBG_VALUE debug-use %ecx, debug-use _, !12, !17, debug-location !23
+    DBG_VALUE 0, 0, !13, !17, debug-location !25
+    %ecx = IMUL32rr killed %ecx, killed %edx, implicit-def dead %eflags, debug-location !46
+  
+  bb.9.for.end:
+    liveins: %ecx
+  
+    DBG_VALUE 0, 0, !13, !17, debug-location !25
+    %eax = MOV32rr killed %ecx, debug-location !50
+    RETQ %eax, debug-location !50
+
+...

Added: llvm/trunk/test/DebugInfo/MIR/X86/live-debug-values.mir
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/DebugInfo/MIR/X86/live-debug-values.mir?rev=255759&view=auto
==============================================================================
--- llvm/trunk/test/DebugInfo/MIR/X86/live-debug-values.mir (added)
+++ llvm/trunk/test/DebugInfo/MIR/X86/live-debug-values.mir Wed Dec 16 05:09:48 2015
@@ -0,0 +1,260 @@
+# RUN: llc -run-pass=livedebugvalues -march=x86-64 -o /dev/null %s | FileCheck %s
+
+# Test the extension of debug ranges from predecessors.
+# Generated from the source file LiveDebugValues.c:
+# #include <stdio.h>
+# int m;
+# extern int inc(int n); 
+# extern int change(int n); 
+# extern int modify(int n); 
+# int main(int argc, char **argv) {
+#   int n;
+#   if (argc != 2)
+#     n = 2;
+#   else
+#     n = atoi(argv[1]);
+#   n = change(n);
+#   if (n > 10) {
+#     m = modify(n);
+#     m = m + n;  // var `m' doesn't has a dbg.value
+#   }   
+#   else
+#     m = inc(n); // var `m' doesn't has a dbg.value
+#   printf("m(main): %d\n", m); 
+#   return 0;
+# }
+# with clang -g -O3 -c -emit-llvm LiveDebugValues.c -S -o live-debug-values.ll
+# then llc -stop-after stackmap-liveness live-debug-values.ll -o /dev/null > live-debug-values.mir
+# This case will also produce multiple locations but only the debug range
+# extension is tested here. This test case is tested with DWARF information under
+# llvm/test/DebugInfo/live-debug-values.ll and present here for testing under
+# MIR->MIR serialization.
+
+# DBG_VALUE for variable "n" is extended into BB#5 from its predecessors BB#3
+# and BB#4.
+# CHECK:      bb.5.if.end.7:
+# CHECK:      DBG_VALUE debug-use %rsi, debug-use _, !13, !20, debug-location !22
+# CHECK-NEXT: DBG_VALUE debug-use %ebx, debug-use _, !14, !20, debug-location !33
+
+
+--- |
+  ; ModuleID = 'live-debug-values.ll'
+  target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
+  target triple = "x86_64-unknown-linux-gnu"
+  
+  @m = common global i32 0, align 4
+  @.str = private unnamed_addr constant [13 x i8] c"m(main): %d\0A\00", align 1
+  
+  ; Function Attrs: nounwind uwtable
+  define i32 @main(i32 %argc, i8** nocapture readonly %argv) #0 !dbg !4 {
+  entry:
+    tail call void @llvm.dbg.value(metadata i32 %argc, i64 0, metadata !12, metadata !20), !dbg !21
+    tail call void @llvm.dbg.value(metadata i8** %argv, i64 0, metadata !13, metadata !20), !dbg !22
+    %cmp = icmp eq i32 %argc, 2, !dbg !24
+    br i1 %cmp, label %if.else, label %if.end, !dbg !26
+  
+  if.else:                                          ; preds = %entry
+    %arrayidx = getelementptr inbounds i8*, i8** %argv, i64 1, !dbg !27
+    %0 = load i8*, i8** %arrayidx, align 8, !dbg !27, !tbaa !28
+    %call = tail call i32 (i8*, ...) bitcast (i32 (...)* @atoi to i32 (i8*, ...)*)(i8* %0) #4, !dbg !32
+    tail call void @llvm.dbg.value(metadata i32 %call, i64 0, metadata !14, metadata !20), !dbg !33
+    br label %if.end
+  
+  if.end:                                           ; preds = %if.else, %entry
+    %n.0 = phi i32 [ %call, %if.else ], [ 2, %entry ]
+    %call1 = tail call i32 @change(i32 %n.0) #4, !dbg !34
+    tail call void @llvm.dbg.value(metadata i32 %call1, i64 0, metadata !14, metadata !20), !dbg !33
+    %cmp2 = icmp sgt i32 %call1, 10, !dbg !35
+    br i1 %cmp2, label %if.then.3, label %if.else.5, !dbg !37
+  
+  if.then.3:                                        ; preds = %if.end
+    %call4 = tail call i32 @modify(i32 %call1) #4, !dbg !38
+    %add = add nsw i32 %call4, %call1, !dbg !40
+    br label %if.end.7, !dbg !41
+  
+  if.else.5:                                        ; preds = %if.end
+    %call6 = tail call i32 @inc(i32 %call1) #4, !dbg !42
+    br label %if.end.7
+  
+  if.end.7:                                         ; preds = %if.else.5, %if.then.3
+    %storemerge = phi i32 [ %call6, %if.else.5 ], [ %add, %if.then.3 ]
+    store i32 %storemerge, i32* @m, align 4, !dbg !43, !tbaa !44
+    %call8 = tail call i32 (i8*, ...) @printf(i8* nonnull getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %storemerge) #4, !dbg !46
+    ret i32 0, !dbg !47
+  }
+  
+  declare i32 @atoi(...) #1
+  
+  declare i32 @change(i32) #1
+  
+  declare i32 @modify(i32) #1
+  
+  declare i32 @inc(i32) #1
+  
+  ; Function Attrs: nounwind
+  declare i32 @printf(i8* nocapture readonly, ...) #2
+  
+  ; Function Attrs: nounwind readnone
+  declare void @llvm.dbg.value(metadata, i64, metadata, metadata) #3
+  
+  attributes #0 = { nounwind uwtable }
+  attributes #1 = { nounwind }
+  attributes #2 = { nounwind }
+  attributes #3 = { nounwind readnone }
+  attributes #4 = { nounwind }
+  
+  !llvm.dbg.cu = !{!0}
+  !llvm.module.flags = !{!17, !18}
+  !llvm.ident = !{!19}
+  
+  !0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 3.8.0 (trunk 253049) ", isOptimized: true, runtimeVersion: 0, emissionKind: 1, enums: !2, subprograms: !3, globals: !15)
+  !1 = !DIFile(filename: "LiveDebugValues.c", directory: "/home/vt/julia/test/tvvikram")
+  !2 = !{}
+  !3 = !{!4}
+  !4 = distinct !DISubprogram(name: "main", scope: !1, file: !1, line: 6, type: !5, isLocal: false, isDefinition: true, scopeLine: 6, flags: DIFlagPrototyped, isOptimized: true, variables: !11)
+  !5 = !DISubroutineType(types: !6)
+  !6 = !{!7, !7, !8}
+  !7 = !DIBasicType(name: "int", size: 32, align: 32, encoding: DW_ATE_signed)
+  !8 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !9, size: 64, align: 64)
+  !9 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !10, size: 64, align: 64)
+  !10 = !DIBasicType(name: "char", size: 8, align: 8, encoding: DW_ATE_signed_char)
+  !11 = !{!12, !13, !14}
+  !12 = !DILocalVariable(name: "argc", arg: 1, scope: !4, file: !1, line: 6, type: !7)
+  !13 = !DILocalVariable(name: "argv", arg: 2, scope: !4, file: !1, line: 6, type: !8)
+  !14 = !DILocalVariable(name: "n", scope: !4, file: !1, line: 7, type: !7)
+  !15 = !{!16}
+  !16 = !DIGlobalVariable(name: "m", scope: !0, file: !1, line: 2, type: !7, isLocal: false, isDefinition: true, variable: i32* @m)
+  !17 = !{i32 2, !"Dwarf Version", i32 4}
+  !18 = !{i32 2, !"Debug Info Version", i32 3}
+  !19 = !{!"clang version 3.8.0 (trunk 253049)"}
+  !20 = !DIExpression()
+  !21 = !DILocation(line: 6, column: 14, scope: !4)
+  !22 = !DILocation(line: 6, column: 27, scope: !23)
+  !23 = !DILexicalBlockFile(scope: !4, file: !1, discriminator: 1)
+  !24 = !DILocation(line: 8, column: 12, scope: !25)
+  !25 = distinct !DILexicalBlock(scope: !4, file: !1, line: 8, column: 7)
+  !26 = !DILocation(line: 8, column: 7, scope: !4)
+  !27 = !DILocation(line: 11, column: 14, scope: !25)
+  !28 = !{!29, !29, i64 0}
+  !29 = !{!"any pointer", !30, i64 0}
+  !30 = !{!"omnipotent char", !31, i64 0}
+  !31 = !{!"Simple C/C++ TBAA"}
+  !32 = !DILocation(line: 11, column: 9, scope: !25)
+  !33 = !DILocation(line: 7, column: 7, scope: !23)
+  !34 = !DILocation(line: 12, column: 7, scope: !4)
+  !35 = !DILocation(line: 13, column: 9, scope: !36)
+  !36 = distinct !DILexicalBlock(scope: !4, file: !1, line: 13, column: 7)
+  !37 = !DILocation(line: 13, column: 7, scope: !4)
+  !38 = !DILocation(line: 14, column: 9, scope: !39)
+  !39 = distinct !DILexicalBlock(scope: !36, file: !1, line: 13, column: 15)
+  !40 = !DILocation(line: 15, column: 11, scope: !39)
+  !41 = !DILocation(line: 16, column: 3, scope: !39)
+  !42 = !DILocation(line: 18, column: 9, scope: !36)
+  !43 = !DILocation(line: 15, column: 7, scope: !39)
+  !44 = !{!45, !45, i64 0}
+  !45 = !{!"int", !30, i64 0}
+  !46 = !DILocation(line: 19, column: 3, scope: !4)
+  !47 = !DILocation(line: 20, column: 3, scope: !4)
+
+...
+---
+name:            main
+alignment:       4
+exposesReturnsTwice: false
+hasInlineAsm:    false
+isSSA:           false
+tracksRegLiveness: true
+tracksSubRegLiveness: false
+liveins:         
+  - { reg: '%edi' }
+  - { reg: '%rsi' }
+calleeSavedRegisters: [ '%bh', '%bl', '%bp', '%bpl', '%bx', '%ebp', '%ebx', 
+                        '%rbp', '%rbx', '%r12', '%r13', '%r14', '%r15', 
+                        '%r12b', '%r13b', '%r14b', '%r15b', '%r12d', '%r13d', 
+                        '%r14d', '%r15d', '%r12w', '%r13w', '%r14w', '%r15w' ]
+frameInfo:       
+  isFrameAddressTaken: false
+  isReturnAddressTaken: false
+  hasStackMap:     false
+  hasPatchPoint:   false
+  stackSize:       8
+  offsetAdjustment: 0
+  maxAlignment:    0
+  adjustsStack:    true
+  hasCalls:        true
+  maxCallFrameSize: 0
+  hasOpaqueSPAdjustment: false
+  hasVAStart:      false
+  hasMustTailInVarArgFunc: false
+fixedStack:      
+  - { id: 0, type: spill-slot, offset: -16, size: 8, alignment: 16, callee-saved-register: '%rbx' }
+body:             |
+  bb.0.entry:
+    successors: %bb.1.if.else(16), %bb.2.if.end(16)
+    liveins: %edi, %rsi, %rbx
+  
+    frame-setup PUSH64r killed %rbx, implicit-def %rsp, implicit %rsp
+    CFI_INSTRUCTION .cfi_def_cfa_offset 16
+    CFI_INSTRUCTION .cfi_offset %rbx, -16
+    DBG_VALUE debug-use %edi, debug-use _, !12, !20, debug-location !21
+    DBG_VALUE debug-use %rsi, debug-use _, !13, !20, debug-location !22
+    %eax = MOV32rr %edi
+    DBG_VALUE debug-use %eax, debug-use _, !12, !20, debug-location !21
+    %edi = MOV32ri 2
+    CMP32ri8 killed %eax, 2, implicit-def %eflags, debug-location !26
+    JNE_1 %bb.2.if.end, implicit %eflags
+  
+  bb.1.if.else:
+    successors: %bb.2.if.end(0)
+    liveins: %rsi
+  
+    DBG_VALUE debug-use %rsi, debug-use _, !13, !20, debug-location !22
+    %rdi = MOV64rm killed %rsi, 1, _, 8, _, debug-location !27 :: (load 8 from %ir.arrayidx, !tbaa !28)
+    dead %eax = XOR32rr undef %eax, undef %eax, implicit-def dead %eflags, implicit-def %al, debug-location !32
+    CALL64pcrel32 @atoi, csr_64, implicit %rsp, implicit %rdi, implicit %al, implicit-def %rsp, implicit-def %eax, debug-location !32
+    %edi = MOV32rr %eax, debug-location !32
+    DBG_VALUE debug-use %edi, debug-use _, !14, !20, debug-location !33
+  
+  bb.2.if.end:
+    successors: %bb.3.if.then.3(16), %bb.4.if.else.5(16)
+    liveins: %edi
+  
+    CALL64pcrel32 @change, csr_64, implicit %rsp, implicit %edi, implicit-def %rsp, implicit-def %eax, debug-location !34
+    %ebx = MOV32rr %eax, debug-location !34
+    DBG_VALUE debug-use %ebx, debug-use _, !14, !20, debug-location !33
+    CMP32ri8 %ebx, 11, implicit-def %eflags, debug-location !37
+    JL_1 %bb.4.if.else.5, implicit killed %eflags, debug-location !37
+  
+  bb.3.if.then.3:
+    successors: %bb.5.if.end.7(0)
+    liveins: %ebx
+  
+    DBG_VALUE debug-use %ebx, debug-use _, !14, !20, debug-location !33
+    %edi = MOV32rr %ebx, debug-location !38
+    CALL64pcrel32 @modify, csr_64, implicit %rsp, implicit %edi, implicit-def %rsp, implicit-def %eax, debug-location !38
+    %ecx = MOV32rr %eax, debug-location !38
+    %ecx = ADD32rr killed %ecx, killed %ebx, implicit-def dead %eflags, debug-location !40
+    JMP_1 %bb.5.if.end.7
+  
+  bb.4.if.else.5:
+    successors: %bb.5.if.end.7(0)
+    liveins: %ebx
+  
+    DBG_VALUE debug-use %ebx, debug-use _, !14, !20, debug-location !33
+    %edi = MOV32rr killed %ebx, debug-location !42
+    CALL64pcrel32 @inc, csr_64, implicit %rsp, implicit %edi, implicit-def %rsp, implicit-def %eax, debug-location !42
+    %ecx = MOV32rr %eax, debug-location !42
+  
+  bb.5.if.end.7:
+    liveins: %ecx
+  
+    MOV32mr %rip, 1, _, @m, _, %ecx, debug-location !43 :: (store 4 into @m, !tbaa !44)
+    dead undef %edi = MOV32ri64 @.str, implicit-def %rdi, debug-location !46
+    dead %eax = XOR32rr undef %eax, undef %eax, implicit-def dead %eflags, implicit-def %al, debug-location !47
+    %esi = MOV32rr killed %ecx, debug-location !46
+    CALL64pcrel32 @printf, csr_64, implicit %rsp, implicit %rdi, implicit %esi, implicit %al, implicit-def %rsp, implicit-def dead %eax, debug-location !46
+    %eax = XOR32rr undef %eax, undef %eax, implicit-def dead %eflags, debug-location !47
+    %rbx = POP64r implicit-def %rsp, implicit %rsp, debug-location !47
+    RETQ %eax, debug-location !47
+
+...

Added: llvm/trunk/test/DebugInfo/MIR/lit.local.cfg
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/DebugInfo/MIR/lit.local.cfg?rev=255759&view=auto
==============================================================================
--- llvm/trunk/test/DebugInfo/MIR/lit.local.cfg (added)
+++ llvm/trunk/test/DebugInfo/MIR/lit.local.cfg Wed Dec 16 05:09:48 2015
@@ -0,0 +1,2 @@
+config.suffixes = ['.mir']
+

Modified: llvm/trunk/test/DebugInfo/X86/array.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/DebugInfo/X86/array.ll?rev=255759&r1=255758&r2=255759&view=diff
==============================================================================
--- llvm/trunk/test/DebugInfo/X86/array.ll (original)
+++ llvm/trunk/test/DebugInfo/X86/array.ll Wed Dec 16 05:09:48 2015
@@ -17,6 +17,8 @@
 ; rdar://problem/14874886
 ;
 ; CHECK:     ##DEBUG_VALUE: main:array <- [%R{{.*}}+0]
+; CHECK:     ##DEBUG_VALUE: main:array <- [%R{{.*}}+0]
+; CHECK:     ##DEBUG_VALUE: main:array <- [%R{{.*}}+0]
 ; CHECK-NOT: ##DEBUG_VALUE: main:array <- %R{{.*}}
 target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
 target triple = "x86_64-apple-macosx10.9.0"

Modified: llvm/trunk/test/DebugInfo/X86/fission-ranges.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/DebugInfo/X86/fission-ranges.ll?rev=255759&r1=255758&r2=255759&view=diff
==============================================================================
--- llvm/trunk/test/DebugInfo/X86/fission-ranges.ll (original)
+++ llvm/trunk/test/DebugInfo/X86/fission-ranges.ll Wed Dec 16 05:09:48 2015
@@ -29,16 +29,16 @@
 ; CHECK-NEXT:      Location description: 11 00
 ; CHECK-NEXT: {{^$}}
 ; CHECK-NEXT:   Beginning address index: 3
-; CHECK-NEXT:                    Length: 21
+; CHECK-NEXT:                    Length: 25
 ; CHECK-NEXT:      Location description: 50 93 04
 ; CHECK: [[E]]: Beginning address index: 4
-; CHECK-NEXT:                    Length: 19
+; CHECK-NEXT:                    Length: 23
 ; CHECK-NEXT:      Location description: 50 93 04
 ; CHECK: [[B]]: Beginning address index: 5
-; CHECK-NEXT:                    Length: 17
+; CHECK-NEXT:                    Length: 21
 ; CHECK-NEXT:      Location description: 50 93 04
 ; CHECK: [[D]]: Beginning address index: 6
-; CHECK-NEXT:                    Length: 17
+; CHECK-NEXT:                    Length: 21
 ; CHECK-NEXT:      Location description: 50 93 04
 
 ; Make sure we don't produce any relocations in any .dwo section (though in particular, debug_info.dwo)

Modified: llvm/trunk/test/DebugInfo/X86/pieces-3.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/DebugInfo/X86/pieces-3.ll?rev=255759&r1=255758&r2=255759&view=diff
==============================================================================
--- llvm/trunk/test/DebugInfo/X86/pieces-3.ll (original)
+++ llvm/trunk/test/DebugInfo/X86/pieces-3.ll Wed Dec 16 05:09:48 2015
@@ -26,7 +26,7 @@
 ; CHECK: .debug_loc
 ; CHECK: [[LOC]]:
 ; CHECK: Beginning address offset: 0x0000000000000000
-; CHECK:    Ending address offset: 0x0000000000000004
+; CHECK:    Ending address offset: 0x0000000000000008
 ; rdi, piece 0x00000008, piece 0x00000004, rsi, piece 0x00000004
 ; CHECK: Location description: 55 93 08 93 04 54 93 04 
 ;

Added: llvm/trunk/test/DebugInfo/live-debug-values.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/DebugInfo/live-debug-values.ll?rev=255759&view=auto
==============================================================================
--- llvm/trunk/test/DebugInfo/live-debug-values.ll (added)
+++ llvm/trunk/test/DebugInfo/live-debug-values.ll Wed Dec 16 05:09:48 2015
@@ -0,0 +1,153 @@
+; RUN: llc -filetype=asm %s -o - | FileCheck %s
+
+; Test the extension of debug ranges from predecessors.
+; Generated from the source file LiveDebugValues.c:
+; #include <stdio.h>
+; int m;
+; extern int inc(int n); 
+; extern int change(int n); 
+; extern int modify(int n); 
+; int main(int argc, char **argv) {
+;   int n;
+;   if (argc != 2)
+;     n = 2;
+;   else
+;     n = atoi(argv[1]);
+;   n = change(n);
+;   if (n > 10) {
+;     m = modify(n);
+;     m = m + n;  // var `m' doesn't has a dbg.value
+;   }
+;   else
+;     m = inc(n); // var `m' doesn't has a dbg.value
+;   printf("m(main): %d\n", m); 
+;   return 0;
+; }
+; with clang -g -O3 -emit-llvm -c LiveDebugValues.c -S -o live-debug-values.ll
+; This case will also produce multiple locations but only the debug range
+; extension is tested here.
+
+; DBG_VALUE for variable "n" is extended into BB#5 from its predecessors BB#3
+; and BB#4.
+; CHECK:       .LBB0_5:
+; CHECK-NEXT:  #DEBUG_VALUE: main:argv <- %RSI
+; CHECK-NEXT:  #DEBUG_VALUE: main:n <- %EBX
+
+
+; ModuleID = 'LiveDebugValues.c'
+target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-unknown-linux-gnu"
+
+ at m = common global i32 0, align 4
+ at .str = private unnamed_addr constant [13 x i8] c"m(main): %d\0A\00", align 1
+
+; Function Attrs: nounwind uwtable
+define i32 @main(i32 %argc, i8** nocapture readonly %argv) #0 !dbg !4 {
+entry:
+  tail call void @llvm.dbg.value(metadata i32 %argc, i64 0, metadata !12, metadata !20), !dbg !21
+  tail call void @llvm.dbg.value(metadata i8** %argv, i64 0, metadata !13, metadata !20), !dbg !22
+  %cmp = icmp eq i32 %argc, 2, !dbg !24
+  br i1 %cmp, label %if.else, label %if.end, !dbg !26
+
+if.else:                                          ; preds = %entry
+  %arrayidx = getelementptr inbounds i8*, i8** %argv, i64 1, !dbg !27
+  %0 = load i8*, i8** %arrayidx, align 8, !dbg !27, !tbaa !28
+  %call = tail call i32 (i8*, ...) bitcast (i32 (...)* @atoi to i32 (i8*, ...)*)(i8* %0) #4, !dbg !32
+  tail call void @llvm.dbg.value(metadata i32 %call, i64 0, metadata !14, metadata !20), !dbg !33
+  br label %if.end
+
+if.end:                                           ; preds = %entry, %if.else
+  %n.0 = phi i32 [ %call, %if.else ], [ 2, %entry ]
+  %call1 = tail call i32 @change(i32 %n.0) #4, !dbg !34
+  tail call void @llvm.dbg.value(metadata i32 %call1, i64 0, metadata !14, metadata !20), !dbg !33
+  %cmp2 = icmp sgt i32 %call1, 10, !dbg !35
+  br i1 %cmp2, label %if.then.3, label %if.else.5, !dbg !37
+
+if.then.3:                                        ; preds = %if.end
+  %call4 = tail call i32 @modify(i32 %call1) #4, !dbg !38
+  %add = add nsw i32 %call4, %call1, !dbg !40
+  br label %if.end.7, !dbg !41
+
+if.else.5:                                        ; preds = %if.end
+  %call6 = tail call i32 @inc(i32 %call1) #4, !dbg !42
+  br label %if.end.7
+
+if.end.7:                                         ; preds = %if.else.5, %if.then.3
+  %storemerge = phi i32 [ %call6, %if.else.5 ], [ %add, %if.then.3 ]
+  store i32 %storemerge, i32* @m, align 4, !dbg !43, !tbaa !44
+  %call8 = tail call i32 (i8*, ...) @printf(i8* nonnull getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %storemerge) #4, !dbg !46
+  ret i32 0, !dbg !47
+}
+
+declare i32 @atoi(...) #1
+
+declare i32 @change(i32) #1
+
+declare i32 @modify(i32) #1
+
+declare i32 @inc(i32) #1
+
+; Function Attrs: nounwind
+declare i32 @printf(i8* nocapture readonly, ...) #2
+
+; Function Attrs: nounwind readnone
+declare void @llvm.dbg.value(metadata, i64, metadata, metadata) #3
+
+attributes #0 = { nounwind uwtable }
+attributes #1 = { nounwind }
+attributes #2 = { nounwind }
+attributes #3 = { nounwind readnone }
+attributes #4 = { nounwind }
+
+!llvm.dbg.cu = !{!0}
+!llvm.module.flags = !{!17, !18}
+!llvm.ident = !{!19}
+
+!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 3.8.0 (trunk 253049) ", isOptimized: true, runtimeVersion: 0, emissionKind: 1, enums: !2, subprograms: !3, globals: !15)
+!1 = !DIFile(filename: "LiveDebugValues.c", directory: "/home/vt/julia/test/tvvikram")
+!2 = !{}
+!3 = !{!4}
+!4 = distinct !DISubprogram(name: "main", scope: !1, file: !1, line: 6, type: !5, isLocal: false, isDefinition: true, scopeLine: 6, flags: DIFlagPrototyped, isOptimized: true, variables: !11)
+!5 = !DISubroutineType(types: !6)
+!6 = !{!7, !7, !8}
+!7 = !DIBasicType(name: "int", size: 32, align: 32, encoding: DW_ATE_signed)
+!8 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !9, size: 64, align: 64)
+!9 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !10, size: 64, align: 64)
+!10 = !DIBasicType(name: "char", size: 8, align: 8, encoding: DW_ATE_signed_char)
+!11 = !{!12, !13, !14}
+!12 = !DILocalVariable(name: "argc", arg: 1, scope: !4, file: !1, line: 6, type: !7)
+!13 = !DILocalVariable(name: "argv", arg: 2, scope: !4, file: !1, line: 6, type: !8)
+!14 = !DILocalVariable(name: "n", scope: !4, file: !1, line: 7, type: !7)
+!15 = !{!16}
+!16 = !DIGlobalVariable(name: "m", scope: !0, file: !1, line: 2, type: !7, isLocal: false, isDefinition: true, variable: i32* @m)
+!17 = !{i32 2, !"Dwarf Version", i32 4}
+!18 = !{i32 2, !"Debug Info Version", i32 3}
+!19 = !{!"clang version 3.8.0 (trunk 253049) "}
+!20 = !DIExpression()
+!21 = !DILocation(line: 6, column: 14, scope: !4)
+!22 = !DILocation(line: 6, column: 27, scope: !23)
+!23 = !DILexicalBlockFile(scope: !4, file: !1, discriminator: 1)
+!24 = !DILocation(line: 8, column: 12, scope: !25)
+!25 = distinct !DILexicalBlock(scope: !4, file: !1, line: 8, column: 7)
+!26 = !DILocation(line: 8, column: 7, scope: !4)
+!27 = !DILocation(line: 11, column: 14, scope: !25)
+!28 = !{!29, !29, i64 0}
+!29 = !{!"any pointer", !30, i64 0}
+!30 = !{!"omnipotent char", !31, i64 0}
+!31 = !{!"Simple C/C++ TBAA"}
+!32 = !DILocation(line: 11, column: 9, scope: !25)
+!33 = !DILocation(line: 7, column: 7, scope: !23)
+!34 = !DILocation(line: 12, column: 7, scope: !4)
+!35 = !DILocation(line: 13, column: 9, scope: !36)
+!36 = distinct !DILexicalBlock(scope: !4, file: !1, line: 13, column: 7)
+!37 = !DILocation(line: 13, column: 7, scope: !4)
+!38 = !DILocation(line: 14, column: 9, scope: !39)
+!39 = distinct !DILexicalBlock(scope: !36, file: !1, line: 13, column: 15)
+!40 = !DILocation(line: 15, column: 11, scope: !39)
+!41 = !DILocation(line: 16, column: 3, scope: !39)
+!42 = !DILocation(line: 18, column: 9, scope: !36)
+!43 = !DILocation(line: 15, column: 7, scope: !39)
+!44 = !{!45, !45, i64 0}
+!45 = !{!"int", !30, i64 0}
+!46 = !DILocation(line: 19, column: 3, scope: !4)
+!47 = !DILocation(line: 20, column: 3, scope: !4)




More information about the llvm-commits mailing list