xref: /freebsd/contrib/llvm-project/llvm/lib/Target/BPF/BPF.h (revision 0fca6ea1d4eea4c934cfff25ac9ee8ad6fe95583)
10b57cec5SDimitry Andric //===-- BPF.h - Top-level interface for BPF representation ------*- C++ -*-===//
20b57cec5SDimitry Andric //
30b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
40b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
50b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
60b57cec5SDimitry Andric //
70b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
80b57cec5SDimitry Andric 
90b57cec5SDimitry Andric #ifndef LLVM_LIB_TARGET_BPF_BPF_H
100b57cec5SDimitry Andric #define LLVM_LIB_TARGET_BPF_BPF_H
110b57cec5SDimitry Andric 
120b57cec5SDimitry Andric #include "MCTargetDesc/BPFMCTargetDesc.h"
135f757f3fSDimitry Andric #include "llvm/IR/Instructions.h"
14e8d8bef9SDimitry Andric #include "llvm/IR/PassManager.h"
1581ad6265SDimitry Andric #include "llvm/Pass.h"
160b57cec5SDimitry Andric #include "llvm/Target/TargetMachine.h"
170b57cec5SDimitry Andric 
180b57cec5SDimitry Andric namespace llvm {
195f757f3fSDimitry Andric class BPFRegisterBankInfo;
205f757f3fSDimitry Andric class BPFSubtarget;
210b57cec5SDimitry Andric class BPFTargetMachine;
225f757f3fSDimitry Andric class InstructionSelector;
23bdd1243dSDimitry Andric class PassRegistry;
240b57cec5SDimitry Andric 
25e8d8bef9SDimitry Andric ModulePass *createBPFCheckAndAdjustIR();
260b57cec5SDimitry Andric 
270b57cec5SDimitry Andric FunctionPass *createBPFISelDag(BPFTargetMachine &TM);
280b57cec5SDimitry Andric FunctionPass *createBPFMISimplifyPatchablePass();
290b57cec5SDimitry Andric FunctionPass *createBPFMIPeepholePass();
300b57cec5SDimitry Andric FunctionPass *createBPFMIPreEmitPeepholePass();
310b57cec5SDimitry Andric FunctionPass *createBPFMIPreEmitCheckingPass();
320b57cec5SDimitry Andric 
335f757f3fSDimitry Andric InstructionSelector *createBPFInstructionSelector(const BPFTargetMachine &,
345f757f3fSDimitry Andric                                                   const BPFSubtarget &,
355f757f3fSDimitry Andric                                                   const BPFRegisterBankInfo &);
365f757f3fSDimitry Andric 
37e8d8bef9SDimitry Andric void initializeBPFCheckAndAdjustIRPass(PassRegistry&);
38*0fca6ea1SDimitry Andric void initializeBPFDAGToDAGISelLegacyPass(PassRegistry &);
390b57cec5SDimitry Andric void initializeBPFMIPeepholePass(PassRegistry &);
400b57cec5SDimitry Andric void initializeBPFMIPreEmitCheckingPass(PassRegistry&);
41bdd1243dSDimitry Andric void initializeBPFMIPreEmitPeepholePass(PassRegistry &);
42bdd1243dSDimitry Andric void initializeBPFMISimplifyPatchablePass(PassRegistry &);
43e8d8bef9SDimitry Andric 
44e8d8bef9SDimitry Andric class BPFAbstractMemberAccessPass
45e8d8bef9SDimitry Andric     : public PassInfoMixin<BPFAbstractMemberAccessPass> {
46e8d8bef9SDimitry Andric   BPFTargetMachine *TM;
47e8d8bef9SDimitry Andric 
48e8d8bef9SDimitry Andric public:
BPFAbstractMemberAccessPass(BPFTargetMachine * TM)49e8d8bef9SDimitry Andric   BPFAbstractMemberAccessPass(BPFTargetMachine *TM) : TM(TM) {}
50e8d8bef9SDimitry Andric   PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM);
51e8d8bef9SDimitry Andric 
isRequired()52e8d8bef9SDimitry Andric   static bool isRequired() { return true; }
53e8d8bef9SDimitry Andric };
54e8d8bef9SDimitry Andric 
55e8d8bef9SDimitry Andric class BPFPreserveDITypePass : public PassInfoMixin<BPFPreserveDITypePass> {
56e8d8bef9SDimitry Andric public:
57e8d8bef9SDimitry Andric   PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM);
58e8d8bef9SDimitry Andric 
isRequired()59e8d8bef9SDimitry Andric   static bool isRequired() { return true; }
60e8d8bef9SDimitry Andric };
61e8d8bef9SDimitry Andric 
62349cc55cSDimitry Andric class BPFIRPeepholePass : public PassInfoMixin<BPFIRPeepholePass> {
63349cc55cSDimitry Andric public:
64349cc55cSDimitry Andric   PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM);
65349cc55cSDimitry Andric 
isRequired()66349cc55cSDimitry Andric   static bool isRequired() { return true; }
67349cc55cSDimitry Andric };
68349cc55cSDimitry Andric 
69*0fca6ea1SDimitry Andric class BPFASpaceCastSimplifyPass
70*0fca6ea1SDimitry Andric     : public PassInfoMixin<BPFASpaceCastSimplifyPass> {
71*0fca6ea1SDimitry Andric public:
72*0fca6ea1SDimitry Andric   PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM);
73*0fca6ea1SDimitry Andric 
isRequired()74*0fca6ea1SDimitry Andric   static bool isRequired() { return true; }
75*0fca6ea1SDimitry Andric };
76*0fca6ea1SDimitry Andric 
77e8d8bef9SDimitry Andric class BPFAdjustOptPass : public PassInfoMixin<BPFAdjustOptPass> {
78e8d8bef9SDimitry Andric public:
79e8d8bef9SDimitry Andric   PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM);
80e8d8bef9SDimitry Andric };
815f757f3fSDimitry Andric 
825f757f3fSDimitry Andric class BPFPreserveStaticOffsetPass
835f757f3fSDimitry Andric     : public PassInfoMixin<BPFPreserveStaticOffsetPass> {
845f757f3fSDimitry Andric   bool AllowPartial;
855f757f3fSDimitry Andric 
865f757f3fSDimitry Andric public:
BPFPreserveStaticOffsetPass(bool AllowPartial)875f757f3fSDimitry Andric   BPFPreserveStaticOffsetPass(bool AllowPartial) : AllowPartial(AllowPartial) {}
885f757f3fSDimitry Andric   PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM);
895f757f3fSDimitry Andric 
isRequired()905f757f3fSDimitry Andric   static bool isRequired() { return true; }
915f757f3fSDimitry Andric 
925f757f3fSDimitry Andric   static std::pair<GetElementPtrInst *, LoadInst *>
935f757f3fSDimitry Andric   reconstructLoad(CallInst *Call);
945f757f3fSDimitry Andric 
955f757f3fSDimitry Andric   static std::pair<GetElementPtrInst *, StoreInst *>
965f757f3fSDimitry Andric   reconstructStore(CallInst *Call);
975f757f3fSDimitry Andric };
985f757f3fSDimitry Andric 
99e8d8bef9SDimitry Andric } // namespace llvm
1000b57cec5SDimitry Andric 
1010b57cec5SDimitry Andric #endif
102