20#define LOONGARCH_LATE_BRANCH_OPT_NAME "LoongArch Late Branch Optimisation Pass"
46char LoongArchLateBranchOpt::ID = 0;
61 unsigned Opc =
Cond[0].getImm();
66 if (
Cond.size() < 2 || !
Cond[1].isReg() ||
67 Cond[1].getReg() != LoongArch::R0)
69 Folded = (
Opc == LoongArch::BEQZ) ?
TBB : FBB;
73 if (
Cond.size() < 3 || !
Cond[1].isReg() || !
Cond[2].isReg() ||
74 Cond[1].getReg() !=
Cond[2].getReg())
76 Folded = (
Opc == LoongArch::BEQ) ?
TBB : FBB;
88 TII->insertBranch(
MBB, Folded,
nullptr, {},
DL);
92 while (!
MBB.succ_empty())
93 MBB.removeSuccessor(
MBB.succ_end() - 1);
98 if (Fallthrough !=
MBB.getParent()->end())
99 MBB.addSuccessor(&*Fallthrough);
101 MBB.addSuccessor(Folded);
106bool LoongArchLateBranchOpt::runOnMachineFunction(
MachineFunction &Fn) {
111 TII =
ST.getInstrInfo();
114 for (MachineBasicBlock &
MBB : Fn)
120 return new LoongArchLateBranchOpt();
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
const HexagonInstrInfo * TII
#define LOONGARCH_LATE_BRANCH_OPT_NAME
static bool runOnBasicBlock(MachineBasicBlock *MBB, unsigned BasicBlockNum, VRegRenamer &Renamer)
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
const SmallVectorImpl< MachineOperand > MachineBasicBlock * TBB
const SmallVectorImpl< MachineOperand > & Cond
Represent the analysis usage information of a pass.
FunctionPass class - This class is used to implement most global optimizations.
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.
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.
BasicBlockListType::iterator iterator
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Represent a constant reference to a string, i.e.
This is an optimization pass for GlobalISel generic memory operations.
FunctionPass * createLoongArchLateBranchOptPass()