LLVM  16.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"
19 #include "llvm/MC/MCRegisterInfo.h"
21 #include "llvm/MC/TargetRegistry.h"
22 #include "llvm/Support/Host.h"
23 
24 #define GET_INSTRINFO_MC_DESC
25 #define ENABLE_INSTR_PREDICATE_VERIFIER
26 #include "BPFGenInstrInfo.inc"
27 
28 #define GET_SUBTARGETINFO_MC_DESC
29 #include "BPFGenSubtargetInfo.inc"
30 
31 #define GET_REGINFO_MC_DESC
32 #include "BPFGenRegisterInfo.inc"
33 
34 using namespace llvm;
35 
37  MCInstrInfo *X = new MCInstrInfo();
38  InitBPFMCInstrInfo(X);
39  return X;
40 }
41 
44  InitBPFMCRegisterInfo(X, BPF::R11 /* RAReg doesn't exist */);
45  return X;
46 }
47 
49  StringRef CPU, StringRef FS) {
50  return createBPFMCSubtargetInfoImpl(TT, CPU, /*TuneCPU*/ CPU, FS);
51 }
52 
54  std::unique_ptr<MCAsmBackend> &&MAB,
55  std::unique_ptr<MCObjectWriter> &&OW,
56  std::unique_ptr<MCCodeEmitter> &&Emitter,
57  bool RelaxAll) {
58  return createELFStreamer(Ctx, std::move(MAB), std::move(OW), std::move(Emitter),
59  RelaxAll);
60 }
61 
63  unsigned SyntaxVariant,
64  const MCAsmInfo &MAI,
65  const MCInstrInfo &MII,
66  const MCRegisterInfo &MRI) {
67  if (SyntaxVariant == 0)
68  return new BPFInstPrinter(MAI, MII, MRI);
69  return nullptr;
70 }
71 
72 namespace {
73 
74 class BPFMCInstrAnalysis : public MCInstrAnalysis {
75 public:
76  explicit BPFMCInstrAnalysis(const MCInstrInfo *Info)
77  : MCInstrAnalysis(Info) {}
78 
79  bool evaluateBranch(const MCInst &Inst, uint64_t Addr, uint64_t Size,
80  uint64_t &Target) const override {
81  // The target is the 3rd operand of cond inst and the 1st of uncond inst.
82  int16_t Imm;
83  if (isConditionalBranch(Inst)) {
84  Imm = Inst.getOperand(2).getImm();
85  } else if (isUnconditionalBranch(Inst))
86  Imm = Inst.getOperand(0).getImm();
87  else
88  return false;
89 
90  Target = Addr + Size + Imm * Size;
91  return true;
92  }
93 };
94 
95 } // end anonymous namespace
96 
98  return new BPFMCInstrAnalysis(Info);
99 }
100 
102  for (Target *T :
104  // Register the MC asm info.
106 
107  // Register the MC instruction info.
109 
110  // Register the MC register info.
112 
113  // Register the MC subtarget info.
116 
117  // Register the object streamer
119 
120  // Register the MCInstPrinter.
122 
123  // Register the MC instruction analyzer.
125  }
126 
127  // Register the MC code emitter
132 
133  // Register the ASM Backend
138 
144  } else {
149  }
150 
151 }
llvm::Check::Size
@ Size
Definition: FileCheck.h:77
BPFMCTargetDesc.h
llvm::getTheBPFleTarget
Target & getTheBPFleTarget()
Definition: BPFTargetInfo.cpp:14
llvm::createBPFbeMCCodeEmitter
MCCodeEmitter * createBPFbeMCCodeEmitter(const MCInstrInfo &MCII, MCContext &Ctx)
Definition: BPFMCCodeEmitter.cpp:73
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
llvm::BPFInstPrinter
Definition: BPFInstPrinter.h:19
T
llvm::MCContext
Context object for machine code objects.
Definition: MCContext.h:77
llvm::Target
Target - Wrapper for Target specific information.
Definition: TargetRegistry.h:150
llvm::MCAsmInfo
This class is intended to be used as a base class for asm properties and features specific to the tar...
Definition: MCAsmInfo.h:56
Host.h
createBPFInstrAnalysis
static MCInstrAnalysis * createBPFInstrAnalysis(const MCInstrInfo *Info)
Definition: BPFMCTargetDesc.cpp:97
llvm::TargetRegistry::RegisterMCInstrAnalysis
static void RegisterMCInstrAnalysis(Target &T, Target::MCInstrAnalysisCtorFnTy Fn)
RegisterMCInstrAnalysis - Register a MCInstrAnalysis implementation for the given target.
Definition: TargetRegistry.h:880
llvm::Triple
Triple - Helper class for working with autoconf configuration names.
Definition: Triple.h:44
llvm::MCInst
Instances of this class represent a single low-level machine instruction.
Definition: MCInst.h:184
llvm::TargetRegistry::RegisterMCInstPrinter
static void RegisterMCInstPrinter(Target &T, Target::MCInstPrinterCtorTy Fn)
RegisterMCInstPrinter - Register a MCInstPrinter implementation for the given target.
Definition: TargetRegistry.h:987
BPFTargetInfo.h
llvm::MCStreamer
Streaming machine code generation interface.
Definition: MCStreamer.h:213
Emitter
dxil DXContainer Global Emitter
Definition: DXContainerGlobals.cpp:67
MCInstrInfo.h
llvm::MCOperand::getImm
int64_t getImm() const
Definition: MCInst.h:80
llvm::MCInstrAnalysis
Definition: MCInstrAnalysis.h:29
MCSubtargetInfo.h
Info
Analysis containing CSE Info
Definition: CSEInfo.cpp:27
X
static GCMetadataPrinterRegistry::Add< ErlangGCPrinter > X("erlang", "erlang-compatible garbage collector")
llvm::TargetRegistry::RegisterMCAsmBackend
static void RegisterMCAsmBackend(Target &T, Target::MCAsmBackendCtorTy Fn)
RegisterMCAsmBackend - Register a MCAsmBackend implementation for the given target.
Definition: TargetRegistry.h:934
uint64_t
llvm::MCInstPrinter
This is an instance of a target assembly language printer that converts an MCInst to valid target ass...
Definition: MCInstPrinter.h:43
LLVM_EXTERNAL_VISIBILITY
#define LLVM_EXTERNAL_VISIBILITY
Definition: Compiler.h:127
Addr
uint64_t Addr
Definition: ELFObjHandler.cpp:79
move
compiles ldr LCPI1_0 ldr ldr mov lsr tst moveq r1 ldr LCPI1_1 and r0 bx lr It would be better to do something like to fold the shift into the conditional move
Definition: README.txt:546
llvm::createBPFAsmBackend
MCAsmBackend * createBPFAsmBackend(const Target &T, const MCSubtargetInfo &STI, const MCRegisterInfo &MRI, const MCTargetOptions &Options)
Definition: BPFAsmBackend.cpp:106
BPFMCAsmInfo.h
MCRegisterInfo.h
llvm::X86AS::FS
@ FS
Definition: X86.h:200
llvm::getTheBPFbeTarget
Target & getTheBPFbeTarget()
Definition: BPFTargetInfo.cpp:18
llvm::TargetRegistry::RegisterMCSubtargetInfo
static void RegisterMCSubtargetInfo(Target &T, Target::MCSubtargetInfoCtorFnTy Fn)
RegisterMCSubtargetInfo - Register a MCSubtargetInfo implementation for the given target.
Definition: TargetRegistry.h:907
createBPFMCInstPrinter
static MCInstPrinter * createBPFMCInstPrinter(const Triple &T, unsigned SyntaxVariant, const MCAsmInfo &MAI, const MCInstrInfo &MII, const MCRegisterInfo &MRI)
Definition: BPFMCTargetDesc.cpp:62
createBPFMCRegisterInfo
static MCRegisterInfo * createBPFMCRegisterInfo(const Triple &TT)
Definition: BPFMCTargetDesc.cpp:42
MCInstrAnalysis.h
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
llvm::RegisterMCAsmInfo
RegisterMCAsmInfo - Helper template for registering a target assembly info implementation.
Definition: TargetRegistry.h:1157
llvm::MCRegisterInfo
MCRegisterInfo base class - We assume that the target defines a static array of MCRegisterDesc object...
Definition: MCRegisterInfo.h:135
MRI
unsigned const MachineRegisterInfo * MRI
Definition: AArch64AdvSIMDScalarPass.cpp:105
isUnconditionalBranch
static bool isUnconditionalBranch(Instruction *Term)
Definition: ADCE.cpp:211
llvm::createELFStreamer
MCStreamer * createELFStreamer(MCContext &Ctx, std::unique_ptr< MCAsmBackend > &&TAB, std::unique_ptr< MCObjectWriter > &&OW, std::unique_ptr< MCCodeEmitter > &&CE, bool RelaxAll)
Definition: MCELFStreamer.cpp:890
llvm::TargetRegistry::RegisterMCInstrInfo
static void RegisterMCInstrInfo(Target &T, Target::MCInstrInfoCtorFnTy Fn)
RegisterMCInstrInfo - Register a MCInstrInfo implementation for the given target.
Definition: TargetRegistry.h:874
llvm::TargetRegistry::RegisterMCCodeEmitter
static void RegisterMCCodeEmitter(Target &T, Target::MCCodeEmitterCtorTy Fn)
RegisterMCCodeEmitter - Register a MCCodeEmitter implementation for the given target.
Definition: TargetRegistry.h:1000
llvm::createBPFMCCodeEmitter
MCCodeEmitter * createBPFMCCodeEmitter(const MCInstrInfo &MCII, MCContext &Ctx)
Definition: BPFMCCodeEmitter.cpp:68
llvm::MCInstrInfo
Interface to description of machine instruction set.
Definition: MCInstrInfo.h:26
llvm::TargetRegistry::RegisterMCRegInfo
static void RegisterMCRegInfo(Target &T, Target::MCRegInfoCtorFnTy Fn)
RegisterMCRegInfo - Register a MCRegisterInfo implementation for the given target.
Definition: TargetRegistry.h:894
llvm::TargetRegistry::RegisterELFStreamer
static void RegisterELFStreamer(Target &T, Target::ELFStreamerCtorTy Fn)
Definition: TargetRegistry.h:1012
createBPFMCInstrInfo
static MCInstrInfo * createBPFMCInstrInfo()
Definition: BPFMCTargetDesc.cpp:36
BPFInstPrinter.h
llvm::RISCVMatInt::Imm
@ Imm
Definition: RISCVMatInt.h:23
createBPFMCSubtargetInfo
static MCSubtargetInfo * createBPFMCSubtargetInfo(const Triple &TT, StringRef CPU, StringRef FS)
Definition: BPFMCTargetDesc.cpp:48
llvm::getTheBPFTarget
Target & getTheBPFTarget()
Definition: BPFTargetInfo.cpp:22
llvm::sys::IsLittleEndianHost
static const bool IsLittleEndianHost
Definition: SwapByteOrder.h:101
llvm::MCInst::getOperand
const MCOperand & getOperand(unsigned i) const
Definition: MCInst.h:206
createBPFMCStreamer
static MCStreamer * createBPFMCStreamer(const Triple &T, MCContext &Ctx, std::unique_ptr< MCAsmBackend > &&MAB, std::unique_ptr< MCObjectWriter > &&OW, std::unique_ptr< MCCodeEmitter > &&Emitter, bool RelaxAll)
Definition: BPFMCTargetDesc.cpp:53
llvm::createBPFbeAsmBackend
MCAsmBackend * createBPFbeAsmBackend(const Target &T, const MCSubtargetInfo &STI, const MCRegisterInfo &MRI, const MCTargetOptions &Options)
Definition: BPFAsmBackend.cpp:113
TargetRegistry.h
llvm::MCSubtargetInfo
Generic base class for all target subtargets.
Definition: MCSubtargetInfo.h:76
LLVMInitializeBPFTargetMC
LLVM_EXTERNAL_VISIBILITY void LLVMInitializeBPFTargetMC()
Definition: BPFMCTargetDesc.cpp:101