33 #define DEBUG_TYPE "bpf-mi-zext-elim" 35 STATISTIC(ZExtElemNum,
"Number of zero extension shifts eliminated");
58 bool eliminateZExtSeq(
void);
60 std::set<MachineInstr *> PhiInsns;
71 return eliminateZExtSeq();
80 LLVM_DEBUG(
dbgs() <<
"*** BPF MachineSSA ZEXT Elim peephole pass ***\n\n");
83 bool BPFMIPeephole::isCopyFrom32Def(
MachineInstr *CopyMI)
101 if (!isInsnFrom32Def(DefInsn))
118 if (PhiDef->
isPHI()) {
119 if (PhiInsns.find(PhiDef) != PhiInsns.end())
121 PhiInsns.insert(PhiDef);
122 if (!isPhiFrom32Def(PhiDef))
125 if (PhiDef->
getOpcode() == BPF::COPY && !isCopyFrom32Def(PhiDef))
133 bool BPFMIPeephole::isInsnFrom32Def(
MachineInstr *DefInsn)
138 if (DefInsn->
isPHI()) {
139 if (PhiInsns.find(DefInsn) != PhiInsns.end())
141 PhiInsns.insert(DefInsn);
142 if (!isPhiFrom32Def(DefInsn))
144 }
else if (DefInsn->
getOpcode() == BPF::COPY) {
145 if (!isCopyFrom32Def(DefInsn))
160 if (!isInsnFrom32Def(DefInsn))
168 bool BPFMIPeephole::eliminateZExtSeq(
void) {
170 bool Eliminated =
false;
185 if (
MI.getOpcode() == BPF::SRL_ri &&
186 MI.getOperand(2).getImm() == 32) {
206 MovMI->getOpcode() != BPF::MOV_32_64)
213 if (!isMovFrom32Def(MovMI)) {
215 <<
" One ZExt elim sequence failed qualifying elim.\n");
219 BuildMI(MBB,
MI,
MI.getDebugLoc(), TII->get(BPF::SUBREG_TO_REG), DstReg)
223 MovMI->eraseFromParent();
239 "BPF MachineSSA Peephole Optimization For ZEXT Eliminate",
242 char BPFMIPeephole::ID = 0;
245 STATISTIC(RedundantMovElemNum,
"Number of redundant moves eliminated");
263 bool eliminateRedundantMov(
void);
274 return eliminateRedundantMov();
285 bool BPFMIPreEmitPeephole::eliminateRedundantMov(
void) {
287 bool Eliminated =
false;
307 unsigned Opcode =
MI.getOpcode();
308 if (Opcode == BPF::MOV_32_64 ||
309 Opcode == BPF::MOV_rr || Opcode == BPF::MOV_rr_32) {
313 if (Opcode == BPF::MOV_32_64)
320 RedundantMovElemNum++;
332 "BPF PreEmit Peephole Optimization",
false,
false)
334 char BPFMIPreEmitPeephole::ID = 0;
337 return new BPFMIPreEmitPeephole();
340 STATISTIC(TruncElemNum,
"Number of truncation eliminated");
359 bool eliminateTruncSeq(
void);
370 return eliminateTruncSeq();
374 static bool TruncSizeCompatible(
int TruncSize,
unsigned opcode)
377 return opcode == BPF::LDB || opcode == BPF::LDB32;
380 return opcode == BPF::LDH || opcode == BPF::LDH32;
383 return opcode == BPF::LDW || opcode == BPF::LDW32;
393 LLVM_DEBUG(
dbgs() <<
"*** BPF MachineSSA TRUNC Elim peephole pass ***\n\n");
406 bool BPFMIPeepholeTruncElim::eliminateTruncSeq(
void) {
408 bool Eliminated =
false;
426 if (
MI.getOpcode() == BPF::SRL_ri &&
427 MI.getOperand(2).getImm() == 32) {
428 SrcReg =
MI.getOperand(1).getReg();
430 DstReg =
MI.getOperand(0).getReg();
442 }
else if (
MI.getOpcode() == BPF::AND_ri ||
443 MI.getOpcode() == BPF::AND_ri_32) {
444 SrcReg =
MI.getOperand(1).getReg();
445 DstReg =
MI.getOperand(0).getReg();
451 int64_t imm =
MI.getOperand(2).getImm();
454 else if (imm == 0xffff)
462 if (DefMI->
isPHI()) {
463 bool CheckFail =
false;
473 if (!PhiDef || PhiDef->
isPHI() ||
474 !TruncSizeCompatible(TruncSize, PhiDef->
getOpcode())) {
482 }
else if (!TruncSizeCompatible(TruncSize, DefMI->
getOpcode())) {
486 BuildMI(MBB,
MI,
MI.getDebugLoc(), TII->get(BPF::MOV_rr), DstReg)
505 "BPF MachineSSA Peephole Optimization For TRUNC Eliminate",
508 char BPFMIPeepholeTruncElim::ID = 0;
511 return new BPFMIPeepholeTruncElim();
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
void initializeBPFMIPeepholePass(PassRegistry &)
This class represents lattice values for constants.
FunctionPass * createBPFMIPreEmitPeepholePass()
void initializeBPFMIPreEmitPeepholePass(PassRegistry &)
STATISTIC(NumFunctions, "Total number of functions")
unsigned const TargetRegisterInfo * TRI
const TargetRegisterClass * getRegClass(Register Reg) const
Return the register class of the specified virtual register.
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
const HexagonInstrInfo * TII
unsigned getNumOperands() const
Retuns the total number of operands.
void eraseFromParent()
Unlink 'this' from the containing basic block and delete it.
unsigned getOpcode() const
Returns the opcode of this MachineInstr.
MachineInstr * getVRegDef(unsigned Reg) const
getVRegDef - Return the machine instr that defines the specified virtual register or null if none is ...
Register getSubReg(MCRegister Reg, unsigned Idx) const
Returns the physical register number of sub-register "Index" for physical register RegNo...
static void initialize(TargetLibraryInfoImpl &TLI, const Triple &T, ArrayRef< StringLiteral > StandardNames)
Initialize the set of available library functions based on the specified target triple.
MachineInstrBuilder BuildMI(MachineFunction &MF, const DebugLoc &DL, const MCInstrDesc &MCID)
Builder interface. Specify how to create the initial instruction itself.
unsigned const MachineRegisterInfo * MRI
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
FunctionPass class - This class is used to implement most global optimizations.
FunctionPass * createBPFMIPeepholePass()
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
MachineOperand class - Representation of each machine instruction operand.
MachineInstrBuilder MachineInstrBuilder & DefMI
const Function & getFunction() const
Return the LLVM function that this machine code represents.
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
void initializeBPFMIPeepholeTruncElimPass(PassRegistry &)
MachineRegisterInfo - Keep track of information for virtual and physical registers, including vreg register classes, use/def chains for registers, etc.
Representation of each machine instruction.
const MachineInstrBuilder & addImm(int64_t Val) const
Add a new immediate operand.
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
bool isReg() const
isReg - Tests if this is a MO_Register operand.
static bool isVirtualRegister(unsigned Reg)
Return true if the specified register number is in the virtual register namespace.
FunctionPass * createBPFMIPeepholeTruncElimPass()
Register getReg() const
getReg - Returns the register number.
const MachineOperand & getOperand(unsigned i) const
const MachineInstrBuilder & addReg(Register RegNo, unsigned flags=0, unsigned SubReg=0) const
Add a new virtual register operand.
Wrapper class representing virtual and physical registers.