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)
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) {
108 const auto &
MRI = MF.getRegInfo();
115 .addReg(NVPTX::VRFrameLocal)
116 .
add(Prev.getOperand(2));
121 if (
MRI.hasOneNonDBGUse(Prev.getOperand(0).getReg())) {
122 Prev.eraseFromParentAndMarkDBGValuesForRemoval();
124 Root.eraseFromParentAndMarkDBGValuesForRemoval();
131 bool Changed =
false;
133 for (
auto &MBB : MF) {
135 auto BlockIter = MBB.begin();
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 MachineInstrBuilder & add(const MachineOperand &MO) const
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
static void CombineCVTAToLocal(MachineInstr &Root)
This class represents lattice values for constants.
const DebugLoc & getDebugLoc() const
Returns the debug location id of this MachineInstr.
unsigned getReg() const
getReg - Returns the register number.
static bool isVirtualRegister(unsigned Reg)
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.
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.
Represent the analysis usage information of a pass.
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
const Function & getFunction() const
Return the LLVM function that this machine code represents.
const MachineBasicBlock * getParent() const
Representation of each machine instruction.
const MachineFunction * getParent() const
Return the MachineFunction containing this basic block.
MachineFunctionPass * createNVPTXPeephole()
const MCInstrDesc & get(unsigned Opcode) const
Return the machine instruction descriptor that corresponds to the specified instruction opcode...
void initializeNVPTXPeepholePass(PassRegistry &)
StringRef - Represent a constant reference to a string, i.e.
PassRegistry - This class manages the registration and intitialization of the pass subsystem as appli...
const MachineOperand & getOperand(unsigned i) const