LCOV - code coverage report
Current view: top level - lib/Target/AMDGPU - SIDebuggerInsertNops.cpp (source / functions) Hit Total Coverage
Test: llvm-toolchain.info Lines: 21 21 100.0 %
Date: 2018-06-17 00:07:59 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             : /// 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 "MCTargetDesc/AMDGPUMCTargetDesc.h"
      25             : #include "llvm/ADT/DenseSet.h"
      26             : #include "llvm/CodeGen/MachineFunction.h"
      27             : #include "llvm/CodeGen/MachineFunctionPass.h"
      28             : #include "llvm/CodeGen/MachineInstrBuilder.h"
      29             : #include "llvm/CodeGen/MachineModuleInfo.h"
      30             : using namespace llvm;
      31             : 
      32             : #define DEBUG_TYPE "si-debugger-insert-nops"
      33             : #define PASS_NAME "SI Debugger Insert Nops"
      34             : 
      35             : namespace {
      36             : 
      37        1787 : class SIDebuggerInsertNops : public MachineFunctionPass {
      38             : public:
      39             :   static char ID;
      40             : 
      41        1795 :   SIDebuggerInsertNops() : MachineFunctionPass(ID) { }
      42        1784 :   StringRef getPassName() const override { return PASS_NAME; }
      43             : 
      44        1784 :   void getAnalysisUsage(AnalysisUsage &AU) const override {
      45        1784 :     AU.setPreservesCFG();
      46        1784 :     MachineFunctionPass::getAnalysisUsage(AU);
      47        1784 :   }
      48             : 
      49             :   bool runOnMachineFunction(MachineFunction &MF) override;
      50             : };
      51             : 
      52             : } // anonymous namespace
      53             : 
      54      357084 : INITIALIZE_PASS(SIDebuggerInsertNops, DEBUG_TYPE, PASS_NAME, false, false)
      55             : 
      56             : char SIDebuggerInsertNops::ID = 0;
      57             : char &llvm::SIDebuggerInsertNopsID = SIDebuggerInsertNops::ID;
      58             : 
      59        1795 : FunctionPass *llvm::createSIDebuggerInsertNopsPass() {
      60        3590 :   return new SIDebuggerInsertNops();
      61             : }
      62             : 
      63       17852 : bool SIDebuggerInsertNops::runOnMachineFunction(MachineFunction &MF) {
      64             :   // Skip this pass if "amdgpu-debugger-insert-nops" attribute was not
      65             :   // specified.
      66       17852 :   const SISubtarget &ST = MF.getSubtarget<SISubtarget>();
      67       17852 :   if (!ST.debuggerInsertNops())
      68             :     return false;
      69             : 
      70             :   // Skip machine functions without debug info.
      71           5 :   if (!MF.getMMI().hasDebugInfo())
      72             :     return false;
      73             : 
      74             :   // Target instruction info.
      75             :   const SIInstrInfo *TII = ST.getInstrInfo();
      76             : 
      77             :   // Set containing line numbers that have nop inserted.
      78             :   DenseSet<unsigned> NopInserted;
      79             : 
      80          10 :   for (auto &MBB : MF) {
      81         242 :     for (auto MI = MBB.begin(); MI != MBB.end(); ++MI) {
      82             :       // Skip debug instructions and instructions without location.
      83         332 :       if (MI->isDebugInstr() || !MI->getDebugLoc())
      84         103 :         continue;
      85             : 
      86             :       // Insert nop instruction if line number does not have nop inserted.
      87             :       auto DL = MI->getDebugLoc();
      88         258 :       if (NopInserted.find(DL.getLine()) == NopInserted.end()) {
      89          60 :         BuildMI(MBB, *MI, DL, TII->get(AMDGPU::S_NOP))
      90             :           .addImm(0);
      91          40 :         NopInserted.insert(DL.getLine());
      92             :       }
      93             :     }
      94             :   }
      95             : 
      96             :   return true;
      97             : }

Generated by: LCOV version 1.13