xref: /freebsd/contrib/llvm-project/llvm/lib/Target/NVPTX/MCTargetDesc/NVPTXMCTargetDesc.cpp (revision 753f127f3ace09432b2baeffd71a308760641a62)
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 
35 static MCInstrInfo *createNVPTXMCInstrInfo() {
36   MCInstrInfo *X = new MCInstrInfo();
37   InitNVPTXMCInstrInfo(X);
38   return X;
39 }
40 
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 *
49 createNVPTXMCSubtargetInfo(const Triple &TT, StringRef CPU, StringRef FS) {
50   return createNVPTXMCSubtargetInfoImpl(TT, CPU, /*TuneCPU*/ CPU, FS);
51 }
52 
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 
63 static MCTargetStreamer *createTargetAsmStreamer(MCStreamer &S,
64                                                  formatted_raw_ostream &,
65                                                  MCInstPrinter *, bool) {
66   return new NVPTXTargetStreamer(S);
67 }
68 
69 // Force static initialization.
70 extern "C" LLVM_EXTERNAL_VISIBILITY void LLVMInitializeNVPTXTargetMC() {
71   for (Target *T : {&getTheNVPTXTarget32(), &getTheNVPTXTarget64()}) {
72     // Register the MC asm info.
73     RegisterMCAsmInfo<NVPTXMCAsmInfo> X(*T);
74 
75     // Register the MC instruction info.
76     TargetRegistry::RegisterMCInstrInfo(*T, createNVPTXMCInstrInfo);
77 
78     // Register the MC register info.
79     TargetRegistry::RegisterMCRegInfo(*T, createNVPTXMCRegisterInfo);
80 
81     // Register the MC subtarget info.
82     TargetRegistry::RegisterMCSubtargetInfo(*T, createNVPTXMCSubtargetInfo);
83 
84     // Register the MCInstPrinter.
85     TargetRegistry::RegisterMCInstPrinter(*T, createNVPTXMCInstPrinter);
86 
87     // Register the MCTargetStreamer.
88     TargetRegistry::RegisterAsmTargetStreamer(*T, createTargetAsmStreamer);
89   }
90 }
91