1 //===-- SPIRVMCTargetDesc.cpp - SPIR-V Target Descriptions ----*- C++ -*---===//
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
7 //===----------------------------------------------------------------------===//
9 // This file provides SPIR-V specific target descriptions.
11 //===----------------------------------------------------------------------===//
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"
24 #define GET_INSTRINFO_MC_DESC
25 #define ENABLE_INSTR_PREDICATE_VERIFIER
26 #include "SPIRVGenInstrInfo.inc"
28 #define GET_SUBTARGETINFO_MC_DESC
29 #include "SPIRVGenSubtargetInfo.inc"
31 #define GET_REGINFO_MC_DESC
32 #include "SPIRVGenRegisterInfo.inc"
36 static MCInstrInfo
*createSPIRVMCInstrInfo() {
37 MCInstrInfo
*X
= new MCInstrInfo();
38 InitSPIRVMCInstrInfo(X
);
42 static MCRegisterInfo
*createSPIRVMCRegisterInfo(const Triple
&TT
) {
43 MCRegisterInfo
*X
= new MCRegisterInfo();
47 static MCSubtargetInfo
*
48 createSPIRVMCSubtargetInfo(const Triple
&TT
, StringRef CPU
, StringRef FS
) {
49 return createSPIRVMCSubtargetInfoImpl(TT
, CPU
, /*TuneCPU*/ CPU
, FS
);
52 static MCTargetStreamer
*createTargetAsmStreamer(MCStreamer
&S
,
53 formatted_raw_ostream
&,
55 return new SPIRVTargetStreamer(S
);
58 static MCInstPrinter
*createSPIRVMCInstPrinter(const Triple
&T
,
59 unsigned SyntaxVariant
,
61 const MCInstrInfo
&MII
,
62 const MCRegisterInfo
&MRI
) {
63 assert(SyntaxVariant
== 0);
64 return new SPIRVInstPrinter(MAI
, MII
, MRI
);
69 class SPIRVMCInstrAnalysis
: public MCInstrAnalysis
{
71 explicit SPIRVMCInstrAnalysis(const MCInstrInfo
*Info
)
72 : MCInstrAnalysis(Info
) {}
75 } // end anonymous namespace
77 static MCInstrAnalysis
*createSPIRVInstrAnalysis(const MCInstrInfo
*Info
) {
78 return new SPIRVMCInstrAnalysis(Info
);
81 extern "C" LLVM_EXTERNAL_VISIBILITY
void LLVMInitializeSPIRVTargetMC() {
82 for (Target
*T
: {&getTheSPIRV32Target(), &getTheSPIRV64Target(),
83 &getTheSPIRVLogicalTarget()}) {
84 RegisterMCAsmInfo
<SPIRVMCAsmInfo
> X(*T
);
85 TargetRegistry::RegisterMCInstrInfo(*T
, createSPIRVMCInstrInfo
);
86 TargetRegistry::RegisterMCRegInfo(*T
, createSPIRVMCRegisterInfo
);
87 TargetRegistry::RegisterMCSubtargetInfo(*T
, createSPIRVMCSubtargetInfo
);
88 TargetRegistry::RegisterMCInstPrinter(*T
, createSPIRVMCInstPrinter
);
89 TargetRegistry::RegisterMCInstrAnalysis(*T
, createSPIRVInstrAnalysis
);
90 TargetRegistry::RegisterMCCodeEmitter(*T
, createSPIRVMCCodeEmitter
);
91 TargetRegistry::RegisterMCAsmBackend(*T
, createSPIRVAsmBackend
);
92 TargetRegistry::RegisterAsmTargetStreamer(*T
, createTargetAsmStreamer
);