[PATCH] [DebugInfo][FastISel] Prevent using debug location from previous block for local values

Sergey Dmitrouk sdmitrouk at accesssoftek.com
Wed May 20 10:38:55 PDT 2015


Hi mcrosier, probinson, dblaikie, echristo,

As FastISel groups local values at the top of each block and doesn't attach any
debug location to them (it's intensionally cleared to prevent jumping back and
forth in debuggers), the following situation is possible:

```
BB#0:
    .loc 1 2 3
    ...

BB#1:
    <constant load>
    .loc 1 3 4
    ...
```

Here `<constant load>` "accidentally" gets wrong debug location from the
preceding block, which is wrong.

This patch adds basic block post-processing for `FastISel`, which will look for
first instruction with non-null debug location and assign the location to first
local value (if one exists), producing the following:

```
BB#0:
    .loc 1 2 3
    ...

BB#1:
    .loc 1 3 4
    <constant load>
    .loc 1 3 4
    ...
```

REPOSITORY
  rL LLVM

http://reviews.llvm.org/D9887

Files:
  include/llvm/CodeGen/FastISel.h
  lib/CodeGen/SelectionDAG/FastISel.cpp
  lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp
  test/DebugInfo/ARM/single-constant-use-preserves-dbgloc.ll

Index: include/llvm/CodeGen/FastISel.h
===================================================================
--- include/llvm/CodeGen/FastISel.h
+++ include/llvm/CodeGen/FastISel.h
@@ -226,6 +226,9 @@
   /// be appended, and clear the local CSE map.
   void startNewBlock();
 
+  /// \brief Performs post-processing of complete basic block.
+  void finishNewBlock();
+
   /// \brief Return current debug location information.
   DebugLoc getCurDebugLoc() const { return DbgLoc; }
 
@@ -569,6 +572,10 @@
   bool lowerCallOperands(const CallInst *CI, unsigned ArgIdx, unsigned NumArgs,
                          const Value *Callee, bool ForceRetVoidTy,
                          CallLoweringInfo &CLI);
+
+  /// \brief Copies first non-empty debug location from list of instructions as
+  /// starting location for current block.
+  void fixupLocalValueLocations();
 };
 
 } // end namespace llvm
Index: lib/CodeGen/SelectionDAG/FastISel.cpp
===================================================================
--- lib/CodeGen/SelectionDAG/FastISel.cpp
+++ lib/CodeGen/SelectionDAG/FastISel.cpp
@@ -104,6 +104,35 @@
   LastLocalValue = EmitStartPt;
 }
 
+void FastISel::finishNewBlock() {
+  fixupLocalValueLocations();
+}
+
+void FastISel::fixupLocalValueLocations() {
+  // Nothing to do if we didn't emit any local values.
+  if (LocalValueMap.empty())
+    return;
+
+  // Skip entry basic block to do not move "prologue_end" location above stack
+  // adjustment.
+  if (FuncInfo.MBB == FuncInfo.MBBMap[&FuncInfo.Fn->getEntryBlock()])
+    return;
+
+  // Find first local value by skipping past any EH_LABELs, which go before
+  // local values.
+  MachineBasicBlock::iterator FirstLocalValue = FuncInfo.MBB->begin();
+  while (FirstLocalValue->getOpcode() == TargetOpcode::EH_LABEL)
+    ++FirstLocalValue;
+
+  // Find first instruction with non-null debug location.
+  MachineBasicBlock::iterator InstWithLoc = FuncInfo.InsertPt;
+  while (InstWithLoc != FuncInfo.MBB->end() && !InstWithLoc->getDebugLoc())
+    ++InstWithLoc;
+
+  if (InstWithLoc != FuncInfo.MBB->end())
+    FirstLocalValue->setDebugLoc(InstWithLoc->getDebugLoc());
+}
+
 bool FastISel::lowerArguments() {
   if (!FuncInfo.CanLowerReturn)
     // Fallback to SDISel argument lowering code to deal with sret pointer
Index: lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp
===================================================================
--- lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp
+++ lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp
@@ -1312,6 +1312,8 @@
     }
 
     FinishBasicBlock();
+    if (FastIS)
+      FastIS->finishNewBlock();
     FuncInfo->PHINodesToUpdate.clear();
   }
 
Index: test/DebugInfo/ARM/single-constant-use-preserves-dbgloc.ll
===================================================================
--- test/DebugInfo/ARM/single-constant-use-preserves-dbgloc.ll
+++ test/DebugInfo/ARM/single-constant-use-preserves-dbgloc.ll
@@ -1,4 +1,5 @@
 ; RUN: llc -filetype=asm -asm-verbose=0 < %s | FileCheck %s
+; RUN: llc -fast-isel -filetype=asm -asm-verbose=0 < %s | FileCheck %s
 
 ; int main()
 ; {

EMAIL PREFERENCES
  http://reviews.llvm.org/settings/panel/emailpreferences/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D9887.26161.patch
Type: text/x-patch
Size: 3094 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150520/ce8d1afa/attachment.bin>


More information about the llvm-commits mailing list