xref: /freebsd/contrib/llvm-project/llvm/lib/Target/SPIRV/MCTargetDesc/SPIRVMCTargetDesc.cpp (revision 2e3507c25e42292b45a5482e116d278f5515d04d)
1 //===-- SPIRVMCTargetDesc.cpp - SPIR-V Target Descriptions ----*- 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 // This file provides SPIR-V specific target descriptions.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #include "SPIRVMCTargetDesc.h"
14 #include "SPIRVInstPrinter.h"
15 #include "SPIRVMCAsmInfo.h"
16 #include "SPIRVTargetStreamer.h"
17 #include "TargetInfo/SPIRVTargetInfo.h"
18 #include "llvm/MC/MCInstrAnalysis.h"
19 #include "llvm/MC/MCInstrInfo.h"
20 #include "llvm/MC/MCRegisterInfo.h"
21 #include "llvm/MC/MCSubtargetInfo.h"
22 #include "llvm/MC/TargetRegistry.h"
23 
24 #define GET_INSTRINFO_MC_DESC
25 #define ENABLE_INSTR_PREDICATE_VERIFIER
26 #include "SPIRVGenInstrInfo.inc"
27 
28 #define GET_SUBTARGETINFO_MC_DESC
29 #include "SPIRVGenSubtargetInfo.inc"
30 
31 #define GET_REGINFO_MC_DESC
32 #include "SPIRVGenRegisterInfo.inc"
33 
34 using namespace llvm;
35 
36 static MCInstrInfo *createSPIRVMCInstrInfo() {
37   MCInstrInfo *X = new MCInstrInfo();
38   InitSPIRVMCInstrInfo(X);
39   return X;
40 }
41 
42 static MCRegisterInfo *createSPIRVMCRegisterInfo(const Triple &TT) {
43   MCRegisterInfo *X = new MCRegisterInfo();
44   return X;
45 }
46 
47 static MCSubtargetInfo *
48 createSPIRVMCSubtargetInfo(const Triple &TT, StringRef CPU, StringRef FS) {
49   return createSPIRVMCSubtargetInfoImpl(TT, CPU, /*TuneCPU*/ CPU, FS);
50 }
51 
52 static MCStreamer *
53 createSPIRVMCStreamer(const Triple &T, MCContext &Ctx,
54                       std::unique_ptr<MCAsmBackend> &&MAB,
55                       std::unique_ptr<MCObjectWriter> &&OW,
56                       std::unique_ptr<MCCodeEmitter> &&Emitter, bool RelaxAll) {
57   return createSPIRVStreamer(Ctx, std::move(MAB), std::move(OW),
58                              std::move(Emitter), RelaxAll);
59 }
60 
61 static MCTargetStreamer *createTargetAsmStreamer(MCStreamer &S,
62                                                  formatted_raw_ostream &,
63                                                  MCInstPrinter *, bool) {
64   return new SPIRVTargetStreamer(S);
65 }
66 
67 static MCInstPrinter *createSPIRVMCInstPrinter(const Triple &T,
68                                                unsigned SyntaxVariant,
69                                                const MCAsmInfo &MAI,
70                                                const MCInstrInfo &MII,
71                                                const MCRegisterInfo &MRI) {
72   assert(SyntaxVariant == 0);
73   return new SPIRVInstPrinter(MAI, MII, MRI);
74 }
75 
76 namespace {
77 
78 class SPIRVMCInstrAnalysis : public MCInstrAnalysis {
79 public:
80   explicit SPIRVMCInstrAnalysis(const MCInstrInfo *Info)
81       : MCInstrAnalysis(Info) {}
82 };
83 
84 } // end anonymous namespace
85 
86 static MCInstrAnalysis *createSPIRVInstrAnalysis(const MCInstrInfo *Info) {
87   return new SPIRVMCInstrAnalysis(Info);
88 }
89 
90 extern "C" LLVM_EXTERNAL_VISIBILITY void LLVMInitializeSPIRVTargetMC() {
91   for (Target *T : {&getTheSPIRV32Target(), &getTheSPIRV64Target()}) {
92     RegisterMCAsmInfo<SPIRVMCAsmInfo> X(*T);
93     TargetRegistry::RegisterMCInstrInfo(*T, createSPIRVMCInstrInfo);
94     TargetRegistry::RegisterMCRegInfo(*T, createSPIRVMCRegisterInfo);
95     TargetRegistry::RegisterMCSubtargetInfo(*T, createSPIRVMCSubtargetInfo);
96     TargetRegistry::RegisterSPIRVStreamer(*T, createSPIRVMCStreamer);
97     TargetRegistry::RegisterMCInstPrinter(*T, createSPIRVMCInstPrinter);
98     TargetRegistry::RegisterMCInstrAnalysis(*T, createSPIRVInstrAnalysis);
99     TargetRegistry::RegisterMCCodeEmitter(*T, createSPIRVMCCodeEmitter);
100     TargetRegistry::RegisterMCAsmBackend(*T, createSPIRVAsmBackend);
101     TargetRegistry::RegisterAsmTargetStreamer(*T, createTargetAsmStreamer);
102   }
103 }
104