44 #define DEBUG_TYPE "nvptx-peephole"
61 return "NVPTX optimize redundant cvta.to.local instruction";
72 INITIALIZE_PASS(NVPTXPeephole,
"nvptx-peephole",
"NVPTX Peephole",
false,
false)
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) {
108 const auto &
MRI = MF.getRegInfo();
115 .addReg(NVPTX::VRFrameLocal)
121 if (
MRI.hasOneNonDBGUse(Prev.getOperand(0).getReg())) {
122 Prev.eraseFromParentAndMarkDBGValuesForRemoval();
124 Root.eraseFromParentAndMarkDBGValuesForRemoval();
131 bool Changed =
false;
133 for (
auto &
MBB : MF) {
137 while (BlockIter !=
MBB.
end()) {
138 auto &
MI = *BlockIter++;
147 const auto &
MRI = MF.getRegInfo();
148 if (
MRI.use_empty(NVPTX::VRFrame)) {
149 if (
auto MI =
MRI.getUniqueVRegDef(NVPTX::VRFrame)) {
150 MI->eraseFromParentAndMarkDBGValuesForRemoval();
const MachineFunction * getParent() const
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)
Return true if the specified register number is in the virtual register namespace.
const Function * getFunction() const
getFunction - Return the LLVM function that this machine code represents
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.
MachineInstrBuilder BuildMI(MachineFunction &MF, const DebugLoc &DL, const MCInstrDesc &MCID)
Builder interface. Specify how to create the initial instruction itself.
static bool isCVTAToLocalCombinationCandidate(MachineInstr &Root)
unsigned const MachineRegisterInfo * MRI
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.
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()
instr_iterator insert(instr_iterator I, MachineInstr *M)
Insert MI into the instruction list before I, possibly inside a bundle.
void initializeNVPTXPeepholePass(PassRegistry &)
unsigned getReg() const
getReg - Returns the register number.
const MachineInstrBuilder & addOperand(const MachineOperand &MO) const
StringRef - Represent a constant reference to a string, i.e.
PassRegistry - This class manages the registration and intitialization of the pass subsystem as appli...