45#define DEBUG_TYPE "nvptx-peephole"
49 auto &MF = *
MBB.getParent();
51 if (Root.
getOpcode() != NVPTX::cvta_to_local_64 &&
52 Root.
getOpcode() != NVPTX::cvta_to_local_32)
56 const auto &MRI = MF.getRegInfo();
58 if (
Op.isReg() &&
Op.getReg().isVirtual()) {
59 GenericAddrDef = MRI.getUniqueVRegDef(
Op.getReg());
63 if (!GenericAddrDef || GenericAddrDef->
getParent() != &
MBB ||
64 (GenericAddrDef->
getOpcode() != NVPTX::LEA_ADDRi64 &&
65 GenericAddrDef->
getOpcode() != NVPTX::LEA_ADDRi)) {
73 if ((GenericAddrDef->
getOpcode() == NVPTX::LEA_ADDRi64) !=
78 auto &BaseAddrOp = GenericAddrDef->
getOperand(1);
79 if (BaseAddrOp.isReg() && BaseAddrOp.getReg() == NRI->
getFrameRegister(MF)) {
88 auto &MF = *
MBB.getParent();
89 const auto &MRI = MF.getRegInfo();
100 .
add(Prev.getOperand(2));
105 if (MRI.hasOneNonDBGUse(Prev.getOperand(0).getReg())) {
106 Prev.eraseFromParent();
114 for (
auto &
MBB : MF) {
116 auto BlockIter =
MBB.begin();
118 while (BlockIter !=
MBB.end()) {
119 auto &
MI = *BlockIter++;
134 MI->eraseFromParent();
146 NVPTXPeepholeLegacyPass() : MachineFunctionPass(ID) {}
154 StringRef getPassName()
const override {
155 return "NVPTX optimize redundant cvta.to.local instruction";
158 void getAnalysisUsage(AnalysisUsage &AU)
const override {
165char NVPTXPeepholeLegacyPass::ID = 0;
171 return new NVPTXPeepholeLegacyPass();
const HexagonInstrInfo * TII
static bool runNVPTXPeephole(MachineFunction &MF)
static bool isCVTAToLocalCombinationCandidate(MachineInstr &Root)
static void CombineCVTAToLocal(MachineInstr &Root)
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
LLVM_ABI void setPreservesCFG()
This function should be called by the pass, iff they do not:
Represents analyses that only rely on functions' control flow.
MachineInstrBundleIterator< MachineInstr > iterator
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
Function & getFunction()
Return the LLVM function that this machine code represents.
const MachineInstrBuilder & addReg(Register RegNo, RegState Flags={}, unsigned SubReg=0) const
Add a new virtual register operand.
const MachineInstrBuilder & add(const MachineOperand &MO) const
Representation of each machine instruction.
unsigned getOpcode() const
Returns the opcode of this MachineInstr.
const MachineBasicBlock * getParent() const
const DebugLoc & getDebugLoc() const
Returns the debug location id of this MachineInstr.
const MachineOperand & getOperand(unsigned i) const
LLVM_ABI MachineInstrBundleIterator< MachineInstr > eraseFromParent()
Unlink 'this' from the containing basic block and delete it.
Register getReg() const
getReg - Returns the register number.
PreservedAnalyses run(MachineFunction &MF, MachineFunctionAnalysisManager &MFAM)
Register getFrameLocalRegister(const MachineFunction &MF) const
Register getFrameRegister(const MachineFunction &MF) const override
A set of analyses that are preserved following a run of a transformation pass.
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
PreservedAnalyses & preserveSet()
Mark an analysis set as preserved.
TargetInstrInfo - Interface to description of machine instruction set.
This is an optimization pass for GlobalISel generic memory operations.
MachineInstrBuilder BuildMI(MachineFunction &MF, const MIMetadata &MIMD, const MCInstrDesc &MCID)
Builder interface. Specify how to create the initial instruction itself.
AnalysisManager< MachineFunction > MachineFunctionAnalysisManager
LLVM_ABI PreservedAnalyses getMachineFunctionPassPreservedAnalyses()
Returns the minimum set of Analyses that all machine function passes must preserve.
MachineFunctionPass * createNVPTXPeepholeLegacyPass()
DWARFExpression::Operation Op