LLVM  10.0.0svn
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/Support/Host.h"
23 
24 #define GET_INSTRINFO_MC_DESC
25 #include "BPFGenInstrInfo.inc"
26 
27 #define GET_SUBTARGETINFO_MC_DESC
28 #include "BPFGenSubtargetInfo.inc"
29 
30 #define GET_REGINFO_MC_DESC
31 #include "BPFGenRegisterInfo.inc"
32 
33 using namespace llvm;
34 
36  MCInstrInfo *X = new MCInstrInfo();
37  InitBPFMCInstrInfo(X);
38  return X;
39 }
40 
43  InitBPFMCRegisterInfo(X, BPF::R11 /* RAReg doesn't exist */);
44  return X;
45 }
46 
48  StringRef CPU, StringRef FS) {
49  return createBPFMCSubtargetInfoImpl(TT, CPU, FS);
50 }
51 
53  std::unique_ptr<MCAsmBackend> &&MAB,
54  std::unique_ptr<MCObjectWriter> &&OW,
55  std::unique_ptr<MCCodeEmitter> &&Emitter,
56  bool RelaxAll) {
57  return createELFStreamer(Ctx, std::move(MAB), std::move(OW), std::move(Emitter),
58  RelaxAll);
59 }
60 
62  unsigned SyntaxVariant,
63  const MCAsmInfo &MAI,
64  const MCInstrInfo &MII,
65  const MCRegisterInfo &MRI) {
66  if (SyntaxVariant == 0)
67  return new BPFInstPrinter(MAI, MII, MRI);
68  return nullptr;
69 }
70 
71 namespace {
72 
73 class BPFMCInstrAnalysis : public MCInstrAnalysis {
74 public:
75  explicit BPFMCInstrAnalysis(const MCInstrInfo *Info)
76  : MCInstrAnalysis(Info) {}
77 
78  bool evaluateBranch(const MCInst &Inst, uint64_t Addr, uint64_t Size,
79  uint64_t &Target) const override {
80  // The target is the 3rd operand of cond inst and the 1st of uncond inst.
81  int16_t Imm;
82  if (isConditionalBranch(Inst)) {
83  Imm = Inst.getOperand(2).getImm();
84  } else if (isUnconditionalBranch(Inst))
85  Imm = Inst.getOperand(0).getImm();
86  else
87  return false;
88 
89  Target = Addr + Size + Imm * Size;
90  return true;
91  }
92 };
93 
94 } // end anonymous namespace
95 
97  return new BPFMCInstrAnalysis(Info);
98 }
99 
100 extern "C" void LLVMInitializeBPFTargetMC() {
101  for (Target *T :
103  // Register the MC asm info.
105 
106  // Register the MC instruction info.
108 
109  // Register the MC register info.
111 
112  // Register the MC subtarget info.
115 
116  // Register the object streamer
118 
119  // Register the MCInstPrinter.
121 
122  // Register the MC instruction analyzer.
124  }
125 
126  // Register the MC code emitter
131 
132  // Register the ASM Backend
137 
143  } else {
148  }
149 
150 }
static GCMetadataPrinterRegistry::Add< ErlangGCPrinter > X("erlang", "erlang-compatible garbage collector")
This class represents lattice values for constants.
Definition: AllocatorList.h:23
static void RegisterMCInstrAnalysis(Target &T, Target::MCInstrAnalysisCtorFnTy Fn)
RegisterMCInstrAnalysis - Register a MCInstrAnalysis implementation for the given target...
static MCSubtargetInfo * createBPFMCSubtargetInfo(const Triple &TT, StringRef CPU, StringRef FS)
static void RegisterMCInstPrinter(Target &T, Target::MCInstPrinterCtorTy Fn)
RegisterMCInstPrinter - Register a MCInstPrinter implementation for the given target.
Context object for machine code objects.
Definition: MCContext.h:65
MCCodeEmitter * createBPFbeMCCodeEmitter(const MCInstrInfo &MCII, const MCRegisterInfo &MRI, MCContext &Ctx)
static const bool IsLittleEndianHost
Definition: Host.h:49
static bool isUnconditionalBranch(Instruction *Term)
Definition: ADCE.cpp:209
MCAsmBackend * createBPFAsmBackend(const Target &T, const MCSubtargetInfo &STI, const MCRegisterInfo &MRI, const MCTargetOptions &Options)
Instances of this class represent a single low-level machine instruction.
Definition: MCInst.h:158
Analysis containing CSE Info
Definition: CSEInfo.cpp:20
MCRegisterInfo base class - We assume that the target defines a static array of MCRegisterDesc object...
This class is intended to be used as a base class for asm properties and features specific to the tar...
Definition: MCAsmInfo.h:56
int64_t getImm() const
Definition: MCInst.h:75
static void RegisterMCAsmBackend(Target &T, Target::MCAsmBackendCtorTy Fn)
RegisterMCAsmBackend - Register a MCAsmBackend implementation for the given target.
Streaming machine code generation interface.
Definition: MCStreamer.h:190
unsigned const MachineRegisterInfo * MRI
void LLVMInitializeBPFTargetMC()
MCStreamer * createELFStreamer(MCContext &Ctx, std::unique_ptr< MCAsmBackend > &&TAB, std::unique_ptr< MCObjectWriter > &&OW, std::unique_ptr< MCCodeEmitter > &&CE, bool RelaxAll)
Interface to description of machine instruction set.
Definition: MCInstrInfo.h:23
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)
static void RegisterMCSubtargetInfo(Target &T, Target::MCSubtargetInfoCtorFnTy Fn)
RegisterMCSubtargetInfo - Register a MCSubtargetInfo implementation for the given target...
Triple - Helper class for working with autoconf configuration names.
Definition: Triple.h:43
static MCInstrAnalysis * createBPFInstrAnalysis(const MCInstrInfo *Info)
const MCOperand & getOperand(unsigned i) const
Definition: MCInst.h:179
static void RegisterMCCodeEmitter(Target &T, Target::MCCodeEmitterCtorTy Fn)
RegisterMCCodeEmitter - Register a MCCodeEmitter implementation for the given target.
MCAsmBackend * createBPFbeAsmBackend(const Target &T, const MCSubtargetInfo &STI, const MCRegisterInfo &MRI, const MCTargetOptions &Options)
static MCInstPrinter * createBPFMCInstPrinter(const Triple &T, unsigned SyntaxVariant, const MCAsmInfo &MAI, const MCInstrInfo &MII, const MCRegisterInfo &MRI)
static void RegisterMCRegInfo(Target &T, Target::MCRegInfoCtorFnTy Fn)
RegisterMCRegInfo - Register a MCRegisterInfo implementation for the given target.
Target - Wrapper for Target specific information.
static MCInstrInfo * createBPFMCInstrInfo()
This is an instance of a target assembly language printer that converts an MCInst to valid target ass...
Definition: MCInstPrinter.h:39
static void RegisterMCInstrInfo(Target &T, Target::MCInstrInfoCtorFnTy Fn)
RegisterMCInstrInfo - Register a MCInstrInfo implementation for the given target. ...
Generic base class for all target subtargets.
uint32_t Size
Definition: Profile.cpp:46
static void RegisterELFStreamer(Target &T, Target::ELFStreamerCtorTy Fn)
Target & getTheBPFleTarget()
static MCRegisterInfo * createBPFMCRegisterInfo(const Triple &TT)
RegisterMCAsmInfo - Helper template for registering a target assembly info implementation.
MCCodeEmitter * createBPFMCCodeEmitter(const MCInstrInfo &MCII, const MCRegisterInfo &MRI, MCContext &Ctx)
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:48
Target & getTheBPFbeTarget()
Target & getTheBPFTarget()