| 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 | #include "llvm/Support/Compiler.h" |
| 24 | |
| 25 | #define GET_INSTRINFO_MC_DESC |
| 26 | #define ENABLE_INSTR_PREDICATE_VERIFIER |
| 27 | #include "SPIRVGenInstrInfo.inc" |
| 28 | |
| 29 | #define GET_SUBTARGETINFO_MC_DESC |
| 30 | #include "SPIRVGenSubtargetInfo.inc" |
| 31 | |
| 32 | #define GET_REGINFO_MC_DESC |
| 33 | #include "SPIRVGenRegisterInfo.inc" |
| 34 | |
| 35 | using namespace llvm; |
| 36 | |
| 37 | static MCInstrInfo *createSPIRVMCInstrInfo() { |
| 38 | MCInstrInfo *X = new MCInstrInfo(); |
| 39 | InitSPIRVMCInstrInfo(II: X); |
| 40 | return X; |
| 41 | } |
| 42 | |
| 43 | static MCRegisterInfo *createSPIRVMCRegisterInfo(const Triple &TT) { |
| 44 | MCRegisterInfo *X = new MCRegisterInfo(); |
| 45 | return X; |
| 46 | } |
| 47 | |
| 48 | static MCSubtargetInfo * |
| 49 | createSPIRVMCSubtargetInfo(const Triple &TT, StringRef CPU, StringRef FS) { |
| 50 | return createSPIRVMCSubtargetInfoImpl(TT, CPU, /*TuneCPU*/ CPU, FS); |
| 51 | } |
| 52 | |
| 53 | static MCTargetStreamer *createTargetAsmStreamer(MCStreamer &S, |
| 54 | formatted_raw_ostream &, |
| 55 | MCInstPrinter *) { |
| 56 | return new SPIRVTargetStreamer(S); |
| 57 | } |
| 58 | |
| 59 | static MCInstPrinter *createSPIRVMCInstPrinter(const Triple &T, |
| 60 | unsigned SyntaxVariant, |
| 61 | const MCAsmInfo &MAI, |
| 62 | const MCInstrInfo &MII, |
| 63 | const MCRegisterInfo &MRI) { |
| 64 | assert(SyntaxVariant == 0); |
| 65 | return new SPIRVInstPrinter(MAI, MII, MRI); |
| 66 | } |
| 67 | |
| 68 | namespace { |
| 69 | |
| 70 | class SPIRVMCInstrAnalysis : public MCInstrAnalysis { |
| 71 | public: |
| 72 | explicit SPIRVMCInstrAnalysis(const MCInstrInfo *Info) |
| 73 | : MCInstrAnalysis(Info) {} |
| 74 | }; |
| 75 | |
| 76 | } // end anonymous namespace |
| 77 | |
| 78 | static MCInstrAnalysis *createSPIRVInstrAnalysis(const MCInstrInfo *Info) { |
| 79 | return new SPIRVMCInstrAnalysis(Info); |
| 80 | } |
| 81 | |
| 82 | extern "C" LLVM_ABI LLVM_EXTERNAL_VISIBILITY void |
| 83 | LLVMInitializeSPIRVTargetMC() { |
| 84 | for (Target *T : {&getTheSPIRV32Target(), &getTheSPIRV64Target(), |
| 85 | &getTheSPIRVLogicalTarget()}) { |
| 86 | RegisterMCAsmInfo<SPIRVMCAsmInfo> X(*T); |
| 87 | TargetRegistry::RegisterMCInstrInfo(T&: *T, Fn: createSPIRVMCInstrInfo); |
| 88 | TargetRegistry::RegisterMCRegInfo(T&: *T, Fn: createSPIRVMCRegisterInfo); |
| 89 | TargetRegistry::RegisterMCSubtargetInfo(T&: *T, Fn: createSPIRVMCSubtargetInfo); |
| 90 | TargetRegistry::RegisterMCInstPrinter(T&: *T, Fn: createSPIRVMCInstPrinter); |
| 91 | TargetRegistry::RegisterMCInstrAnalysis(T&: *T, Fn: createSPIRVInstrAnalysis); |
| 92 | TargetRegistry::RegisterMCCodeEmitter(T&: *T, Fn: createSPIRVMCCodeEmitter); |
| 93 | TargetRegistry::RegisterMCAsmBackend(T&: *T, Fn: createSPIRVAsmBackend); |
| 94 | TargetRegistry::RegisterAsmTargetStreamer(T&: *T, Fn: createTargetAsmStreamer); |
| 95 | } |
| 96 | } |
| 97 | |