45#define DEBUG_TYPE "nvptx-peephole"
56 return "NVPTX optimize redundant cvta.to.local instruction";
65char NVPTXPeephole::ID = 0;
67INITIALIZE_PASS(NVPTXPeephole,
"nvptx-peephole",
"NVPTX Peephole",
false,
false)
70 auto &
MBB = *Root.getParent();
71 auto &MF = *
MBB.getParent();
73 if (Root.getOpcode() != NVPTX::cvta_to_local_64 &&
74 Root.getOpcode() != NVPTX::cvta_to_local_32)
77 auto &
Op = Root.getOperand(1);
78 const auto &MRI = MF.getRegInfo();
80 if (
Op.isReg() &&
Op.getReg().isVirtual()) {
81 GenericAddrDef = MRI.getUniqueVRegDef(Op.getReg());
85 if (!GenericAddrDef || GenericAddrDef->getParent() != &
MBB ||
86 (GenericAddrDef->getOpcode() != NVPTX::LEA_ADDRi64 &&
87 GenericAddrDef->getOpcode() != NVPTX::LEA_ADDRi)) {
95 if ((GenericAddrDef->getOpcode() == NVPTX::LEA_ADDRi64) !=
96 (NRI->getFrameLocalRegister(MF) == NVPTX::VRFrameLocal64))
100 auto &BaseAddrOp = GenericAddrDef->getOperand(1);
101 if (BaseAddrOp.isReg() && BaseAddrOp.getReg() == NRI->getFrameRegister(MF)) {
110 auto &MF = *
MBB.getParent();
111 const auto &MRI = MF.getRegInfo();
122 .
add(Prev.getOperand(2));
127 if (MRI.hasOneNonDBGUse(Prev.getOperand(0).getReg())) {
128 Prev.eraseFromParent();
139 for (
auto &
MBB : MF) {
143 while (BlockIter !=
MBB.
end()) {
144 auto &
MI = *BlockIter++;
152 const NVPTXRegisterInfo *NRI =
153 MF.getSubtarget<NVPTXSubtarget>().getRegisterInfo();
156 const auto &MRI = MF.getRegInfo();
159 MI->eraseFromParent();
const HexagonInstrInfo * TII
static bool isCVTAToLocalCombinationCandidate(MachineInstr &Root)
static void CombineCVTAToLocal(MachineInstr &Root)
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
Represent the analysis usage information of a pass.
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.
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.
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.
Register getFrameLocalRegister(const MachineFunction &MF) const
Register getFrameRegister(const MachineFunction &MF) const override
const NVPTXRegisterInfo * getRegisterInfo() const override
Represent a constant reference to a string, i.e.
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.
MachineFunctionPass * createNVPTXPeephole()
DWARFExpression::Operation Op