xref: /freebsd/contrib/llvm-project/llvm/lib/Target/BPF/BPF.h (revision 0fca6ea1d4eea4c934cfff25ac9ee8ad6fe95583)
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 ModulePass *createBPFCheckAndAdjustIR();
26 
27 FunctionPass *createBPFISelDag(BPFTargetMachine &TM);
28 FunctionPass *createBPFMISimplifyPatchablePass();
29 FunctionPass *createBPFMIPeepholePass();
30 FunctionPass *createBPFMIPreEmitPeepholePass();
31 FunctionPass *createBPFMIPreEmitCheckingPass();
32 
33 InstructionSelector *createBPFInstructionSelector(const BPFTargetMachine &,
34                                                   const BPFSubtarget &,
35                                                   const BPFRegisterBankInfo &);
36 
37 void initializeBPFCheckAndAdjustIRPass(PassRegistry&);
38 void initializeBPFDAGToDAGISelLegacyPass(PassRegistry &);
39 void initializeBPFMIPeepholePass(PassRegistry &);
40 void initializeBPFMIPreEmitCheckingPass(PassRegistry&);
41 void initializeBPFMIPreEmitPeepholePass(PassRegistry &);
42 void initializeBPFMISimplifyPatchablePass(PassRegistry &);
43 
44 class BPFAbstractMemberAccessPass
45     : public PassInfoMixin<BPFAbstractMemberAccessPass> {
46   BPFTargetMachine *TM;
47 
48 public:
BPFAbstractMemberAccessPass(BPFTargetMachine * TM)49   BPFAbstractMemberAccessPass(BPFTargetMachine *TM) : TM(TM) {}
50   PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM);
51 
isRequired()52   static bool isRequired() { return true; }
53 };
54 
55 class BPFPreserveDITypePass : public PassInfoMixin<BPFPreserveDITypePass> {
56 public:
57   PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM);
58 
isRequired()59   static bool isRequired() { return true; }
60 };
61 
62 class BPFIRPeepholePass : public PassInfoMixin<BPFIRPeepholePass> {
63 public:
64   PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM);
65 
isRequired()66   static bool isRequired() { return true; }
67 };
68 
69 class BPFASpaceCastSimplifyPass
70     : public PassInfoMixin<BPFASpaceCastSimplifyPass> {
71 public:
72   PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM);
73 
isRequired()74   static bool isRequired() { return true; }
75 };
76 
77 class BPFAdjustOptPass : public PassInfoMixin<BPFAdjustOptPass> {
78 public:
79   PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM);
80 };
81 
82 class BPFPreserveStaticOffsetPass
83     : public PassInfoMixin<BPFPreserveStaticOffsetPass> {
84   bool AllowPartial;
85 
86 public:
BPFPreserveStaticOffsetPass(bool AllowPartial)87   BPFPreserveStaticOffsetPass(bool AllowPartial) : AllowPartial(AllowPartial) {}
88   PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM);
89 
isRequired()90   static bool isRequired() { return true; }
91 
92   static std::pair<GetElementPtrInst *, LoadInst *>
93   reconstructLoad(CallInst *Call);
94 
95   static std::pair<GetElementPtrInst *, StoreInst *>
96   reconstructStore(CallInst *Call);
97 };
98 
99 } // namespace llvm
100 
101 #endif
102