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 MCTargetStreamer *createTargetAsmStreamer(MCStreamer &S, 53 formatted_raw_ostream &, 54 MCInstPrinter *) { 55 return new SPIRVTargetStreamer(S); 56 } 57 58 static MCInstPrinter *createSPIRVMCInstPrinter(const Triple &T, 59 unsigned SyntaxVariant, 60 const MCAsmInfo &MAI, 61 const MCInstrInfo &MII, 62 const MCRegisterInfo &MRI) { 63 assert(SyntaxVariant == 0); 64 return new SPIRVInstPrinter(MAI, MII, MRI); 65 } 66 67 namespace { 68 69 class SPIRVMCInstrAnalysis : public MCInstrAnalysis { 70 public: 71 explicit SPIRVMCInstrAnalysis(const MCInstrInfo *Info) 72 : MCInstrAnalysis(Info) {} 73 }; 74 75 } // end anonymous namespace 76 77 static MCInstrAnalysis *createSPIRVInstrAnalysis(const MCInstrInfo *Info) { 78 return new SPIRVMCInstrAnalysis(Info); 79 } 80 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); 93 } 94 } 95