21#define RISCV_MOVE_MERGE_NAME "RISC-V Zcmp move merging pass"
55char RISCVMoveMerge::ID = 0;
63 if (ST.hasStdExtZcmp())
64 return RISCV::CM_MVA01S;
66 if (ST.hasVendorXqccmp())
67 return RISCV::QC_CM_MVA01S;
73 if (ST.hasStdExtZcmp())
74 return RISCV::CM_MVSA01;
76 if (ST.hasVendorXqccmp())
77 return RISCV::QC_CM_MVSA01;
83bool RISCVMoveMerge::isCandidateToMergeMVA01S(
const DestSourcePair &RegPair) {
87 if ((Destination == RISCV::X10 || Destination == RISCV::X11) &&
88 RISCV::SR07RegClass.
contains(Source))
94bool RISCVMoveMerge::isCandidateToMergeMVSA01(
const DestSourcePair &RegPair) {
98 if ((Source == RISCV::X10 || Source == RISCV::X11) &&
99 RISCV::SR07RegClass.
contains(Destination))
136 for (
auto It = std::next(
I); It != Paired && PairedSource.
isKill(); ++It)
137 if (It->readsRegister(PairedSource.
getReg(),
TRI))
140 Opcode = getMoveFromSToAOpcode(*ST);
142 Sreg2 = &PairedSource;
155 I->eraseFromParent();
156 Paired->eraseFromParent();
168 ModifiedRegUnits.clear();
169 UsedRegUnits.clear();
176 if (
auto SecondPair =
TII->isCopyInstrImpl(
MI)) {
177 Register SourceReg = SecondPair->Source->getReg();
178 Register DestReg = SecondPair->Destination->getReg();
180 bool IsCandidate = MoveFromSToA ? isCandidateToMergeMVA01S(*SecondPair)
181 : isCandidateToMergeMVSA01(*SecondPair);
188 if (!MoveFromSToA && RegPair.
Source->
getReg() == SourceReg)
194 if (!ModifiedRegUnits.available(DestReg) ||
195 !UsedRegUnits.available(DestReg) ||
196 !ModifiedRegUnits.available(SourceReg))
217 auto RegPair =
TII->isCopyInstrImpl(*
MBBI);
218 if (RegPair.has_value()) {
219 bool MoveFromSToA = isCandidateToMergeMVA01S(*RegPair);
220 if (!MoveFromSToA && !isCandidateToMergeMVSA01(*RegPair)) {
226 findMatchingInst(
MBBI, MoveFromSToA, RegPair.value());
229 MBBI = mergePairedInsns(
MBBI, Paired, MoveFromSToA);
244 if (!
ST->hasStdExtZcmp() && !
ST->hasVendorXqccmp())
247 TII =
ST->getInstrInfo();
248 TRI =
ST->getRegisterInfo();
252 ModifiedRegUnits.init(*
TRI);
253 UsedRegUnits.init(*
TRI);
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
MachineBasicBlock MachineBasicBlock::iterator MBBI
const HexagonInstrInfo * TII
Register const TargetRegisterInfo * TRI
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
#define RISCV_MOVE_MERGE_NAME
static unsigned getMoveFromAToSOpcode(const RISCVSubtarget &ST)
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.
void setIsKill(bool Val=true)
Register getReg() const
getReg - Returns the register number.
virtual StringRef getPassName() const
getPassName - Return a nice clean name for a pass.
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...
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
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 swap(llvm::BitVector &LHS, llvm::BitVector &RHS)
Implement std::swap in terms of BitVector swap.
const MachineOperand * Source
const MachineOperand * Destination