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
23using 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
35static MCInstrInfo *createNVPTXMCInstrInfo() {
36 MCInstrInfo *X = new MCInstrInfo();
37 InitNVPTXMCInstrInfo(II: X);
38 return X;
39}
40
41static MCRegisterInfo *createNVPTXMCRegisterInfo(const Triple &TT) {
42 MCRegisterInfo *X = new MCRegisterInfo();
43 // PTX does not have a return address register.
44 InitNVPTXMCRegisterInfo(RI: X, RA: 0);
45 return X;
46}
47
48static MCSubtargetInfo *
49createNVPTXMCSubtargetInfo(const Triple &TT, StringRef CPU, StringRef FS) {
50 return createNVPTXMCSubtargetInfoImpl(TT, CPU, /*TuneCPU*/ CPU, FS);
51}
52
53static 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
63static MCTargetStreamer *createTargetAsmStreamer(MCStreamer &S,
64 formatted_raw_ostream &,
65 MCInstPrinter *) {
66 return new NVPTXAsmTargetStreamer(S);
67}
68
69static MCTargetStreamer *createNullTargetStreamer(MCStreamer &S) {
70 return new NVPTXTargetStreamer(S);
71}
72
73// Force static initialization.
74extern "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&: *T, Fn: createNVPTXMCInstrInfo);
81
82 // Register the MC register info.
83 TargetRegistry::RegisterMCRegInfo(T&: *T, Fn: createNVPTXMCRegisterInfo);
84
85 // Register the MC subtarget info.
86 TargetRegistry::RegisterMCSubtargetInfo(T&: *T, Fn: createNVPTXMCSubtargetInfo);
87
88 // Register the MCInstPrinter.
89 TargetRegistry::RegisterMCInstPrinter(T&: *T, Fn: createNVPTXMCInstPrinter);
90
91 // Register the MCTargetStreamer.
92 TargetRegistry::RegisterAsmTargetStreamer(T&: *T, Fn: createTargetAsmStreamer);
93
94 // Register the MCTargetStreamer.
95 TargetRegistry::RegisterNullTargetStreamer(T&: *T, Fn: createNullTargetStreamer);
96 }
97}
98