| 1 | //===-- BPF.h - Top-level interface for BPF representation ------*- C++ -*-===// |
| 2 | // |
| 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | |
| 9 | #ifndef LLVM_LIB_TARGET_BPF_BPF_H |
| 10 | #define LLVM_LIB_TARGET_BPF_BPF_H |
| 11 | |
| 12 | #include "MCTargetDesc/BPFMCTargetDesc.h" |
| 13 | #include "llvm/IR/Instructions.h" |
| 14 | #include "llvm/IR/PassManager.h" |
| 15 | #include "llvm/Pass.h" |
| 16 | #include "llvm/Target/TargetMachine.h" |
| 17 | |
| 18 | namespace llvm { |
| 19 | class BPFRegisterBankInfo; |
| 20 | class BPFSubtarget; |
| 21 | class BPFTargetMachine; |
| 22 | class InstructionSelector; |
| 23 | class PassRegistry; |
| 24 | |
| 25 | static const char *BPF_TRAP = "__bpf_trap" ; |
| 26 | |
| 27 | ModulePass *createBPFCheckAndAdjustIR(); |
| 28 | |
| 29 | FunctionPass *createBPFISelDag(BPFTargetMachine &TM); |
| 30 | FunctionPass *createBPFMISimplifyPatchablePass(); |
| 31 | FunctionPass *createBPFMIPeepholePass(); |
| 32 | FunctionPass *createBPFMIPreEmitPeepholePass(); |
| 33 | FunctionPass *createBPFMIPreEmitCheckingPass(); |
| 34 | |
| 35 | InstructionSelector *createBPFInstructionSelector(const BPFTargetMachine &, |
| 36 | const BPFSubtarget &, |
| 37 | const BPFRegisterBankInfo &); |
| 38 | |
| 39 | void initializeBPFAsmPrinterPass(PassRegistry &); |
| 40 | void initializeBPFCheckAndAdjustIRPass(PassRegistry&); |
| 41 | void initializeBPFDAGToDAGISelLegacyPass(PassRegistry &); |
| 42 | void initializeBPFMIPeepholePass(PassRegistry &); |
| 43 | void initializeBPFMIPreEmitCheckingPass(PassRegistry &); |
| 44 | void initializeBPFMIPreEmitPeepholePass(PassRegistry &); |
| 45 | void initializeBPFMISimplifyPatchablePass(PassRegistry &); |
| 46 | |
| 47 | class BPFAbstractMemberAccessPass |
| 48 | : public PassInfoMixin<BPFAbstractMemberAccessPass> { |
| 49 | BPFTargetMachine *TM; |
| 50 | |
| 51 | public: |
| 52 | BPFAbstractMemberAccessPass(BPFTargetMachine *TM) : TM(TM) {} |
| 53 | PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM); |
| 54 | |
| 55 | static bool isRequired() { return true; } |
| 56 | }; |
| 57 | |
| 58 | class BPFPreserveDITypePass : public PassInfoMixin<BPFPreserveDITypePass> { |
| 59 | public: |
| 60 | PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM); |
| 61 | |
| 62 | static bool isRequired() { return true; } |
| 63 | }; |
| 64 | |
| 65 | class BPFIRPeepholePass : public PassInfoMixin<BPFIRPeepholePass> { |
| 66 | public: |
| 67 | PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM); |
| 68 | |
| 69 | static bool isRequired() { return true; } |
| 70 | }; |
| 71 | |
| 72 | class BPFASpaceCastSimplifyPass |
| 73 | : public PassInfoMixin<BPFASpaceCastSimplifyPass> { |
| 74 | public: |
| 75 | PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM); |
| 76 | |
| 77 | static bool isRequired() { return true; } |
| 78 | }; |
| 79 | |
| 80 | class BPFAdjustOptPass : public PassInfoMixin<BPFAdjustOptPass> { |
| 81 | public: |
| 82 | PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM); |
| 83 | }; |
| 84 | |
| 85 | class BPFPreserveStaticOffsetPass |
| 86 | : public PassInfoMixin<BPFPreserveStaticOffsetPass> { |
| 87 | bool AllowPartial; |
| 88 | |
| 89 | public: |
| 90 | BPFPreserveStaticOffsetPass(bool AllowPartial) : AllowPartial(AllowPartial) {} |
| 91 | PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM); |
| 92 | |
| 93 | static bool isRequired() { return true; } |
| 94 | |
| 95 | static std::pair<GetElementPtrInst *, LoadInst *> |
| 96 | reconstructLoad(CallInst *Call); |
| 97 | |
| 98 | static std::pair<GetElementPtrInst *, StoreInst *> |
| 99 | reconstructStore(CallInst *Call); |
| 100 | }; |
| 101 | |
| 102 | } // namespace llvm |
| 103 | |
| 104 | #endif |
| 105 | |