1//===-- BPFFrameLowering.h - Define frame lowering for BPF -----*- 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_BPFASMPRINTER_H
10#define LLVM_LIB_TARGET_BPF_BPFASMPRINTER_H
11
12#include "BPFTargetMachine.h"
13#include "BTFDebug.h"
14#include "llvm/CodeGen/AsmPrinter.h"
15#include "llvm/CodeGen/MachineFunction.h"
16#include "llvm/CodeGen/MachineFunctionAnalysisManager.h"
17#include "llvm/IR/Analysis.h"
18#include "llvm/IR/PassManager.h"
19
20namespace llvm {
21
22class BPFAsmPrinter : public AsmPrinter {
23public:
24 explicit BPFAsmPrinter(TargetMachine &TM,
25 std::unique_ptr<MCStreamer> Streamer);
26 ~BPFAsmPrinter() override;
27
28 StringRef getPassName() const override { return "BPF Assembly Printer"; }
29 bool doInitialization(Module &M) override;
30 bool doFinalization(Module &M) override;
31 void printOperand(const MachineInstr *MI, int OpNum, raw_ostream &O);
32 bool PrintAsmOperand(const MachineInstr *MI, unsigned OpNo,
33 const char *ExtraCode, raw_ostream &O) override;
34 bool PrintAsmMemoryOperand(const MachineInstr *MI, unsigned OpNum,
35 const char *ExtraCode, raw_ostream &O) override;
36
37 void emitInstruction(const MachineInstr *MI) override;
38 void emitFunctionBodyEnd() override;
39 MCSymbol *getJTPublicSymbol(unsigned JTI);
40 void emitJumpTableInfo() override;
41
42 static char ID;
43
44private:
45 BTFDebug *BTF;
46 TargetMachine &TM;
47 bool SawTrapCall = false;
48
49 const BPFTargetMachine &getBTM() const;
50};
51
52class BPFAsmPrinterBeginPass
53 : public RequiredPassInfoMixin<BPFAsmPrinterBeginPass> {
54public:
55 PreservedAnalyses run(Module &M, ModuleAnalysisManager &MAM);
56};
57
58class BPFAsmPrinterPass : public RequiredPassInfoMixin<BPFAsmPrinterPass> {
59public:
60 PreservedAnalyses run(MachineFunction &MF,
61 MachineFunctionAnalysisManager &MFAM);
62};
63
64class BPFAsmPrinterEndPass
65 : public RequiredPassInfoMixin<BPFAsmPrinterEndPass> {
66public:
67 PreservedAnalyses run(Module &M, ModuleAnalysisManager &MAM);
68};
69
70} // namespace llvm
71
72#endif /* LLVM_LIB_TARGET_BPF_BPFASMPRINTER_H */
73