19#define RISCV_MOVE_MERGE_NAME "RISC-V Zcmp move merging pass"
52char RISCVMoveMerge::ID = 0;
61 Register Destination = RegPair.Destination->getReg();
62 Register Source = RegPair.Source->getReg();
64 if ((Destination == RISCV::X10 || Destination == RISCV::X11) &&
65 RISCV::SR07RegClass.
contains(Source))
71bool RISCVMoveMerge::isCandidateToMergeMVSA01(
const DestSourcePair &RegPair) {
75 if ((Source == RISCV::X10 || Source == RISCV::X11) &&
76 RISCV::SR07RegClass.
contains(Destination))
90 Register ARegInFirstPair = Opcode == RISCV::CM_MVA01S
106 bool StartWithX10 = ARegInFirstPair == RISCV::X10;
107 if (Opcode == RISCV::CM_MVA01S) {
108 Sreg1 = StartWithX10 ? FirstPair.
Source : PairedRegs.
Source;
109 Sreg2 = StartWithX10 ? PairedRegs.
Source : FirstPair.
Source;
117 I->eraseFromParent();
118 Paired->eraseFromParent();
130 ModifiedRegUnits.clear();
131 UsedRegUnits.clear();
138 if (
auto SecondPair =
TII->isCopyInstrImpl(
MI)) {
139 Register SourceReg = SecondPair->Source->getReg();
140 Register DestReg = SecondPair->Destination->getReg();
142 if (InstOpcode == RISCV::CM_MVA01S &&
143 isCandidateToMergeMVA01S(*SecondPair)) {
151 if (!ModifiedRegUnits.available(DestReg) ||
152 !UsedRegUnits.available(DestReg) ||
153 !ModifiedRegUnits.available(SourceReg))
157 }
else if (InstOpcode == RISCV::CM_MVSA01 &&
158 isCandidateToMergeMVSA01(*SecondPair)) {
163 if (!ModifiedRegUnits.available(DestReg) ||
164 !UsedRegUnits.available(DestReg) ||
165 !ModifiedRegUnits.available(SourceReg))
186 auto RegPair =
TII->isCopyInstrImpl(*
MBBI);
187 if (RegPair.has_value()) {
190 if (isCandidateToMergeMVA01S(*RegPair))
191 Opcode = RISCV::CM_MVA01S;
192 else if (isCandidateToMergeMVSA01(*RegPair))
193 Opcode = RISCV::CM_MVSA01;
200 findMatchingInst(
MBBI, Opcode, RegPair.value());
203 MBBI = mergePairedInsns(
MBBI, Paired, Opcode);
218 if (!Subtarget->hasStdExtZcmp())
226 ModifiedRegUnits.init(*
TRI);
227 UsedRegUnits.init(*
TRI);
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_MOVE_MERGE_NAME
static bool contains(SmallPtrSetImpl< ConstantExpr * > &Cache, ConstantExpr *Expr, Constant *C)
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.
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.
const MachineOperand * Source
const MachineOperand * Destination