LCOV - code coverage report
Current view: top level - lib/Target/AMDGPU - SIDebuggerInsertNops.cpp (source / functions) Hit Total Coverage
Test: llvm-toolchain.info Lines: 26 26 100.0 %
Date: 2017-09-14 15:23:50 Functions: 7 8 87.5 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : //===--- SIDebuggerInsertNops.cpp - Inserts nops for debugger usage -------===//
       2             : //
       3             : //                     The LLVM Compiler Infrastructure
       4             : //
       5             : // This file is distributed under the University of Illinois Open Source
       6             : // License. See LICENSE.TXT for details.
       7             : //
       8             : //===----------------------------------------------------------------------===//
       9             : //
      10             : /// \file
      11             : /// \brief Inserts one nop instruction for each high level source statement for
      12             : /// debugger usage.
      13             : ///
      14             : /// Tools, such as a debugger, need to pause execution based on user input (i.e.
      15             : /// breakpoint). In order to do this, one nop instruction is inserted before the
      16             : /// first isa instruction of each high level source statement. Further, the
      17             : /// debugger may replace nop instructions with trap instructions based on user
      18             : /// input.
      19             : //
      20             : //===----------------------------------------------------------------------===//
      21             : 
      22             : #include "AMDGPUSubtarget.h"
      23             : #include "SIInstrInfo.h"
      24             : #include "llvm/ADT/DenseSet.h"
      25             : #include "llvm/CodeGen/MachineFunction.h"
      26             : #include "llvm/CodeGen/MachineFunctionPass.h"
      27             : #include "llvm/CodeGen/MachineInstrBuilder.h"
      28             : #include "llvm/CodeGen/MachineModuleInfo.h"
      29             : using namespace llvm;
      30             : 
      31             : #define DEBUG_TYPE "si-debugger-insert-nops"
      32             : #define PASS_NAME "SI Debugger Insert Nops"
      33             : 
      34             : namespace {
      35             : 
      36        1460 : class SIDebuggerInsertNops : public MachineFunctionPass {
      37             : public:
      38             :   static char ID;
      39             : 
      40        1468 :   SIDebuggerInsertNops() : MachineFunctionPass(ID) { }
      41        1459 :   StringRef getPassName() const override { return PASS_NAME; }
      42             : 
      43        1459 :   void getAnalysisUsage(AnalysisUsage &AU) const override {
      44        1459 :     AU.setPreservesCFG();
      45        1459 :     MachineFunctionPass::getAnalysisUsage(AU);
      46        1459 :   }
      47             : 
      48             :   bool runOnMachineFunction(MachineFunction &MF) override;
      49             : };
      50             : 
      51             : } // anonymous namespace
      52             : 
      53      312538 : INITIALIZE_PASS(SIDebuggerInsertNops, DEBUG_TYPE, PASS_NAME, false, false)
      54             : 
      55             : char SIDebuggerInsertNops::ID = 0;
      56             : char &llvm::SIDebuggerInsertNopsID = SIDebuggerInsertNops::ID;
      57             : 
      58        1468 : FunctionPass *llvm::createSIDebuggerInsertNopsPass() {
      59        2936 :   return new SIDebuggerInsertNops();
      60             : }
      61             : 
      62       14827 : bool SIDebuggerInsertNops::runOnMachineFunction(MachineFunction &MF) {
      63             :   // Skip this pass if "amdgpu-debugger-insert-nops" attribute was not
      64             :   // specified.
      65       14827 :   const SISubtarget &ST = MF.getSubtarget<SISubtarget>();
      66       14827 :   if (!ST.debuggerInsertNops())
      67             :     return false;
      68             : 
      69             :   // Skip machine functions without debug info.
      70           5 :   if (!MF.getMMI().hasDebugInfo())
      71             :     return false;
      72             : 
      73             :   // Target instruction info.
      74           5 :   const SIInstrInfo *TII = ST.getInstrInfo();
      75             : 
      76             :   // Set containing line numbers that have nop inserted.
      77           5 :   DenseSet<unsigned> NopInserted;
      78             : 
      79          20 :   for (auto &MBB : MF) {
      80         523 :     for (auto MI = MBB.begin(); MI != MBB.end(); ++MI) {
      81             :       // Skip DBG_VALUE instructions and instructions without location.
      82        1010 :       if (MI->isDebugValue() || !MI->getDebugLoc())
      83         122 :         continue;
      84             : 
      85             :       // Insert nop instruction if line number does not have nop inserted.
      86         396 :       auto DL = MI->getDebugLoc();
      87         528 :       if (NopInserted.find(DL.getLine()) == NopInserted.end()) {
      88          80 :         BuildMI(MBB, *MI, DL, TII->get(AMDGPU::S_NOP))
      89          20 :           .addImm(0);
      90          40 :         NopInserted.insert(DL.getLine());
      91             :       }
      92             :     }
      93             :   }
      94             : 
      95           5 :   return true;
      96             : }

Generated by: LCOV version 1.13