OSDN Git Service

[AMDGPU] Insert nop pass: take care of outstanding feedback
authorKonstantin Zhuravlyov <kzhuravl_dev@outlook.com>
Fri, 22 Apr 2016 17:04:51 +0000 (17:04 +0000)
committerKonstantin Zhuravlyov <kzhuravl_dev@outlook.com>
Fri, 22 Apr 2016 17:04:51 +0000 (17:04 +0000)
- Switch few loops to range-based for loops
- Fix nop insertion at the end of BB
- Fix formatting
- Check for endpgm

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@267167 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Target/AMDGPU/AMDGPUTargetMachine.cpp
lib/Target/AMDGPU/SIInsertNopsPass.cpp
test/CodeGen/AMDGPU/debugger_insert_nops.ll

index 85dae20..9cd19b8 100644 (file)
@@ -391,11 +391,7 @@ void GCNPassConfig::addPreSched2() {
 void GCNPassConfig::addPreEmitPass() {
   addPass(createSIInsertWaitsPass(), false);
   addPass(createSILowerControlFlowPass(), false);
-
-  const AMDGPUSubtarget &ST = *getAMDGPUTargetMachine().getSubtargetImpl();
-  if (ST.debuggerInsertNops()) {
-    addPass(createSIInsertNopsPass(), false);
-  }
+  addPass(createSIInsertNopsPass(), false);
 }
 
 TargetPassConfig *GCNTargetMachine::createPassConfig(PassManagerBase &PM) {
index d81cca0..7720018 100644 (file)
@@ -54,10 +54,14 @@ FunctionPass *llvm::createSIInsertNopsPass() {
 }
 
 bool SIInsertNops::runOnMachineFunction(MachineFunction &MF) {
+  // Skip this pass if debugger-insert-nops feature is not enabled.
+  const AMDGPUSubtarget &ST = MF.getSubtarget<AMDGPUSubtarget>();
+  if (!ST.debuggerInsertNops())
+    return false;
+
   // Skip machine functions without debug info.
-  if (!MF.getMMI().hasDebugInfo()) {
+  if (!MF.getMMI().hasDebugInfo())
     return false;
-  }
 
   // Target instruction info.
   const SIInstrInfo *TII =
@@ -69,16 +73,16 @@ bool SIInsertNops::runOnMachineFunction(MachineFunction &MF) {
   // Insert nop instruction before first isa instruction of each high level
   // source statement and collect last isa instruction for each high level
   // source statement.
-  for (auto MBB = MF.begin(); MBB != MF.end(); ++MBB) {
-    for (auto MI = MBB->begin(); MI != MBB->end(); ++MI) {
-      if (MI->isDebugValue() || !MI->getDebugLoc()) {
+  for (auto &MBB : MF) {
+    for (auto MI = MBB.begin(); MI != MBB.end(); ++MI) {
+      if (MI->isDebugValue() || !MI->getDebugLoc())
         continue;
-      }
+
       auto DL = MI->getDebugLoc();
       auto CL = DL.getLine();
       auto LineToInstEntry = LineToInst.find(CL);
       if (LineToInstEntry == LineToInst.end()) {
-        BuildMI(*MBB, *MI, DL, TII->get(AMDGPU::S_NOP))
+        BuildMI(MBB, *MI, DL, TII->get(AMDGPU::S_NOP))
           .addImm(0);
         LineToInst.insert(std::make_pair(CL, MI));
       } else {
@@ -88,16 +92,13 @@ bool SIInsertNops::runOnMachineFunction(MachineFunction &MF) {
   }
   // Insert nop instruction after last isa instruction of each high level source
   // statement.
-  for (auto LineToInstEntry = LineToInst.begin();
-         LineToInstEntry != LineToInst.end(); ++LineToInstEntry) {
-    auto MBB = LineToInstEntry->second->getParent();
-    auto DL = LineToInstEntry->second->getDebugLoc();
-    MachineBasicBlock::iterator MI = LineToInstEntry->second;
-    ++MI;
-    if (MI != MBB->end()) {
-      BuildMI(*MBB, *MI, DL, TII->get(AMDGPU::S_NOP))
+  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();
index 8c43b54..3c74f60 100644 (file)
@@ -2,13 +2,17 @@
 
 ; CHECK: debugger_insert_nops.cl:2:3
 ; CHECK-NEXT: s_nop 0
-; CHECK: debugger_insert_nops.cl:3:3
+; CHECK: s_nop 0
+; CHECK-NEXT: debugger_insert_nops.cl:3:3
 ; CHECK-NEXT: s_nop 0
-; CHECK: debugger_insert_nops.cl:4:3
+; CHECK: s_nop 0
+; CHECK-NEXT: debugger_insert_nops.cl:4:3
 ; CHECK-NEXT: s_nop 0
-; CHECK: debugger_insert_nops.cl:5:3
+; CHECK: s_nop 0
+; CHECK-NEXT: debugger_insert_nops.cl:5:3
 ; CHECK-NEXT: s_nop 0
-; CHECK: debugger_insert_nops.cl:6:1
+; CHECK: s_nop 0
+; CHECK-NEXT: debugger_insert_nops.cl:6:1
 ; CHECK-NEXT: s_nop 0
 ; CHECK-NEXT: s_endpgm