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