1 //===-- NVPTXMCTargetDesc.cpp - NVPTX 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 NVPTX specific target descriptions.
10 //
11 //===----------------------------------------------------------------------===//
12
13 #include "NVPTXMCTargetDesc.h"
14 #include "NVPTXInstPrinter.h"
15 #include "NVPTXMCAsmInfo.h"
16 #include "NVPTXTargetStreamer.h"
17 #include "TargetInfo/NVPTXTargetInfo.h"
18 #include "llvm/MC/MCInstrInfo.h"
19 #include "llvm/MC/MCRegisterInfo.h"
20 #include "llvm/MC/MCSubtargetInfo.h"
21 #include "llvm/MC/TargetRegistry.h"
22
23 using namespace llvm;
24
25 #define GET_INSTRINFO_MC_DESC
26 #define ENABLE_INSTR_PREDICATE_VERIFIER
27 #include "NVPTXGenInstrInfo.inc"
28
29 #define GET_SUBTARGETINFO_MC_DESC
30 #include "NVPTXGenSubtargetInfo.inc"
31
32 #define GET_REGINFO_MC_DESC
33 #include "NVPTXGenRegisterInfo.inc"
34
createNVPTXMCInstrInfo()35 static MCInstrInfo *createNVPTXMCInstrInfo() {
36 MCInstrInfo *X = new MCInstrInfo();
37 InitNVPTXMCInstrInfo(X);
38 return X;
39 }
40
createNVPTXMCRegisterInfo(const Triple & TT)41 static MCRegisterInfo *createNVPTXMCRegisterInfo(const Triple &TT) {
42 MCRegisterInfo *X = new MCRegisterInfo();
43 // PTX does not have a return address register.
44 InitNVPTXMCRegisterInfo(X, 0);
45 return X;
46 }
47
48 static MCSubtargetInfo *
createNVPTXMCSubtargetInfo(const Triple & TT,StringRef CPU,StringRef FS)49 createNVPTXMCSubtargetInfo(const Triple &TT, StringRef CPU, StringRef FS) {
50 return createNVPTXMCSubtargetInfoImpl(TT, CPU, /*TuneCPU*/ CPU, FS);
51 }
52
createNVPTXMCInstPrinter(const Triple & T,unsigned SyntaxVariant,const MCAsmInfo & MAI,const MCInstrInfo & MII,const MCRegisterInfo & MRI)53 static MCInstPrinter *createNVPTXMCInstPrinter(const Triple &T,
54 unsigned SyntaxVariant,
55 const MCAsmInfo &MAI,
56 const MCInstrInfo &MII,
57 const MCRegisterInfo &MRI) {
58 if (SyntaxVariant == 0)
59 return new NVPTXInstPrinter(MAI, MII, MRI);
60 return nullptr;
61 }
62
createTargetAsmStreamer(MCStreamer & S,formatted_raw_ostream &,MCInstPrinter *)63 static MCTargetStreamer *createTargetAsmStreamer(MCStreamer &S,
64 formatted_raw_ostream &,
65 MCInstPrinter *) {
66 return new NVPTXAsmTargetStreamer(S);
67 }
68
createNullTargetStreamer(MCStreamer & S)69 static MCTargetStreamer *createNullTargetStreamer(MCStreamer &S) {
70 return new NVPTXTargetStreamer(S);
71 }
72
73 // Force static initialization.
LLVMInitializeNVPTXTargetMC()74 extern "C" LLVM_EXTERNAL_VISIBILITY void LLVMInitializeNVPTXTargetMC() {
75 for (Target *T : {&getTheNVPTXTarget32(), &getTheNVPTXTarget64()}) {
76 // Register the MC asm info.
77 RegisterMCAsmInfo<NVPTXMCAsmInfo> X(*T);
78
79 // Register the MC instruction info.
80 TargetRegistry::RegisterMCInstrInfo(*T, createNVPTXMCInstrInfo);
81
82 // Register the MC register info.
83 TargetRegistry::RegisterMCRegInfo(*T, createNVPTXMCRegisterInfo);
84
85 // Register the MC subtarget info.
86 TargetRegistry::RegisterMCSubtargetInfo(*T, createNVPTXMCSubtargetInfo);
87
88 // Register the MCInstPrinter.
89 TargetRegistry::RegisterMCInstPrinter(*T, createNVPTXMCInstPrinter);
90
91 // Register the MCTargetStreamer.
92 TargetRegistry::RegisterAsmTargetStreamer(*T, createTargetAsmStreamer);
93
94 // Register the MCTargetStreamer.
95 TargetRegistry::RegisterNullTargetStreamer(*T, createNullTargetStreamer);
96 }
97 }
98