32#define DEBUG_TYPE "bpf-check-and-opt-ir"
38class BPFCheckAndAdjustIR final :
public ModulePass {
48 bool removePassThroughBuiltin(
Module &M);
49 bool removeCompareBuiltin(
Module &M);
53char BPFCheckAndAdjustIR::ID = 0;
58 return new BPFCheckAndAdjustIR();
61void BPFCheckAndAdjustIR::checkIR(
Module &M) {
94bool BPFCheckAndAdjustIR::removePassThroughBuiltin(
Module &M) {
105 ToBeDeleted =
nullptr;
108 auto *
Call = dyn_cast<CallInst>(&
I);
111 auto *GV = dyn_cast<GlobalValue>(
Call->getCalledOperand());
114 if (!GV->getName().startswith(
"llvm.bpf.passthrough"))
124bool BPFCheckAndAdjustIR::removeCompareBuiltin(
Module &M) {
128 bool Changed =
false;
135 ToBeDeleted =
nullptr;
138 auto *
Call = dyn_cast<CallInst>(&
I);
141 auto *GV = dyn_cast<GlobalValue>(
Call->getCalledOperand());
144 if (!GV->getName().startswith(
"llvm.bpf.compare"))
152 auto OpVal = cast<ConstantInt>(Arg0)->getValue().getZExtValue();
155 auto *ICmp =
new ICmpInst(Opcode, Arg1, Arg2);
156 ICmp->insertBefore(Call);
158 Call->replaceAllUsesWith(ICmp);
164bool BPFCheckAndAdjustIR::adjustIR(
Module &M) {
165 bool Changed = removePassThroughBuiltin(M);
166 Changed = removeCompareBuiltin(M) || Changed;
170bool BPFCheckAndAdjustIR::runOnModule(
Module &M) {
amdgpu Simplify well known AMD library false FunctionCallee Value * Arg
Module.h This file contains the declarations for the Module class.
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
static constexpr StringRef TypeIdAttr
The attribute attached to globals representing a type id.
static constexpr StringRef AmaAttr
The attribute attached to globals representing a field access.
This class represents a function call, abstracting a target machine's calling convention.
Predicate
This enumeration lists the possible predicates for CmpInst subclasses.
This instruction compares its operands according to the predicate given to the constructor.
SymbolTableList< Instruction >::iterator eraseFromParent()
This method unlinks 'this' from the containing basic block and deletes it.
ModulePass class - This class is used to implement unstructured interprocedural optimizations and ana...
virtual bool runOnModule(Module &M)=0
runOnModule - Virtual method overriden by subclasses to process the module being operated on.
A Module instance is used to store all the information related to an LLVM module.
Value * getIncomingValue(unsigned i) const
Return incoming value number x.
unsigned getNumIncomingValues() const
Return the number of incoming edges.
LLVM Value Representation.
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
This is an optimization pass for GlobalISel generic memory operations.
ModulePass * createBPFCheckAndAdjustIR()
void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.