19#define RISCV_PUSH_POP_OPT_NAME "RISC-V Zcmp Push/Pop optimization pass"
41char RISCVPushPopOpt::ID = 0;
52 if (
MBBI->getOpcode() == RISCV::CM_POP)
64 unsigned Opc = IsReturnZero ? RISCV::CM_POPRETZ : RISCV::CM_POPRET;
76 for (
unsigned i = FirstNonDeclaredOp; i <
MBBI->getNumOperands(); ++i)
77 PopRetBuilder.
add(
MBBI->getOperand(i));
80 NextI->eraseFromParent();
90 ModifiedRegUnits.clear();
98 if (
auto OperandPair =
TII->isCopyInstrImpl(
MI)) {
99 Register DestReg = OperandPair->Destination->getReg();
101 if (DestReg == RISCV::X10 && Source == RISCV::X0) {
102 MI.removeFromParent();
110 if (!ModifiedRegUnits.available(RISCV::X10) ||
111 !UsedRegUnits.available(RISCV::X10))
123 if (!Subtarget->hasStdExtZcmp())
136 ModifiedRegUnits.init(*
TRI);
137 UsedRegUnits.init(*
TRI);
139 for (
auto &
MBB : Fn) {
143 NextI->getOpcode() == RISCV::PseudoRET)
152 return new RISCVPushPopOpt();
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
MachineBasicBlock MachineBasicBlock::iterator MBBI
const HexagonInstrInfo * TII
unsigned const TargetRegisterInfo * TRI
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
#define RISCV_PUSH_POP_OPT_NAME
FunctionPass class - This class is used to implement most global optimizations.
A set of register units used to track register liveness.
static void accumulateUsedDefed(const MachineInstr &MI, LiveRegUnits &ModifiedRegUnits, LiveRegUnits &UsedRegUnits, const TargetRegisterInfo *TRI)
For a machine instruction MI, adds all register units used in UsedRegUnits and defined or clobbered i...
Describe properties that are true of each instruction in the target description file.
unsigned char NumImplicitUses
unsigned getNumOperands() const
Return the number of declared MachineOperands for this MachineInstruction.
unsigned char NumImplicitDefs
void eraseFromParent()
This method unlinks 'this' from the containing function and deletes it.
const MachineFunction * getParent() const
Return the MachineFunction containing this basic block.
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
virtual bool runOnMachineFunction(MachineFunction &MF)=0
runOnMachineFunction - This method must be overloaded to perform the desired machine code transformat...
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
Function & getFunction()
Return the LLVM function that this machine code represents.
const LLVMTargetMachine & getTarget() const
getTarget - Return the target machine this machine code is compiled with
const MachineInstrBuilder & add(const MachineOperand &MO) const
Representation of each machine instruction.
virtual StringRef getPassName() const
getPassName - Return a nice clean name for a pass.
const RISCVRegisterInfo * getRegisterInfo() const override
const RISCVInstrInfo * getInstrInfo() const override
Wrapper class representing virtual and physical registers.
StringRef - Represent a constant reference to a string, i.e.
bool DisableFramePointerElim(const MachineFunction &MF) const
DisableFramePointerElim - This returns true if frame pointer elimination optimization should be disab...
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
This is an optimization pass for GlobalISel generic memory operations.
IterT next_nodbg(IterT It, IterT End, bool SkipPseudoOp=true)
Increment It, then continue incrementing it while it points to a debug instruction.
MachineInstrBuilder BuildMI(MachineFunction &MF, const MIMetadata &MIMD, const MCInstrDesc &MCID)
Builder interface. Specify how to create the initial instruction itself.
FunctionPass * createRISCVPushPopOptimizationPass()
createRISCVPushPopOptimizationPass - returns an instance of the Push/Pop optimization pass.