| 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/CodeGen/MachineFunction.h" |
| 14 | #include "llvm/CodeGen/MachineFunctionAnalysisManager.h" |
| 15 | #include "llvm/CodeGen/SelectionDAGISel.h" |
| 16 | #include "llvm/IR/Analysis.h" |
| 17 | #include "llvm/IR/Instructions.h" |
| 18 | #include "llvm/IR/PassManager.h" |
| 19 | #include "llvm/Pass.h" |
| 20 | #include "llvm/Target/TargetMachine.h" |
| 21 | |
| 22 | namespace llvm { |
| 23 | class BPFRegisterBankInfo; |
| 24 | class BPFSubtarget; |
| 25 | class BPFTargetMachine; |
| 26 | class InstructionSelector; |
| 27 | class PassRegistry; |
| 28 | |
| 29 | #define BPF_TRAP "__bpf_trap" |
| 30 | |
| 31 | class BPFCheckAndAdjustIRPass |
| 32 | : public RequiredPassInfoMixin<BPFCheckAndAdjustIRPass> { |
| 33 | public: |
| 34 | PreservedAnalyses run(Module &M, ModuleAnalysisManager &MAM); |
| 35 | }; |
| 36 | |
| 37 | ModulePass *createBPFCheckAndAdjustIRLegacyPass(); |
| 38 | |
| 39 | class BPFISelDAGToDAGPass : public SelectionDAGISelPass { |
| 40 | public: |
| 41 | BPFISelDAGToDAGPass(BPFTargetMachine &TM); |
| 42 | }; |
| 43 | |
| 44 | FunctionPass *createBPFISelDag(BPFTargetMachine &TM); |
| 45 | |
| 46 | class BPFMISimplifyPatchablePass |
| 47 | : public OptionalPassInfoMixin<BPFMISimplifyPatchablePass> { |
| 48 | public: |
| 49 | PreservedAnalyses run(MachineFunction &MF, |
| 50 | MachineFunctionAnalysisManager &MFAM); |
| 51 | }; |
| 52 | |
| 53 | FunctionPass *createBPFMISimplifyPatchableLegacyPass(); |
| 54 | |
| 55 | class BPFMIPeepholePass : public OptionalPassInfoMixin<BPFMIPeepholePass> { |
| 56 | public: |
| 57 | PreservedAnalyses run(MachineFunction &MF, |
| 58 | MachineFunctionAnalysisManager &MFAM); |
| 59 | }; |
| 60 | |
| 61 | FunctionPass *createBPFMIPeepholeLegacyPass(); |
| 62 | |
| 63 | class BPFMIExpandStackArgPseudosPass |
| 64 | : public RequiredPassInfoMixin<BPFMIExpandStackArgPseudosPass> { |
| 65 | public: |
| 66 | PreservedAnalyses run(MachineFunction &MF, |
| 67 | MachineFunctionAnalysisManager &MFAM); |
| 68 | }; |
| 69 | |
| 70 | FunctionPass *createBPFMIExpandStackArgPseudosLegacyPass(); |
| 71 | |
| 72 | class BPFMIPreEmitPeepholePass |
| 73 | : public OptionalPassInfoMixin<BPFMIPreEmitPeepholePass> { |
| 74 | public: |
| 75 | PreservedAnalyses run(MachineFunction &MF, |
| 76 | MachineFunctionAnalysisManager &MFAM); |
| 77 | }; |
| 78 | |
| 79 | FunctionPass *createBPFMIPreEmitPeepholeLegacyPass(); |
| 80 | |
| 81 | class BPFMIPreEmitCheckingPass |
| 82 | : public OptionalPassInfoMixin<BPFMIPreEmitCheckingPass> { |
| 83 | public: |
| 84 | PreservedAnalyses run(MachineFunction &MF, |
| 85 | MachineFunctionAnalysisManager &MFAM); |
| 86 | }; |
| 87 | |
| 88 | FunctionPass *createBPFMIPreEmitCheckingLegacyPass(); |
| 89 | |
| 90 | InstructionSelector *createBPFInstructionSelector(const BPFTargetMachine &, |
| 91 | const BPFSubtarget &, |
| 92 | const BPFRegisterBankInfo &); |
| 93 | |
| 94 | void initializeBPFAsmPrinterPass(PassRegistry &); |
| 95 | void initializeBPFCheckAndAdjustIRLegacyPass(PassRegistry &); |
| 96 | void initializeBPFDAGToDAGISelLegacyPass(PassRegistry &); |
| 97 | void initializeBPFMIPeepholeLegacyPass(PassRegistry &); |
| 98 | void initializeBPFMIPreEmitCheckingLegacyPass(PassRegistry &); |
| 99 | void initializeBPFMIExpandStackArgPseudosLegacyPass(PassRegistry &); |
| 100 | void initializeBPFMIPreEmitPeepholeLegacyPass(PassRegistry &); |
| 101 | void initializeBPFMISimplifyPatchableLegacyPass(PassRegistry &); |
| 102 | |
| 103 | class BPFAbstractMemberAccessPass |
| 104 | : public RequiredPassInfoMixin<BPFAbstractMemberAccessPass> { |
| 105 | BPFTargetMachine *TM; |
| 106 | |
| 107 | public: |
| 108 | BPFAbstractMemberAccessPass(BPFTargetMachine *TM) : TM(TM) {} |
| 109 | PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM); |
| 110 | }; |
| 111 | |
| 112 | class BPFPreserveDITypePass |
| 113 | : public RequiredPassInfoMixin<BPFPreserveDITypePass> { |
| 114 | public: |
| 115 | PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM); |
| 116 | }; |
| 117 | |
| 118 | class BPFIRPeepholePass : public RequiredPassInfoMixin<BPFIRPeepholePass> { |
| 119 | public: |
| 120 | PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM); |
| 121 | }; |
| 122 | |
| 123 | class BPFASpaceCastSimplifyPass |
| 124 | : public RequiredPassInfoMixin<BPFASpaceCastSimplifyPass> { |
| 125 | public: |
| 126 | PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM); |
| 127 | }; |
| 128 | |
| 129 | class BPFAdjustOptPass : public OptionalPassInfoMixin<BPFAdjustOptPass> { |
| 130 | public: |
| 131 | PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM); |
| 132 | }; |
| 133 | |
| 134 | class BPFPreserveStaticOffsetPass |
| 135 | : public RequiredPassInfoMixin<BPFPreserveStaticOffsetPass> { |
| 136 | bool AllowPartial; |
| 137 | |
| 138 | public: |
| 139 | BPFPreserveStaticOffsetPass(bool AllowPartial) : AllowPartial(AllowPartial) {} |
| 140 | PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM); |
| 141 | |
| 142 | static std::pair<GetElementPtrInst *, LoadInst *> |
| 143 | reconstructLoad(CallInst *Call); |
| 144 | |
| 145 | static std::pair<GetElementPtrInst *, StoreInst *> |
| 146 | reconstructStore(CallInst *Call); |
| 147 | }; |
| 148 | |
| 149 | } // namespace llvm |
| 150 | |
| 151 | #endif |
| 152 | |