xref: /freebsd/contrib/llvm-project/llvm/lib/Target/Sparc/MCTargetDesc/SparcMCTargetDesc.cpp (revision cb14a3fe5122c879eae1fb480ed7ce82a699ddb6)
1 //===-- SparcMCTargetDesc.cpp - Sparc Target Descriptions -----------------===//
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 Sparc specific target descriptions.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #include "SparcMCTargetDesc.h"
14 #include "SparcInstPrinter.h"
15 #include "SparcMCAsmInfo.h"
16 #include "SparcTargetStreamer.h"
17 #include "TargetInfo/SparcTargetInfo.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 #include "llvm/Support/ErrorHandling.h"
23 
24 namespace llvm {
25 namespace SparcASITag {
26 #define GET_ASITagsList_IMPL
27 #include "SparcGenSearchableTables.inc"
28 } // end namespace SparcASITag
29 } // end namespace llvm
30 
31 using namespace llvm;
32 
33 #define GET_INSTRINFO_MC_DESC
34 #define ENABLE_INSTR_PREDICATE_VERIFIER
35 #include "SparcGenInstrInfo.inc"
36 
37 #define GET_SUBTARGETINFO_MC_DESC
38 #include "SparcGenSubtargetInfo.inc"
39 
40 #define GET_REGINFO_MC_DESC
41 #include "SparcGenRegisterInfo.inc"
42 
43 static MCAsmInfo *createSparcMCAsmInfo(const MCRegisterInfo &MRI,
44                                        const Triple &TT,
45                                        const MCTargetOptions &Options) {
46   MCAsmInfo *MAI = new SparcELFMCAsmInfo(TT);
47   unsigned Reg = MRI.getDwarfRegNum(SP::O6, true);
48   MCCFIInstruction Inst = MCCFIInstruction::cfiDefCfa(nullptr, Reg, 0);
49   MAI->addInitialFrameState(Inst);
50   return MAI;
51 }
52 
53 static MCAsmInfo *createSparcV9MCAsmInfo(const MCRegisterInfo &MRI,
54                                          const Triple &TT,
55                                          const MCTargetOptions &Options) {
56   MCAsmInfo *MAI = new SparcELFMCAsmInfo(TT);
57   unsigned Reg = MRI.getDwarfRegNum(SP::O6, true);
58   MCCFIInstruction Inst = MCCFIInstruction::cfiDefCfa(nullptr, Reg, 2047);
59   MAI->addInitialFrameState(Inst);
60   return MAI;
61 }
62 
63 static MCInstrInfo *createSparcMCInstrInfo() {
64   MCInstrInfo *X = new MCInstrInfo();
65   InitSparcMCInstrInfo(X);
66   return X;
67 }
68 
69 static MCRegisterInfo *createSparcMCRegisterInfo(const Triple &TT) {
70   MCRegisterInfo *X = new MCRegisterInfo();
71   InitSparcMCRegisterInfo(X, SP::O7);
72   return X;
73 }
74 
75 static MCSubtargetInfo *
76 createSparcMCSubtargetInfo(const Triple &TT, StringRef CPU, StringRef FS) {
77   if (CPU.empty())
78     CPU = (TT.getArch() == Triple::sparcv9) ? "v9" : "v8";
79   return createSparcMCSubtargetInfoImpl(TT, CPU, /*TuneCPU*/ CPU, FS);
80 }
81 
82 static MCTargetStreamer *
83 createObjectTargetStreamer(MCStreamer &S, const MCSubtargetInfo &STI) {
84   return new SparcTargetELFStreamer(S);
85 }
86 
87 static MCTargetStreamer *createTargetAsmStreamer(MCStreamer &S,
88                                                  formatted_raw_ostream &OS,
89                                                  MCInstPrinter *InstPrint,
90                                                  bool isVerboseAsm) {
91   return new SparcTargetAsmStreamer(S, OS);
92 }
93 
94 static MCTargetStreamer *createNullTargetStreamer(MCStreamer &S) {
95   return new SparcTargetStreamer(S);
96 }
97 
98 static MCInstPrinter *createSparcMCInstPrinter(const Triple &T,
99                                                unsigned SyntaxVariant,
100                                                const MCAsmInfo &MAI,
101                                                const MCInstrInfo &MII,
102                                                const MCRegisterInfo &MRI) {
103   return new SparcInstPrinter(MAI, MII, MRI);
104 }
105 
106 extern "C" LLVM_EXTERNAL_VISIBILITY void LLVMInitializeSparcTargetMC() {
107   // Register the MC asm info.
108   RegisterMCAsmInfoFn X(getTheSparcTarget(), createSparcMCAsmInfo);
109   RegisterMCAsmInfoFn Y(getTheSparcV9Target(), createSparcV9MCAsmInfo);
110   RegisterMCAsmInfoFn Z(getTheSparcelTarget(), createSparcMCAsmInfo);
111 
112   for (Target *T :
113        {&getTheSparcTarget(), &getTheSparcV9Target(), &getTheSparcelTarget()}) {
114     // Register the MC instruction info.
115     TargetRegistry::RegisterMCInstrInfo(*T, createSparcMCInstrInfo);
116 
117     // Register the MC register info.
118     TargetRegistry::RegisterMCRegInfo(*T, createSparcMCRegisterInfo);
119 
120     // Register the MC subtarget info.
121     TargetRegistry::RegisterMCSubtargetInfo(*T, createSparcMCSubtargetInfo);
122 
123     // Register the MC Code Emitter.
124     TargetRegistry::RegisterMCCodeEmitter(*T, createSparcMCCodeEmitter);
125 
126     // Register the asm backend.
127     TargetRegistry::RegisterMCAsmBackend(*T, createSparcAsmBackend);
128 
129     // Register the object target streamer.
130     TargetRegistry::RegisterObjectTargetStreamer(*T,
131                                                  createObjectTargetStreamer);
132 
133     // Register the asm streamer.
134     TargetRegistry::RegisterAsmTargetStreamer(*T, createTargetAsmStreamer);
135 
136     // Register the null streamer.
137     TargetRegistry::RegisterNullTargetStreamer(*T, createNullTargetStreamer);
138 
139     // Register the MCInstPrinter
140     TargetRegistry::RegisterMCInstPrinter(*T, createSparcMCInstPrinter);
141   }
142 }
143