35#define DEBUG_TYPE "bpf-mi-zext-elim"
37STATISTIC(ZExtElemNum,
"Number of zero extension shifts eliminated");
60 bool eliminateZExtSeq();
63 std::set<MachineInstr *> PhiInsns;
76 bool ZExtSeqExist, ZExtExist;
77 ZExtSeqExist = eliminateZExtSeq();
78 ZExtExist = eliminateZExt();
79 return ZExtSeqExist || ZExtExist;
88 LLVM_DEBUG(
dbgs() <<
"*** BPF MachineSSA ZEXT Elim peephole pass ***\n\n");
102 if (!
Reg.isVirtual())
105 if (
MRI->getRegClass(Reg) == &BPF::GPRRegClass)
109 if (!isInsnFrom32Def(DefInsn))
117 for (
unsigned i = 1, e = PhiMI->
getNumOperands(); i < e; i += 2) {
126 if (PhiDef->
isPHI()) {
127 if (!PhiInsns.insert(PhiDef).second)
129 if (!isPhiFrom32Def(PhiDef))
132 if (PhiDef->
getOpcode() == BPF::COPY && !isCopyFrom32Def(PhiDef))
140bool BPFMIPeephole::isInsnFrom32Def(
MachineInstr *DefInsn)
145 if (DefInsn->
isPHI()) {
146 if (!PhiInsns.insert(DefInsn).second)
148 if (!isPhiFrom32Def(DefInsn))
150 }
else if (DefInsn->
getOpcode() == BPF::COPY) {
151 if (!isCopyFrom32Def(DefInsn))
166 if (!isInsnFrom32Def(DefInsn))
174bool BPFMIPeephole::eliminateZExtSeq() {
176 bool Eliminated =
false;
191 if (
MI.getOpcode() == BPF::SRL_ri &&
192 MI.getOperand(2).getImm() == 32) {
219 if (!isMovFrom32Def(MovMI)) {
221 <<
" One ZExt elim sequence failed qualifying elim.\n");
242bool BPFMIPeephole::eliminateZExt() {
244 bool Eliminated =
false;
254 if (
MI.getOpcode() != BPF::MOV_32_64)
267 if (!isMovFrom32Def(&
MI))
290 "BPF MachineSSA Peephole Optimization For ZEXT Eliminate",
293char BPFMIPeephole::
ID = 0;
296STATISTIC(RedundantMovElemNum,
"Number of redundant moves eliminated");
314 bool eliminateRedundantMov();
325 return eliminateRedundantMov();
336bool BPFMIPreEmitPeephole::eliminateRedundantMov() {
338 bool Eliminated =
false;
359 unsigned Opcode =
MI.getOpcode();
360 if (Opcode == BPF::MOV_rr) {
368 RedundantMovElemNum++;
380 "BPF PreEmit Peephole Optimization",
false,
false)
382char BPFMIPreEmitPeephole::
ID = 0;
385 return new BPFMIPreEmitPeephole();
388STATISTIC(TruncElemNum,
"Number of truncation eliminated");
407 bool eliminateTruncSeq();
418 return eliminateTruncSeq();
422static bool TruncSizeCompatible(
int TruncSize,
unsigned opcode)
425 return opcode == BPF::LDB || opcode == BPF::LDB32;
428 return opcode == BPF::LDH || opcode == BPF::LDH32;
431 return opcode == BPF::LDW || opcode == BPF::LDW32;
441 LLVM_DEBUG(
dbgs() <<
"*** BPF MachineSSA TRUNC Elim peephole pass ***\n\n");
454bool BPFMIPeepholeTruncElim::eliminateTruncSeq() {
456 bool Eliminated =
false;
474 if (
MI.getOpcode() == BPF::SRL_ri &&
475 MI.getOperand(2).getImm() == 32) {
476 SrcReg =
MI.getOperand(1).getReg();
477 if (!
MRI->hasOneNonDBGUse(SrcReg))
480 MI2 =
MRI->getVRegDef(SrcReg);
481 DstReg =
MI.getOperand(0).getReg();
493 }
else if (
MI.getOpcode() == BPF::AND_ri ||
494 MI.getOpcode() == BPF::AND_ri_32) {
495 SrcReg =
MI.getOperand(1).getReg();
496 DstReg =
MI.getOperand(0).getReg();
502 int64_t imm =
MI.getOperand(2).getImm();
505 else if (imm == 0xffff)
514 bool CheckFail =
false;
524 if (!PhiDef || PhiDef->
isPHI() ||
525 !TruncSizeCompatible(TruncSize, PhiDef->
getOpcode())) {
556 "BPF MachineSSA Peephole Optimization For TRUNC Eliminate",
559char BPFMIPeepholeTruncElim::
ID = 0;
562 return new BPFMIPeepholeTruncElim();
unsigned const MachineRegisterInfo * MRI
MachineInstrBuilder MachineInstrBuilder & DefMI
const HexagonInstrInfo * TII
unsigned const TargetRegisterInfo * TRI
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
This file defines the 'Statistic' class, which is designed to be an easy way to expose various metric...
#define STATISTIC(VARNAME, DESC)
static void initialize(TargetLibraryInfoImpl &TLI, const Triple &T, ArrayRef< StringLiteral > StandardNames)
Initialize the set of available library functions based on the specified target triple.
FunctionPass class - This class is used to implement most global optimizations.
bool skipFunction(const Function &F) const
Optional passes call this function to check whether the pass should be skipped.
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.
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
Function & getFunction()
Return the LLVM function that this machine code represents.
const MachineInstrBuilder & addImm(int64_t Val) const
Add a new immediate operand.
const MachineInstrBuilder & addReg(Register RegNo, unsigned flags=0, unsigned SubReg=0) const
Add a new virtual register operand.
Representation of each machine instruction.
unsigned getOpcode() const
Returns the opcode of this MachineInstr.
unsigned getNumOperands() const
Retuns the total number of operands.
void eraseFromParent()
Unlink 'this' from the containing basic block and delete it.
const MachineOperand & getOperand(unsigned i) const
MachineOperand class - Representation of each machine instruction operand.
bool isReg() const
isReg - Tests if this is a MO_Register operand.
Register getReg() const
getReg - Returns the register number.
MachineRegisterInfo - Keep track of information for virtual and physical registers,...
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
Wrapper class representing virtual and physical registers.
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.
Reg
All possible values of the reg field in the ModR/M byte.
This is an optimization pass for GlobalISel generic memory operations.
void initializeBPFMIPreEmitPeepholePass(PassRegistry &)
MachineInstrBuilder BuildMI(MachineFunction &MF, const MIMetadata &MIMD, const MCInstrDesc &MCID)
Builder interface. Specify how to create the initial instruction itself.
FunctionPass * createBPFMIPeepholeTruncElimPass()
FunctionPass * createBPFMIPreEmitPeepholePass()
void initializeBPFMIPeepholePass(PassRegistry &)
FunctionPass * createBPFMIPeepholePass()
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
void initializeBPFMIPeepholeTruncElimPass(PassRegistry &)