1 //===-- BPFMCTargetDesc.cpp - BPF Target Descriptions ---------------------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file provides BPF specific target descriptions.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #include "BPF.h"
15 #include "BPFMCTargetDesc.h"
16 #include "BPFMCAsmInfo.h"
17 #include "InstPrinter/BPFInstPrinter.h"
18 #include "llvm/MC/MCCodeGenInfo.h"
19 #include "llvm/MC/MCInstrInfo.h"
20 #include "llvm/MC/MCRegisterInfo.h"
21 #include "llvm/MC/MCStreamer.h"
22 #include "llvm/MC/MCSubtargetInfo.h"
23 #include "llvm/Support/ErrorHandling.h"
24 #include "llvm/Support/TargetRegistry.h"
25
26 #define GET_INSTRINFO_MC_DESC
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
35 using namespace llvm;
36
createBPFMCInstrInfo()37 static MCInstrInfo *createBPFMCInstrInfo() {
38 MCInstrInfo *X = new MCInstrInfo();
39 InitBPFMCInstrInfo(X);
40 return X;
41 }
42
createBPFMCRegisterInfo(const Triple & TT)43 static MCRegisterInfo *createBPFMCRegisterInfo(const Triple &TT) {
44 MCRegisterInfo *X = new MCRegisterInfo();
45 InitBPFMCRegisterInfo(X, BPF::R11 /* RAReg doesn't exist */);
46 return X;
47 }
48
createBPFMCSubtargetInfo(const Triple & TT,StringRef CPU,StringRef FS)49 static MCSubtargetInfo *createBPFMCSubtargetInfo(const Triple &TT,
50 StringRef CPU, StringRef FS) {
51 return createBPFMCSubtargetInfoImpl(TT, CPU, FS);
52 }
53
createBPFMCCodeGenInfo(const Triple & TT,Reloc::Model RM,CodeModel::Model CM,CodeGenOpt::Level OL)54 static MCCodeGenInfo *createBPFMCCodeGenInfo(const Triple &TT, Reloc::Model RM,
55 CodeModel::Model CM,
56 CodeGenOpt::Level OL) {
57 MCCodeGenInfo *X = new MCCodeGenInfo();
58 X->initMCCodeGenInfo(RM, CM, OL);
59 return X;
60 }
61
createBPFMCStreamer(const Triple & T,MCContext & Ctx,MCAsmBackend & MAB,raw_pwrite_stream & OS,MCCodeEmitter * Emitter,bool RelaxAll)62 static MCStreamer *createBPFMCStreamer(const Triple &T,
63 MCContext &Ctx, MCAsmBackend &MAB,
64 raw_pwrite_stream &OS, MCCodeEmitter *Emitter,
65 bool RelaxAll) {
66 return createELFStreamer(Ctx, MAB, OS, Emitter, RelaxAll);
67 }
68
createBPFMCInstPrinter(const Triple & T,unsigned SyntaxVariant,const MCAsmInfo & MAI,const MCInstrInfo & MII,const MCRegisterInfo & MRI)69 static MCInstPrinter *createBPFMCInstPrinter(const Triple &T,
70 unsigned SyntaxVariant,
71 const MCAsmInfo &MAI,
72 const MCInstrInfo &MII,
73 const MCRegisterInfo &MRI) {
74 if (SyntaxVariant == 0)
75 return new BPFInstPrinter(MAI, MII, MRI);
76 return 0;
77 }
78
LLVMInitializeBPFTargetMC()79 extern "C" void LLVMInitializeBPFTargetMC() {
80 for (Target *T : {&TheBPFleTarget, &TheBPFbeTarget, &TheBPFTarget}) {
81 // Register the MC asm info.
82 RegisterMCAsmInfo<BPFMCAsmInfo> X(*T);
83
84 // Register the MC codegen info.
85 TargetRegistry::RegisterMCCodeGenInfo(*T, createBPFMCCodeGenInfo);
86
87 // Register the MC instruction info.
88 TargetRegistry::RegisterMCInstrInfo(*T, createBPFMCInstrInfo);
89
90 // Register the MC register info.
91 TargetRegistry::RegisterMCRegInfo(*T, createBPFMCRegisterInfo);
92
93 // Register the MC subtarget info.
94 TargetRegistry::RegisterMCSubtargetInfo(*T,
95 createBPFMCSubtargetInfo);
96
97 // Register the object streamer
98 TargetRegistry::RegisterELFStreamer(*T, createBPFMCStreamer);
99
100 // Register the MCInstPrinter.
101 TargetRegistry::RegisterMCInstPrinter(*T, createBPFMCInstPrinter);
102 }
103
104 // Register the MC code emitter
105 TargetRegistry::RegisterMCCodeEmitter(TheBPFleTarget, createBPFMCCodeEmitter);
106 TargetRegistry::RegisterMCCodeEmitter(TheBPFbeTarget, createBPFbeMCCodeEmitter);
107
108 // Register the ASM Backend
109 TargetRegistry::RegisterMCAsmBackend(TheBPFleTarget, createBPFAsmBackend);
110 TargetRegistry::RegisterMCAsmBackend(TheBPFbeTarget, createBPFbeAsmBackend);
111
112 if (sys::IsLittleEndianHost) {
113 TargetRegistry::RegisterMCCodeEmitter(TheBPFTarget, createBPFMCCodeEmitter);
114 TargetRegistry::RegisterMCAsmBackend(TheBPFTarget, createBPFAsmBackend);
115 } else {
116 TargetRegistry::RegisterMCCodeEmitter(TheBPFTarget, createBPFbeMCCodeEmitter);
117 TargetRegistry::RegisterMCAsmBackend(TheBPFTarget, createBPFbeAsmBackend);
118 }
119 }
120