19#define RISCV_MOVE_MERGE_NAME "RISC-V Zcmp move merging pass"
54char RISCVMoveMerge::ID = 0;
63 Register Destination = RegPair.Destination->getReg();
64 Register Source = RegPair.Source->getReg();
66 if ((Destination == RISCV::X10 || Destination == RISCV::X11) &&
67 RISCV::SR07RegClass.
contains(Source))
73bool RISCVMoveMerge::isCandidateToMergeMVSA01(
const DestSourcePair &RegPair) {
77 if ((Source == RISCV::X10 || Source == RISCV::X11) &&
78 RISCV::SR07RegClass.
contains(Destination))
108 bool StartWithX10 = ARegInFirstPair == RISCV::X10;
109 if (
Opcode == RISCV::CM_MVA01S) {
110 Sreg1 = StartWithX10 ? FirstPair.
Source : PairedRegs.
Source;
111 Sreg2 = StartWithX10 ? PairedRegs.
Source : FirstPair.
Source;
119 I->eraseFromParent();
120 Paired->eraseFromParent();
132 ModifiedRegUnits.clear();
133 UsedRegUnits.clear();
140 if (
auto SecondPair =
TII->isCopyInstrImpl(
MI)) {
141 Register SourceReg = SecondPair->Source->getReg();
142 Register DestReg = SecondPair->Destination->getReg();
144 if (InstOpcode == RISCV::CM_MVA01S &&
145 isCandidateToMergeMVA01S(*SecondPair)) {
153 if (!ModifiedRegUnits.available(DestReg) ||
154 !UsedRegUnits.available(DestReg) ||
155 !ModifiedRegUnits.available(SourceReg))
159 }
else if (InstOpcode == RISCV::CM_MVSA01 &&
160 isCandidateToMergeMVSA01(*SecondPair)) {
165 if (!ModifiedRegUnits.available(DestReg) ||
166 !UsedRegUnits.available(DestReg) ||
167 !ModifiedRegUnits.available(SourceReg))
188 auto RegPair =
TII->isCopyInstrImpl(*
MBBI);
189 if (RegPair.has_value()) {
192 if (isCandidateToMergeMVA01S(*RegPair))
193 Opcode = RISCV::CM_MVA01S;
194 else if (isCandidateToMergeMVSA01(*RegPair))
195 Opcode = RISCV::CM_MVSA01;
202 findMatchingInst(
MBBI,
Opcode, RegPair.value());
220 if (!Subtarget->hasStdExtZcmp())
228 ModifiedRegUnits.init(*
TRI);
229 UsedRegUnits.init(*
TRI);
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
MachineBasicBlock MachineBasicBlock::iterator MBBI
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
const HexagonInstrInfo * TII
unsigned const TargetRegisterInfo * TRI
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
#define RISCV_MOVE_MERGE_NAME
static bool contains(SmallPtrSetImpl< ConstantExpr * > &Cache, ConstantExpr *Expr, Constant *C)
static constexpr uint32_t Opcode
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...
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 MachineInstrBuilder & add(const MachineOperand &MO) const
Representation of each machine instruction.
MachineOperand class - Representation of each machine instruction operand.
Register getReg() const
getReg - Returns the register number.
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
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.
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.
FunctionPass * createRISCVMoveMergePass()
createRISCVMoveMergePass - returns an instance of the move merge pass.
MachineInstrBuilder BuildMI(MachineFunction &MF, const MIMetadata &MIMD, const MCInstrDesc &MCID)
Builder interface. Specify how to create the initial instruction itself.
void initializeRISCVMoveMergePass(PassRegistry &)
const MachineOperand * Source
const MachineOperand * Destination