28#define DEBUG_TYPE "bpf-mi-checking"
46 bool processAtomicInsts();
54 return processAtomicInsts();
110 &BPFMCRegisterClasses[BPF::GPRRegClassID];
111 std::vector<unsigned> GPR32LiveDefs;
112 std::vector<unsigned> GPR64DeadDefs;
117 if (!MO.isReg() || MO.isUse())
120 RegIsGPR64 = GPR64RegClass->
contains(MO.getReg());
128 GPR32LiveDefs.push_back(MO.getReg());
135 GPR64DeadDefs.push_back(MO.getReg());
139 if (GPR32LiveDefs.empty())
144 if (GPR64DeadDefs.empty())
148 for (
auto I : GPR32LiveDefs)
156bool BPFMIPreEmitChecking::processAtomicInsts() {
159 if (
MI.getOpcode() != BPF::XADDW &&
160 MI.getOpcode() != BPF::XADDD &&
161 MI.getOpcode() != BPF::XADDW32)
165 if (hasLiveDefs(
MI,
TRI)) {
170 F,
"Invalid usage of the XADD return value",
DL});
179 bool Changed =
false;
188 if (
MI.getOpcode() != BPF::XFADDW32 &&
MI.getOpcode() != BPF::XFADDD &&
189 MI.getOpcode() != BPF::XFANDW32 &&
MI.getOpcode() != BPF::XFANDD &&
190 MI.getOpcode() != BPF::XFXORW32 &&
MI.getOpcode() != BPF::XFXORD &&
191 MI.getOpcode() != BPF::XFORW32 &&
MI.getOpcode() != BPF::XFORD)
194 if (hasLiveDefs(
MI,
TRI))
199 switch (
MI.getOpcode()) {
201 newOpcode = BPF::XADDW32;
204 newOpcode = BPF::XADDD;
207 newOpcode = BPF::XANDW32;
210 newOpcode = BPF::XANDD;
213 newOpcode = BPF::XXORW32;
216 newOpcode = BPF::XXORD;
219 newOpcode = BPF::XORW32;
222 newOpcode = BPF::XORD;
229 .
add(
MI.getOperand(0))
230 .
add(
MI.getOperand(1))
231 .
add(
MI.getOperand(2))
232 .
add(
MI.getOperand(3));
245 "BPF PreEmit Checking",
false,
false)
247char BPFMIPreEmitChecking::
ID = 0;
250 return new BPFMIPreEmitChecking();
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
const HexagonInstrInfo * TII
unsigned const TargetRegisterInfo * TRI
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
static void initialize(TargetLibraryInfoImpl &TLI, const Triple &T, ArrayRef< StringLiteral > StandardNames)
Initialize the set of available library functions based on the specified target triple.
Diagnostic information for unsupported feature in backend.
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.
MCRegisterClass - Base class of TargetRegisterClass.
bool contains(MCRegister Reg) const
contains - Return true if the specified register is included in this register class.
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...
Function & getFunction()
Return the LLVM function that this machine code represents.
const MachineInstrBuilder & add(const MachineOperand &MO) const
Representation of each machine instruction.
void eraseFromParent()
Unlink 'this' from the containing basic block and delete it.
MachineOperand class - Representation of each machine instruction operand.
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
This is an optimization pass for GlobalISel generic memory operations.
MachineInstrBuilder BuildMI(MachineFunction &MF, const MIMetadata &MIMD, const MCInstrDesc &MCID)
Builder interface. Specify how to create the initial instruction itself.
FunctionPass * createBPFMIPreEmitCheckingPass()
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
void initializeBPFMIPreEmitCheckingPass(PassRegistry &)
bool is_contained(R &&Range, const E &Element)
Returns true if Element is found in Range.