2016-05-11 02:33:41 +08:00
|
|
|
//===--- SIDebuggerInsertNops.cpp - Inserts nops for debugger usage -------===//
|
2016-03-03 11:53:29 +08:00
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
/// \file
|
2018-05-01 23:54:18 +08:00
|
|
|
/// Inserts one nop instruction for each high level source statement for
|
2016-05-11 02:33:41 +08:00
|
|
|
/// debugger usage.
|
2016-03-03 11:53:29 +08:00
|
|
|
///
|
2016-05-14 02:21:28 +08:00
|
|
|
/// 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.
|
2016-03-03 11:53:29 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2016-06-24 14:30:11 +08:00
|
|
|
#include "AMDGPUSubtarget.h"
|
2017-06-06 19:49:48 +08:00
|
|
|
#include "SIInstrInfo.h"
|
AMDGPU: Remove #include "MCTargetDesc/AMDGPUMCTargetDesc.h" from common headers
Summary:
MCTargetDesc/AMDGPUMCTargetDesc.h contains enums for all the instuction
and register defintions, which are huge so we only want to include
them where needed.
This will also make it easier if we want to split the R600 and GCN
definitions into separate tablegenerated files.
I was unable to remove AMDGPUMCTargetDesc.h from SIMachineFunctionInfo.h
because it uses some enums from the header to initialize default values
for the SIMachineFunction class, so I ended up having to remove includes of
SIMachineFunctionInfo.h from headers too.
Reviewers: arsenm, nhaehnle
Reviewed By: nhaehnle
Subscribers: MatzeB, kzhuravl, wdng, yaxunl, dstuttard, tpr, t-tye, javed.absar, llvm-commits
Differential Revision: https://reviews.llvm.org/D46272
llvm-svn: 332930
2018-05-22 10:03:23 +08:00
|
|
|
#include "MCTargetDesc/AMDGPUMCTargetDesc.h"
|
2016-05-14 02:21:28 +08:00
|
|
|
#include "llvm/ADT/DenseSet.h"
|
2016-03-03 11:53:29 +08:00
|
|
|
#include "llvm/CodeGen/MachineFunction.h"
|
|
|
|
#include "llvm/CodeGen/MachineFunctionPass.h"
|
|
|
|
#include "llvm/CodeGen/MachineInstrBuilder.h"
|
2016-04-19 00:28:23 +08:00
|
|
|
#include "llvm/CodeGen/MachineModuleInfo.h"
|
2016-03-03 11:53:29 +08:00
|
|
|
using namespace llvm;
|
|
|
|
|
2016-05-11 02:33:41 +08:00
|
|
|
#define DEBUG_TYPE "si-debugger-insert-nops"
|
|
|
|
#define PASS_NAME "SI Debugger Insert Nops"
|
2016-03-03 11:53:29 +08:00
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
2016-05-11 02:33:41 +08:00
|
|
|
class SIDebuggerInsertNops : public MachineFunctionPass {
|
2016-03-03 11:53:29 +08:00
|
|
|
public:
|
|
|
|
static char ID;
|
|
|
|
|
2016-05-11 02:33:41 +08:00
|
|
|
SIDebuggerInsertNops() : MachineFunctionPass(ID) { }
|
2016-10-01 10:56:57 +08:00
|
|
|
StringRef getPassName() const override { return PASS_NAME; }
|
2016-03-03 11:53:29 +08:00
|
|
|
|
2016-06-02 08:04:22 +08:00
|
|
|
void getAnalysisUsage(AnalysisUsage &AU) const override {
|
|
|
|
AU.setPreservesCFG();
|
|
|
|
MachineFunctionPass::getAnalysisUsage(AU);
|
|
|
|
}
|
|
|
|
|
2016-03-03 11:53:29 +08:00
|
|
|
bool runOnMachineFunction(MachineFunction &MF) override;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // anonymous namespace
|
|
|
|
|
2016-05-11 02:33:41 +08:00
|
|
|
INITIALIZE_PASS(SIDebuggerInsertNops, DEBUG_TYPE, PASS_NAME, false, false)
|
2016-03-03 11:53:29 +08:00
|
|
|
|
2016-05-11 02:33:41 +08:00
|
|
|
char SIDebuggerInsertNops::ID = 0;
|
|
|
|
char &llvm::SIDebuggerInsertNopsID = SIDebuggerInsertNops::ID;
|
2016-03-03 11:53:29 +08:00
|
|
|
|
2016-05-11 02:33:41 +08:00
|
|
|
FunctionPass *llvm::createSIDebuggerInsertNopsPass() {
|
|
|
|
return new SIDebuggerInsertNops();
|
2016-03-03 11:53:29 +08:00
|
|
|
}
|
|
|
|
|
2016-05-11 02:33:41 +08:00
|
|
|
bool SIDebuggerInsertNops::runOnMachineFunction(MachineFunction &MF) {
|
|
|
|
// Skip this pass if "amdgpu-debugger-insert-nops" attribute was not
|
|
|
|
// specified.
|
2016-06-24 14:30:11 +08:00
|
|
|
const SISubtarget &ST = MF.getSubtarget<SISubtarget>();
|
2016-04-23 01:04:51 +08:00
|
|
|
if (!ST.debuggerInsertNops())
|
|
|
|
return false;
|
|
|
|
|
2016-04-19 00:28:23 +08:00
|
|
|
// Skip machine functions without debug info.
|
2016-04-23 01:04:51 +08:00
|
|
|
if (!MF.getMMI().hasDebugInfo())
|
2016-04-19 00:28:23 +08:00
|
|
|
return false;
|
|
|
|
|
|
|
|
// Target instruction info.
|
2016-06-24 14:30:11 +08:00
|
|
|
const SIInstrInfo *TII = ST.getInstrInfo();
|
2016-03-03 11:53:29 +08:00
|
|
|
|
2016-05-14 02:21:28 +08:00
|
|
|
// Set containing line numbers that have nop inserted.
|
|
|
|
DenseSet<unsigned> NopInserted;
|
|
|
|
|
2016-04-23 01:04:51 +08:00
|
|
|
for (auto &MBB : MF) {
|
|
|
|
for (auto MI = MBB.begin(); MI != MBB.end(); ++MI) {
|
2018-05-09 10:42:00 +08:00
|
|
|
// Skip debug instructions and instructions without location.
|
|
|
|
if (MI->isDebugInstr() || !MI->getDebugLoc())
|
2016-03-03 11:53:29 +08:00
|
|
|
continue;
|
2016-04-23 01:04:51 +08:00
|
|
|
|
2016-05-14 02:21:28 +08:00
|
|
|
// Insert nop instruction if line number does not have nop inserted.
|
2016-03-03 11:53:29 +08:00
|
|
|
auto DL = MI->getDebugLoc();
|
2016-05-14 02:21:28 +08:00
|
|
|
if (NopInserted.find(DL.getLine()) == NopInserted.end()) {
|
2016-04-23 01:04:51 +08:00
|
|
|
BuildMI(MBB, *MI, DL, TII->get(AMDGPU::S_NOP))
|
2016-03-03 11:53:29 +08:00
|
|
|
.addImm(0);
|
2016-05-14 02:21:28 +08:00
|
|
|
NopInserted.insert(DL.getLine());
|
2016-03-03 11:53:29 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|