37 #define DEBUG_TYPE "bpf-mi-simplify-patchable" 85 LLVM_DEBUG(
dbgs() <<
"*** BPF simplify patchable insts pass ***\n\n");
99 for (
auto I = Begin;
I != End;
I = NextI) {
100 NextI = std::next(
I);
108 if (Opcode == BPF::LDB || Opcode == BPF::LDH || Opcode == BPF::LDW ||
109 Opcode == BPF::LDD || Opcode == BPF::STB || Opcode == BPF::STH ||
110 Opcode == BPF::STW || Opcode == BPF::STD)
111 COREOp = BPF::CORE_MEM;
112 else if (Opcode == BPF::LDB32 || Opcode == BPF::LDH32 ||
113 Opcode == BPF::LDW32 || Opcode == BPF::STB32 ||
114 Opcode == BPF::STH32 || Opcode == BPF::STW32)
115 COREOp = BPF::CORE_ALU32_MEM;
126 .addGlobalAddress(GVal);
141 .add(Inst->
getOperand(1)).addGlobalAddress(GVal);
148 if (MRI->
getRegClass(DstReg) == &BPF::GPR32RegClass) {
157 for (
auto I = Begin;
I != End;
I = NextI) {
158 NextI = std::next(
I);
162 unsigned Opcode =
I->getParent()->getOpcode();
163 if (Opcode == BPF::SUBREG_TO_REG) {
164 Register TmpReg =
I->getParent()->getOperand(0).getReg();
165 processDstReg(MRI, TmpReg, DstReg, GVal,
false);
170 .addReg(SrcReg, 0, BPF::sub_32);
175 processDstReg(MRI, DstReg, SrcReg, GVal,
true);
183 for (
auto I = Begin;
I != End;
I = NextI) {
184 NextI = std::next(
I);
190 processInst(MRI,
I->getParent(), &*
I, GVal);
218 if (Opcode == BPF::ADD_rr)
219 checkADDrr(MRI, RelocOp, GVal);
220 else if (Opcode == BPF::SLL_rr)
221 checkShift(MRI, *Inst->
getParent(), RelocOp, GVal, BPF::SLL_ri);
222 else if (Opcode == BPF::SRA_rr)
223 checkShift(MRI, *Inst->
getParent(), RelocOp, GVal, BPF::SRA_ri);
224 else if (Opcode == BPF::SRL_rr)
225 checkShift(MRI, *Inst->
getParent(), RelocOp, GVal, BPF::SRL_ri);
229 bool BPFMISimplifyPatchable::removeLD() {
232 bool Changed =
false;
261 bool IsCandidate =
false;
263 if (DefInst->
getOpcode() == BPF::LD_imm64) {
282 processCandidate(MRI, MBB, MI, SrcReg, DstReg, GVal);
295 "BPF PreEmit SimplifyPatchable",
false,
false)
299 return new BPFMISimplifyPatchable();
MachineInstr * getParent()
getParent - Return the instruction that this operand belongs to.
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
This class represents lattice values for constants.
FunctionPass * createBPFMISimplifyPatchablePass()
const DebugLoc & getDebugLoc() const
Returns the debug location id of this MachineInstr.
bool isImm() const
isImm - Tests if this is a MO_Immediate operand.
const TargetRegisterClass * getRegClass(Register Reg) const
Return the register class of the specified virtual register.
static use_iterator use_end()
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
const HexagonInstrInfo * TII
void eraseFromParent()
Unlink 'this' from the containing basic block and delete it.
unsigned getOpcode() const
Returns the opcode of this MachineInstr.
void initializeBPFMISimplifyPatchablePass(PassRegistry &)
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 GlobalValue * getGlobal() const
FunctionPass class - This class is used to implement most global optimizations.
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
bool isGlobal() const
isGlobal - Tests if this is a MO_GlobalAddress operand.
static uint64_t add(uint64_t LeftOp, uint64_t RightOp)
MachineOperand class - Representation of each machine instruction operand.
MachineInstr * getUniqueVRegDef(unsigned Reg) const
getUniqueVRegDef - Return the unique machine instr that defines the specified virtual register or nul...
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.
const MachineBasicBlock * getParent() const
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.
use_iterator use_begin(unsigned RegNo) const
LLVM_NODISCARD std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
static const std::string AmaAttr
The attribute attached to globals representing a field access.
bool isReg() const
isReg - Tests if this is a MO_Register operand.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
Register getReg() const
getReg - Returns the register number.
const MachineOperand & getOperand(unsigned i) const
Wrapper class representing virtual and physical registers.