[llvm] r269452 - [AMDGPU] Update nop insertion for debugger usage

Konstantin Zhuravlyov via llvm-commits llvm-commits at lists.llvm.org
Fri May 13 11:21:29 PDT 2016


Author: kzhuravl
Date: Fri May 13 13:21:28 2016
New Revision: 269452

URL: http://llvm.org/viewvc/llvm-project?rev=269452&view=rev
Log:
[AMDGPU] Update nop insertion for debugger usage
- Insert one nop for each high level statement instead of two
- Do not insert nop before prologue

Differential Revision: http://reviews.llvm.org/D20215

Modified:
    llvm/trunk/lib/Target/AMDGPU/AMDGPU.td
    llvm/trunk/lib/Target/AMDGPU/SIDebuggerInsertNops.cpp
    llvm/trunk/test/CodeGen/AMDGPU/debugger-insert-nops.ll

Modified: llvm/trunk/lib/Target/AMDGPU/AMDGPU.td
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/AMDGPU/AMDGPU.td?rev=269452&r1=269451&r2=269452&view=diff
==============================================================================
--- llvm/trunk/lib/Target/AMDGPU/AMDGPU.td (original)
+++ llvm/trunk/lib/Target/AMDGPU/AMDGPU.td Fri May 13 13:21:28 2016
@@ -325,7 +325,7 @@ def FeatureDebuggerInsertNops : Subtarge
   "amdgpu-debugger-insert-nops",
   "DebuggerInsertNops",
   "true",
-  "Insert two nop instructions for each high level source statement"
+  "Insert one nop instruction for each high level source statement"
 >;
 
 def FeatureDebuggerReserveTrapRegs : SubtargetFeature<

Modified: llvm/trunk/lib/Target/AMDGPU/SIDebuggerInsertNops.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/AMDGPU/SIDebuggerInsertNops.cpp?rev=269452&r1=269451&r2=269452&view=diff
==============================================================================
--- llvm/trunk/lib/Target/AMDGPU/SIDebuggerInsertNops.cpp (original)
+++ llvm/trunk/lib/Target/AMDGPU/SIDebuggerInsertNops.cpp Fri May 13 13:21:28 2016
@@ -8,20 +8,19 @@
 //===----------------------------------------------------------------------===//
 //
 /// \file
-/// \brief Inserts two nop instructions for each high level source statement for
+/// \brief Inserts one nop instruction for each high level source statement for
 /// debugger usage.
 ///
-/// Tools, such as debugger, need to pause execution based on user input (i.e.
-/// breakpoint). In order to do this, two nop instructions are inserted for each
-/// high level source statement: one before first isa instruction of high level
-/// source statement, and one after last isa instruction of high level source
-/// statement. Further, debugger may replace nop instructions with trap
-/// instructions based on user input.
+/// Tools, such as a debugger, need to pause execution based on user input (i.e.
+/// breakpoint). In order to do this, one nop instruction is inserted before the
+/// first isa instruction of each high level source statement. Further, the
+/// debugger may replace nop instructions with trap instructions based on user
+/// input.
 //
 //===----------------------------------------------------------------------===//
 
 #include "SIInstrInfo.h"
-#include "llvm/ADT/DenseMap.h"
+#include "llvm/ADT/DenseSet.h"
 #include "llvm/CodeGen/MachineFunction.h"
 #include "llvm/CodeGen/MachineFunctionPass.h"
 #include "llvm/CodeGen/MachineInstrBuilder.h"
@@ -69,44 +68,24 @@ bool SIDebuggerInsertNops::runOnMachineF
   const SIInstrInfo *TII =
     static_cast<const SIInstrInfo*>(MF.getSubtarget().getInstrInfo());
 
-  // Mapping from high level source statement line number to last corresponding
-  // isa instruction.
-  DenseMap<unsigned, MachineBasicBlock::iterator> LineToInst;
-  // Insert nop instruction before first isa instruction of each high level
-  // source statement and collect last isa instruction for each high level
-  // source statement.
+  // Set containing line numbers that have nop inserted.
+  DenseSet<unsigned> NopInserted;
+
   for (auto &MBB : MF) {
     for (auto MI = MBB.begin(); MI != MBB.end(); ++MI) {
+      // Skip DBG_VALUE instructions and instructions without location.
       if (MI->isDebugValue() || !MI->getDebugLoc())
         continue;
 
+      // Insert nop instruction if line number does not have nop inserted.
       auto DL = MI->getDebugLoc();
-      auto CL = DL.getLine();
-      auto LineToInstEntry = LineToInst.find(CL);
-      if (LineToInstEntry == LineToInst.end()) {
+      if (NopInserted.find(DL.getLine()) == NopInserted.end()) {
         BuildMI(MBB, *MI, DL, TII->get(AMDGPU::S_NOP))
           .addImm(0);
-        LineToInst.insert(std::make_pair(CL, MI));
-      } else {
-        LineToInstEntry->second = MI;
+        NopInserted.insert(DL.getLine());
       }
     }
   }
-  // Insert nop instruction after last isa instruction of each high level source
-  // statement.
-  for (auto const &LineToInstEntry : LineToInst) {
-    auto MBB = LineToInstEntry.second->getParent();
-    auto DL = LineToInstEntry.second->getDebugLoc();
-    MachineBasicBlock::iterator MI = LineToInstEntry.second;
-    if (MI->getOpcode() != AMDGPU::S_ENDPGM)
-      BuildMI(*MBB, *(++MI), DL, TII->get(AMDGPU::S_NOP))
-        .addImm(0);
-  }
-  // Insert nop instruction before prologue.
-  MachineBasicBlock &MBB = MF.front();
-  MachineInstr &MI = MBB.front();
-  BuildMI(MBB, MI, DebugLoc(), TII->get(AMDGPU::S_NOP))
-    .addImm(0);
 
   return true;
 }

Modified: llvm/trunk/test/CodeGen/AMDGPU/debugger-insert-nops.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/AMDGPU/debugger-insert-nops.ll?rev=269452&r1=269451&r2=269452&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/AMDGPU/debugger-insert-nops.ll (original)
+++ llvm/trunk/test/CodeGen/AMDGPU/debugger-insert-nops.ll Fri May 13 13:21:28 2016
@@ -1,18 +1,15 @@
-; RUN: llc -mtriple=amdgcn--amdhsa -mcpu=fiji -mattr=+amdgpu-debugger-insert-nops -verify-machineinstrs < %s | FileCheck %s
+; RUN: llc -O0 -mtriple=amdgcn--amdhsa -mcpu=fiji -mattr=+amdgpu-debugger-insert-nops -verify-machineinstrs < %s | FileCheck %s
 
-; CHECK: test01.cl:2:3
+; CHECK: test01.cl:2:{{[0-9]+}}
 ; CHECK-NEXT: s_nop 0
 
-; CHECK: s_nop 0
-; CHECK-NEXT: test01.cl:3:3
+; CHECK: test01.cl:3:{{[0-9]+}}
 ; CHECK-NEXT: s_nop 0
 
-; CHECK: s_nop 0
-; CHECK-NEXT: test01.cl:4:3
+; CHECK: test01.cl:4:{{[0-9]+}}
 ; CHECK-NEXT: s_nop 0
 
-; CHECK: s_nop 0
-; CHECK-NEXT: test01.cl:5:1
+; CHECK: test01.cl:5:{{[0-9]+}}
 ; CHECK-NEXT: s_nop 0
 ; CHECK-NEXT: s_endpgm
 




More information about the llvm-commits mailing list