[PATCH] D59417: [GVN] Add default debug location when constructing PHI nodes

Stephen Tozer via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Mar 15 08:21:42 PDT 2019


StephenTozer created this revision.
StephenTozer added reviewers: probinson, brzycki, gbedwell, aprantl, vsk, twoh.
Herald added subscribers: llvm-commits, hiraditya.
Herald added a project: LLVM.

The GVN pass will attempt to eliminate repeated load instructions with non-local dependencies where possible by constructing PHI nodes. The PHI node that directly replaces the load instruction is currently assigned the debug location associated  with that load; however, any other predecessor PHI nodes constructed as part of this operation have their debug information left blank. This patch changes the PHI construction code to add a default Line 0 Function-scope debug location for when no more specific information is available.


Repository:
  rL LLVM

https://reviews.llvm.org/D59417

Files:
  llvm/lib/Transforms/Utils/SSAUpdater.cpp
  llvm/test/Transforms/GVN/debugloc.ll


Index: llvm/test/Transforms/GVN/debugloc.ll
===================================================================
--- llvm/test/Transforms/GVN/debugloc.ll
+++ llvm/test/Transforms/GVN/debugloc.ll
@@ -1,10 +1,13 @@
 ; RUN: opt < %s -gvn -S | FileCheck %s
+; CHECK-LABEL: @foo(
+; CHECK-SAME: !dbg ![[FNDBG:[0-9]+]]
 ; CHECK: {{^}}for.body:
 ; CHECK-NEXT: [[VREG1:%[^ ]+]] = phi{{.*}}[[VREG2:%[^ ]+]],{{.*}}%.sink,
-; CHECK-NOT: !dbg
+; CHECK: !dbg ![[DBG:[0-9]+]]
 ; CHECK-SAME: {{$}}
 ; CHECK: {{^}}for.inc:
 ; CHECK-NEXT: [[VREG2]] = phi{{.*}}%inc,{{.*}}[[VREG1]]
+; CHECK: ![[DBG]] = !DILocation(line: 0, scope: ![[FNDBG]]
 
 target triple = "x86_64-unknown-linux-gnu"
 
Index: llvm/lib/Transforms/Utils/SSAUpdater.cpp
===================================================================
--- llvm/lib/Transforms/Utils/SSAUpdater.cpp
+++ llvm/lib/Transforms/Utils/SSAUpdater.cpp
@@ -19,6 +19,7 @@
 #include "llvm/IR/BasicBlock.h"
 #include "llvm/IR/CFG.h"
 #include "llvm/IR/Constants.h"
+#include "llvm/IR/DebugInfoMetadata.h"
 #include "llvm/IR/DebugLoc.h"
 #include "llvm/IR/Instruction.h"
 #include "llvm/IR/Instructions.h"
@@ -279,6 +280,11 @@
                                SSAUpdater *Updater) {
     PHINode *PHI = PHINode::Create(Updater->ProtoType, NumPreds,
                                    Updater->ProtoName, &BB->front());
+    // Add debug location with Line 0 and function scope to the new PHI node
+    if (BB->getParent()->getSubprogram()) {
+      PHI->setDebugLoc(DILocation::get(BB->getContext(), 0, 0,
+                                       BB->getParent()->getSubprogram()));
+    }
     return PHI;
   }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D59417.190831.patch
Type: text/x-patch
Size: 1633 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190315/42dce063/attachment.bin>


More information about the llvm-commits mailing list