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