Go to the documentation of this file.
35 #define DEBUG_TYPE "bpf-mi-zext-elim"
37 STATISTIC(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");
91 bool BPFMIPeephole::isCopyFrom32Def(
MachineInstr *CopyMI)
109 if (!isInsnFrom32Def(DefInsn))
126 if (PhiDef->
isPHI()) {
127 if (!PhiInsns.insert(PhiDef).second)
129 if (!isPhiFrom32Def(PhiDef))
132 if (PhiDef->
getOpcode() == BPF::COPY && !isCopyFrom32Def(PhiDef))
140 bool 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))
174 bool 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");
242 bool 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",
293 char BPFMIPeephole::
ID = 0;
296 STATISTIC(RedundantMovElemNum,
"Number of redundant moves eliminated");
314 bool eliminateRedundantMov();
325 return eliminateRedundantMov();
336 bool 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)
382 char BPFMIPreEmitPeephole::
ID = 0;
385 return new BPFMIPreEmitPeephole();
388 STATISTIC(TruncElemNum,
"Number of truncation eliminated");
407 bool eliminateTruncSeq();
418 return eliminateTruncSeq();
422 static 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");
454 bool 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();
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",
559 char BPFMIPeepholeTruncElim::
ID = 0;
562 return new BPFMIPeepholeTruncElim();
const MachineInstrBuilder & addImm(int64_t Val) const
Add a new immediate operand.
This is an optimization pass for GlobalISel generic memory operations.
MachineRegisterInfo - Keep track of information for virtual and physical registers,...
Reg
All possible values of the reg field in the ModR/M byte.
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
FunctionPass * createBPFMIPeepholeTruncElimPass()
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
FunctionPass * createBPFMIPreEmitPeepholePass()
static void initialize(TargetLibraryInfoImpl &TLI, const Triple &T, ArrayRef< StringLiteral > StandardNames)
Initialize the set of available library functions based on the specified target triple.
unsigned const TargetRegisterInfo * TRI
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
const MachineOperand & getOperand(unsigned i) const
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
const HexagonInstrInfo * TII
MachineOperand class - Representation of each machine instruction operand.
void initializeBPFMIPeepholePass(PassRegistry &)
STATISTIC(NumFunctions, "Total number of functions")
MachineInstr * getVRegDef(Register Reg) const
getVRegDef - Return the machine instr that defines the specified virtual register or null if none is ...
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
const TargetRegisterClass * getRegClass(Register Reg) const
Return the register class of the specified virtual register.
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
bool isReg() const
isReg - Tests if this is a MO_Register operand.
Representation of each machine instruction.
static bool isVirtualRegister(unsigned Reg)
Return true if the specified register number is in the virtual register namespace.
const MachineInstrBuilder & addReg(Register RegNo, unsigned flags=0, unsigned SubReg=0) const
Add a new virtual register operand.
Register getReg() const
getReg - Returns the register number.
unsigned getOpcode() const
Returns the opcode of this MachineInstr.
bool hasOneNonDBGUse(Register RegNo) const
hasOneNonDBGUse - Return true if there is exactly one non-Debug use of the specified register.
unsigned const MachineRegisterInfo * MRI
Wrapper class representing virtual and physical registers.
Function & getFunction()
Return the LLVM function that this machine code represents.
FunctionPass * createBPFMIPeepholePass()
void initializeBPFMIPeepholeTruncElimPass(PassRegistry &)
MachineInstrBuilder BuildMI(MachineFunction &MF, const DebugLoc &DL, const MCInstrDesc &MCID)
Builder interface. Specify how to create the initial instruction itself.
MachineInstrBuilder MachineInstrBuilder & DefMI
unsigned getNumOperands() const
Retuns the total number of operands.
FunctionPass class - This class is used to implement most global optimizations.
void eraseFromParent()
Unlink 'this' from the containing basic block and delete it.
void initializeBPFMIPreEmitPeepholePass(PassRegistry &)