LLVM 22.0.0git
BPFMCTargetDesc.cpp
Go to the documentation of this file.
1//===-- BPFMCTargetDesc.cpp - BPF Target Descriptions ---------------------===//
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// This file provides BPF specific target descriptions.
10//
11//===----------------------------------------------------------------------===//
12
18#include "llvm/MC/MCInstrInfo.h"
24
25#define GET_INSTRINFO_MC_DESC
26#define ENABLE_INSTR_PREDICATE_VERIFIER
27#include "BPFGenInstrInfo.inc"
28
29#define GET_SUBTARGETINFO_MC_DESC
30#include "BPFGenSubtargetInfo.inc"
31
32#define GET_REGINFO_MC_DESC
33#include "BPFGenRegisterInfo.inc"
34
35using namespace llvm;
36
38 MCInstrInfo *X = new MCInstrInfo();
39 InitBPFMCInstrInfo(X);
40 return X;
41}
42
45 InitBPFMCRegisterInfo(X, BPF::R11 /* RAReg doesn't exist */);
46 return X;
47}
48
50 StringRef CPU, StringRef FS) {
51 return createBPFMCSubtargetInfoImpl(TT, CPU, /*TuneCPU*/ CPU, FS);
52}
53
54static MCStreamer *
56 std::unique_ptr<MCAsmBackend> &&MAB,
57 std::unique_ptr<MCObjectWriter> &&OW,
58 std::unique_ptr<MCCodeEmitter> &&Emitter) {
59 return createELFStreamer(Ctx, std::move(MAB), std::move(OW),
60 std::move(Emitter));
61}
62
64 unsigned SyntaxVariant,
65 const MCAsmInfo &MAI,
66 const MCInstrInfo &MII,
67 const MCRegisterInfo &MRI) {
68 if (SyntaxVariant == 0)
69 return new BPFInstPrinter(MAI, MII, MRI);
70 return nullptr;
71}
72
73namespace {
74
75class BPFMCInstrAnalysis : public MCInstrAnalysis {
76public:
77 explicit BPFMCInstrAnalysis(const MCInstrInfo *Info)
79
81 uint64_t &Target) const override {
82 // The target is the 3rd operand of cond inst and the 1st of uncond inst.
83 int32_t Imm;
84 if (isConditionalBranch(Inst)) {
85 if (Inst.getOpcode() == BPF::JCOND)
86 Imm = (short)Inst.getOperand(0).getImm();
87 else
88 Imm = (short)Inst.getOperand(2).getImm();
89 } else if (isUnconditionalBranch(Inst)) {
90 if (Inst.getOpcode() == BPF::JMP)
91 Imm = (short)Inst.getOperand(0).getImm();
92 else
93 Imm = (int)Inst.getOperand(0).getImm();
94 } else
95 return false;
96
97 Target = Addr + Size + Imm * Size;
98 return true;
99 }
100};
101
102} // end anonymous namespace
103
105 return new BPFMCInstrAnalysis(Info);
106}
107
109 for (Target *T :
111 // Register the MC asm info.
113
114 // Register the MC instruction info.
116
117 // Register the MC register info.
119
120 // Register the MC subtarget info.
123
124 // Register the object streamer
126
127 // Register the MCInstPrinter.
129
130 // Register the MC instruction analyzer.
132 }
133
134 // Register the MC code emitter
139
140 // Register the ASM Backend
145
151 } else {
156 }
157}
unsigned const MachineRegisterInfo * MRI
static MCStreamer * createBPFMCStreamer(const Triple &T, MCContext &Ctx, std::unique_ptr< MCAsmBackend > &&MAB, std::unique_ptr< MCObjectWriter > &&OW, std::unique_ptr< MCCodeEmitter > &&Emitter)
LLVM_ABI LLVM_EXTERNAL_VISIBILITY void LLVMInitializeBPFTargetMC()
static MCSubtargetInfo * createBPFMCSubtargetInfo(const Triple &TT, StringRef CPU, StringRef FS)
static MCInstrAnalysis * createBPFInstrAnalysis(const MCInstrInfo *Info)
static MCInstPrinter * createBPFMCInstPrinter(const Triple &T, unsigned SyntaxVariant, const MCAsmInfo &MAI, const MCInstrInfo &MII, const MCRegisterInfo &MRI)
static MCInstrInfo * createBPFMCInstrInfo()
static MCRegisterInfo * createBPFMCRegisterInfo(const Triple &TT)
Analysis containing CSE Info
Definition: CSEInfo.cpp:27
#define LLVM_ABI
Definition: Compiler.h:213
#define LLVM_EXTERNAL_VISIBILITY
Definition: Compiler.h:132
dxil DXContainer Global Emitter
uint64_t Addr
uint64_t Size
static GCMetadataPrinterRegistry::Add< ErlangGCPrinter > X("erlang", "erlang-compatible garbage collector")
This class is intended to be used as a base class for asm properties and features specific to the tar...
Definition: MCAsmInfo.h:64
Context object for machine code objects.
Definition: MCContext.h:83
This is an instance of a target assembly language printer that converts an MCInst to valid target ass...
Definition: MCInstPrinter.h:46
Instances of this class represent a single low-level machine instruction.
Definition: MCInst.h:188
unsigned getOpcode() const
Definition: MCInst.h:202
const MCOperand & getOperand(unsigned i) const
Definition: MCInst.h:210
virtual bool isUnconditionalBranch(const MCInst &Inst) const
virtual bool evaluateBranch(const MCInst &Inst, uint64_t Addr, uint64_t Size, uint64_t &Target) const
Given a branch instruction try to get the address the branch targets.
virtual bool isConditionalBranch(const MCInst &Inst) const
Interface to description of machine instruction set.
Definition: MCInstrInfo.h:27
int64_t getImm() const
Definition: MCInst.h:84
MCRegisterInfo base class - We assume that the target defines a static array of MCRegisterDesc object...
Streaming machine code generation interface.
Definition: MCStreamer.h:220
Generic base class for all target subtargets.
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:55
Target - Wrapper for Target specific information.
Triple - Helper class for working with autoconf configuration names.
Definition: Triple.h:47
constexpr bool IsLittleEndianHost
Definition: SwapByteOrder.h:29
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
LLVM_ABI MCStreamer * createELFStreamer(MCContext &Ctx, std::unique_ptr< MCAsmBackend > &&TAB, std::unique_ptr< MCObjectWriter > &&OW, std::unique_ptr< MCCodeEmitter > &&CE)
Target & getTheBPFleTarget()
MCAsmBackend * createBPFAsmBackend(const Target &T, const MCSubtargetInfo &STI, const MCRegisterInfo &MRI, const MCTargetOptions &Options)
Target & getTheBPFbeTarget()
MCAsmBackend * createBPFbeAsmBackend(const Target &T, const MCSubtargetInfo &STI, const MCRegisterInfo &MRI, const MCTargetOptions &Options)
Target & getTheBPFTarget()
MCCodeEmitter * createBPFbeMCCodeEmitter(const MCInstrInfo &MCII, MCContext &Ctx)
MCCodeEmitter * createBPFMCCodeEmitter(const MCInstrInfo &MCII, MCContext &Ctx)
RegisterMCAsmInfo - Helper template for registering a target assembly info implementation.
static void RegisterMCRegInfo(Target &T, Target::MCRegInfoCtorFnTy Fn)
RegisterMCRegInfo - Register a MCRegisterInfo implementation for the given target.
static void RegisterMCAsmBackend(Target &T, Target::MCAsmBackendCtorTy Fn)
RegisterMCAsmBackend - Register a MCAsmBackend implementation for the given target.
static void RegisterMCCodeEmitter(Target &T, Target::MCCodeEmitterCtorTy Fn)
RegisterMCCodeEmitter - Register a MCCodeEmitter implementation for the given target.
static void RegisterMCSubtargetInfo(Target &T, Target::MCSubtargetInfoCtorFnTy Fn)
RegisterMCSubtargetInfo - Register a MCSubtargetInfo implementation for the given target.
static void RegisterMCInstrAnalysis(Target &T, Target::MCInstrAnalysisCtorFnTy Fn)
RegisterMCInstrAnalysis - Register a MCInstrAnalysis implementation for the given target.
static void RegisterELFStreamer(Target &T, Target::ELFStreamerCtorTy Fn)
static void RegisterMCInstPrinter(Target &T, Target::MCInstPrinterCtorTy Fn)
RegisterMCInstPrinter - Register a MCInstPrinter implementation for the given target.
static void RegisterMCInstrInfo(Target &T, Target::MCInstrInfoCtorFnTy Fn)
RegisterMCInstrInfo - Register a MCInstrInfo implementation for the given target.