44 #define DEBUG_TYPE "nvptx-peephole"
60 const char *getPassName()
const override {
61 return "NVPTX optimize redundant cvta.to.local instruction";
72 INITIALIZE_PASS(NVPTXPeephole,
"nvptx-peephole",
"NVPTX Peephole",
false,
false)
75 auto &MBB = *Root.getParent();
76 auto &MF = *MBB.getParent();
78 if (Root.getOpcode() != NVPTX::cvta_to_local_yes_64 &&
79 Root.getOpcode() != NVPTX::cvta_to_local_yes)
82 auto &Op = Root.getOperand(1);
83 const auto &MRI = MF.getRegInfo();
86 GenericAddrDef = MRI.getUniqueVRegDef(Op.getReg());
90 if (!GenericAddrDef || GenericAddrDef->
getParent() != &MBB ||
91 (GenericAddrDef->
getOpcode() != NVPTX::LEA_ADDRi64 &&
92 GenericAddrDef->
getOpcode() != NVPTX::LEA_ADDRi)) {
97 auto &BaseAddrOp = GenericAddrDef->
getOperand(1);
98 if (BaseAddrOp.isReg() && BaseAddrOp.getReg() == NVPTX::VRFrame) {
115 .addReg(NVPTX::VRFrameLocal)
121 if (MRI.hasOneNonDBGUse(Prev.getOperand(0).getReg())) {
122 Prev.eraseFromParentAndMarkDBGValuesForRemoval();
124 Root.eraseFromParentAndMarkDBGValuesForRemoval();
128 bool Changed =
false;
130 for (
auto &MBB : MF) {
132 auto BlockIter = MBB.begin();
134 while (BlockIter != MBB.end()) {
135 auto &
MI = *BlockIter++;
144 const auto &MRI = MF.getRegInfo();
145 if (MRI.use_empty(NVPTX::VRFrame)) {
146 if (
auto MI = MRI.getUniqueVRegDef(NVPTX::VRFrame)) {
147 MI->eraseFromParentAndMarkDBGValuesForRemoval();
const MachineFunction * getParent() const
getParent - Return the MachineFunction containing this basic block.
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
static void CombineCVTAToLocal(MachineInstr &Root)
static bool isVirtualRegister(unsigned Reg)
isVirtualRegister - Return true if the specified register number is in the virtual register namespace...
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
const HexagonInstrInfo * TII
unsigned getOpcode() const
Returns the opcode of this MachineInstr.
const MachineBasicBlock * getParent() const
TargetInstrInfo - Interface to description of machine instruction set.
bundle_iterator< MachineInstr, instr_iterator > iterator
static bool isCVTAToLocalCombinationCandidate(MachineInstr &Root)
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.
const MachineOperand & getOperand(unsigned i) const
Represent the analysis usage information of a pass.
MachineInstrBuilder BuildMI(MachineFunction &MF, DebugLoc DL, const MCInstrDesc &MCID)
BuildMI - Builder interface.
const MCInstrDesc & get(unsigned Opcode) const
Return the machine instruction descriptor that corresponds to the specified instruction opcode...
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
const DebugLoc & getDebugLoc() const
Returns the debug location id of this MachineInstr.
Representation of each machine instruction.
MachineFunctionPass * createNVPTXPeephole()
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
void initializeNVPTXPeepholePass(PassRegistry &)
unsigned getReg() const
getReg - Returns the register number.
const MachineInstrBuilder & addOperand(const MachineOperand &MO) const
PassRegistry - This class manages the registration and intitialization of the pass subsystem as appli...