1f4a2713aSLionel Sambuc //===-- SparcMCTargetDesc.cpp - Sparc Target Descriptions -----------------===//
2f4a2713aSLionel Sambuc //
3f4a2713aSLionel Sambuc // The LLVM Compiler Infrastructure
4f4a2713aSLionel Sambuc //
5f4a2713aSLionel Sambuc // This file is distributed under the University of Illinois Open Source
6f4a2713aSLionel Sambuc // License. See LICENSE.TXT for details.
7f4a2713aSLionel Sambuc //
8f4a2713aSLionel Sambuc //===----------------------------------------------------------------------===//
9f4a2713aSLionel Sambuc //
10f4a2713aSLionel Sambuc // This file provides Sparc specific target descriptions.
11f4a2713aSLionel Sambuc //
12f4a2713aSLionel Sambuc //===----------------------------------------------------------------------===//
13f4a2713aSLionel Sambuc
14f4a2713aSLionel Sambuc #include "SparcMCTargetDesc.h"
15*0a6a1f1dSLionel Sambuc #include "InstPrinter/SparcInstPrinter.h"
16f4a2713aSLionel Sambuc #include "SparcMCAsmInfo.h"
17*0a6a1f1dSLionel Sambuc #include "SparcTargetStreamer.h"
18f4a2713aSLionel Sambuc #include "llvm/MC/MCCodeGenInfo.h"
19f4a2713aSLionel Sambuc #include "llvm/MC/MCInstrInfo.h"
20f4a2713aSLionel Sambuc #include "llvm/MC/MCRegisterInfo.h"
21f4a2713aSLionel Sambuc #include "llvm/MC/MCSubtargetInfo.h"
22f4a2713aSLionel Sambuc #include "llvm/Support/ErrorHandling.h"
23f4a2713aSLionel Sambuc #include "llvm/Support/TargetRegistry.h"
24f4a2713aSLionel Sambuc
25*0a6a1f1dSLionel Sambuc using namespace llvm;
26*0a6a1f1dSLionel Sambuc
27f4a2713aSLionel Sambuc #define GET_INSTRINFO_MC_DESC
28f4a2713aSLionel Sambuc #include "SparcGenInstrInfo.inc"
29f4a2713aSLionel Sambuc
30f4a2713aSLionel Sambuc #define GET_SUBTARGETINFO_MC_DESC
31f4a2713aSLionel Sambuc #include "SparcGenSubtargetInfo.inc"
32f4a2713aSLionel Sambuc
33f4a2713aSLionel Sambuc #define GET_REGINFO_MC_DESC
34f4a2713aSLionel Sambuc #include "SparcGenRegisterInfo.inc"
35f4a2713aSLionel Sambuc
createSparcMCAsmInfo(const MCRegisterInfo & MRI,StringRef TT)36*0a6a1f1dSLionel Sambuc static MCAsmInfo *createSparcMCAsmInfo(const MCRegisterInfo &MRI,
37*0a6a1f1dSLionel Sambuc StringRef TT) {
38*0a6a1f1dSLionel Sambuc MCAsmInfo *MAI = new SparcELFMCAsmInfo(TT);
39*0a6a1f1dSLionel Sambuc unsigned Reg = MRI.getDwarfRegNum(SP::O6, true);
40*0a6a1f1dSLionel Sambuc MCCFIInstruction Inst = MCCFIInstruction::createDefCfa(nullptr, Reg, 0);
41*0a6a1f1dSLionel Sambuc MAI->addInitialFrameState(Inst);
42*0a6a1f1dSLionel Sambuc return MAI;
43*0a6a1f1dSLionel Sambuc }
44*0a6a1f1dSLionel Sambuc
createSparcV9MCAsmInfo(const MCRegisterInfo & MRI,StringRef TT)45*0a6a1f1dSLionel Sambuc static MCAsmInfo *createSparcV9MCAsmInfo(const MCRegisterInfo &MRI,
46*0a6a1f1dSLionel Sambuc StringRef TT) {
47*0a6a1f1dSLionel Sambuc MCAsmInfo *MAI = new SparcELFMCAsmInfo(TT);
48*0a6a1f1dSLionel Sambuc unsigned Reg = MRI.getDwarfRegNum(SP::O6, true);
49*0a6a1f1dSLionel Sambuc MCCFIInstruction Inst = MCCFIInstruction::createDefCfa(nullptr, Reg, 2047);
50*0a6a1f1dSLionel Sambuc MAI->addInitialFrameState(Inst);
51*0a6a1f1dSLionel Sambuc return MAI;
52*0a6a1f1dSLionel Sambuc }
53f4a2713aSLionel Sambuc
createSparcMCInstrInfo()54f4a2713aSLionel Sambuc static MCInstrInfo *createSparcMCInstrInfo() {
55f4a2713aSLionel Sambuc MCInstrInfo *X = new MCInstrInfo();
56f4a2713aSLionel Sambuc InitSparcMCInstrInfo(X);
57f4a2713aSLionel Sambuc return X;
58f4a2713aSLionel Sambuc }
59f4a2713aSLionel Sambuc
createSparcMCRegisterInfo(StringRef TT)60f4a2713aSLionel Sambuc static MCRegisterInfo *createSparcMCRegisterInfo(StringRef TT) {
61f4a2713aSLionel Sambuc MCRegisterInfo *X = new MCRegisterInfo();
62*0a6a1f1dSLionel Sambuc InitSparcMCRegisterInfo(X, SP::O7);
63f4a2713aSLionel Sambuc return X;
64f4a2713aSLionel Sambuc }
65f4a2713aSLionel Sambuc
createSparcMCSubtargetInfo(StringRef TT,StringRef CPU,StringRef FS)66f4a2713aSLionel Sambuc static MCSubtargetInfo *createSparcMCSubtargetInfo(StringRef TT, StringRef CPU,
67f4a2713aSLionel Sambuc StringRef FS) {
68f4a2713aSLionel Sambuc MCSubtargetInfo *X = new MCSubtargetInfo();
69*0a6a1f1dSLionel Sambuc Triple TheTriple(TT);
70*0a6a1f1dSLionel Sambuc if (CPU.empty())
71*0a6a1f1dSLionel Sambuc CPU = (TheTriple.getArch() == Triple::sparcv9) ? "v9" : "v8";
72f4a2713aSLionel Sambuc InitSparcMCSubtargetInfo(X, TT, CPU, FS);
73f4a2713aSLionel Sambuc return X;
74f4a2713aSLionel Sambuc }
75f4a2713aSLionel Sambuc
76f4a2713aSLionel Sambuc // Code models. Some only make sense for 64-bit code.
77f4a2713aSLionel Sambuc //
78f4a2713aSLionel Sambuc // SunCC Reloc CodeModel Constraints
79f4a2713aSLionel Sambuc // abs32 Static Small text+data+bss linked below 2^32 bytes
80f4a2713aSLionel Sambuc // abs44 Static Medium text+data+bss linked below 2^44 bytes
81f4a2713aSLionel Sambuc // abs64 Static Large text smaller than 2^31 bytes
82f4a2713aSLionel Sambuc // pic13 PIC_ Small GOT < 2^13 bytes
83f4a2713aSLionel Sambuc // pic32 PIC_ Medium GOT < 2^32 bytes
84f4a2713aSLionel Sambuc //
85f4a2713aSLionel Sambuc // All code models require that the text segment is smaller than 2GB.
86f4a2713aSLionel Sambuc
createSparcMCCodeGenInfo(StringRef TT,Reloc::Model RM,CodeModel::Model CM,CodeGenOpt::Level OL)87f4a2713aSLionel Sambuc static MCCodeGenInfo *createSparcMCCodeGenInfo(StringRef TT, Reloc::Model RM,
88f4a2713aSLionel Sambuc CodeModel::Model CM,
89f4a2713aSLionel Sambuc CodeGenOpt::Level OL) {
90f4a2713aSLionel Sambuc MCCodeGenInfo *X = new MCCodeGenInfo();
91f4a2713aSLionel Sambuc
92*0a6a1f1dSLionel Sambuc // The default 32-bit code model is abs32/pic32 and the default 32-bit
93*0a6a1f1dSLionel Sambuc // code model for JIT is abs32.
94*0a6a1f1dSLionel Sambuc switch (CM) {
95*0a6a1f1dSLionel Sambuc default: break;
96*0a6a1f1dSLionel Sambuc case CodeModel::Default:
97*0a6a1f1dSLionel Sambuc case CodeModel::JITDefault: CM = CodeModel::Small; break;
98*0a6a1f1dSLionel Sambuc }
99f4a2713aSLionel Sambuc
100f4a2713aSLionel Sambuc X->InitMCCodeGenInfo(RM, CM, OL);
101f4a2713aSLionel Sambuc return X;
102f4a2713aSLionel Sambuc }
103f4a2713aSLionel Sambuc
createSparcV9MCCodeGenInfo(StringRef TT,Reloc::Model RM,CodeModel::Model CM,CodeGenOpt::Level OL)104f4a2713aSLionel Sambuc static MCCodeGenInfo *createSparcV9MCCodeGenInfo(StringRef TT, Reloc::Model RM,
105f4a2713aSLionel Sambuc CodeModel::Model CM,
106f4a2713aSLionel Sambuc CodeGenOpt::Level OL) {
107f4a2713aSLionel Sambuc MCCodeGenInfo *X = new MCCodeGenInfo();
108f4a2713aSLionel Sambuc
109*0a6a1f1dSLionel Sambuc // The default 64-bit code model is abs44/pic32 and the default 64-bit
110*0a6a1f1dSLionel Sambuc // code model for JIT is abs64.
111*0a6a1f1dSLionel Sambuc switch (CM) {
112*0a6a1f1dSLionel Sambuc default: break;
113*0a6a1f1dSLionel Sambuc case CodeModel::Default:
114*0a6a1f1dSLionel Sambuc CM = RM == Reloc::PIC_ ? CodeModel::Small : CodeModel::Medium;
115*0a6a1f1dSLionel Sambuc break;
116*0a6a1f1dSLionel Sambuc case CodeModel::JITDefault:
117*0a6a1f1dSLionel Sambuc CM = CodeModel::Large;
118*0a6a1f1dSLionel Sambuc break;
119*0a6a1f1dSLionel Sambuc }
120f4a2713aSLionel Sambuc
121f4a2713aSLionel Sambuc X->InitMCCodeGenInfo(RM, CM, OL);
122f4a2713aSLionel Sambuc return X;
123f4a2713aSLionel Sambuc }
124*0a6a1f1dSLionel Sambuc
createMCStreamer(const Target & T,StringRef TT,MCContext & Context,MCAsmBackend & MAB,raw_ostream & OS,MCCodeEmitter * Emitter,const MCSubtargetInfo & STI,bool RelaxAll)125*0a6a1f1dSLionel Sambuc static MCStreamer *createMCStreamer(const Target &T, StringRef TT,
126*0a6a1f1dSLionel Sambuc MCContext &Context, MCAsmBackend &MAB,
127*0a6a1f1dSLionel Sambuc raw_ostream &OS, MCCodeEmitter *Emitter,
128*0a6a1f1dSLionel Sambuc const MCSubtargetInfo &STI, bool RelaxAll) {
129*0a6a1f1dSLionel Sambuc MCStreamer *S = createELFStreamer(Context, MAB, OS, Emitter, RelaxAll);
130*0a6a1f1dSLionel Sambuc new SparcTargetELFStreamer(*S);
131*0a6a1f1dSLionel Sambuc return S;
132*0a6a1f1dSLionel Sambuc }
133*0a6a1f1dSLionel Sambuc
134*0a6a1f1dSLionel Sambuc static MCStreamer *
createMCAsmStreamer(MCContext & Ctx,formatted_raw_ostream & OS,bool isVerboseAsm,bool useDwarfDirectory,MCInstPrinter * InstPrint,MCCodeEmitter * CE,MCAsmBackend * TAB,bool ShowInst)135*0a6a1f1dSLionel Sambuc createMCAsmStreamer(MCContext &Ctx, formatted_raw_ostream &OS,
136*0a6a1f1dSLionel Sambuc bool isVerboseAsm, bool useDwarfDirectory,
137*0a6a1f1dSLionel Sambuc MCInstPrinter *InstPrint, MCCodeEmitter *CE,
138*0a6a1f1dSLionel Sambuc MCAsmBackend *TAB, bool ShowInst) {
139*0a6a1f1dSLionel Sambuc
140*0a6a1f1dSLionel Sambuc MCStreamer *S = llvm::createAsmStreamer(
141*0a6a1f1dSLionel Sambuc Ctx, OS, isVerboseAsm, useDwarfDirectory, InstPrint, CE, TAB, ShowInst);
142*0a6a1f1dSLionel Sambuc new SparcTargetAsmStreamer(*S, OS);
143*0a6a1f1dSLionel Sambuc return S;
144*0a6a1f1dSLionel Sambuc }
145*0a6a1f1dSLionel Sambuc
createSparcMCInstPrinter(const Target & T,unsigned SyntaxVariant,const MCAsmInfo & MAI,const MCInstrInfo & MII,const MCRegisterInfo & MRI,const MCSubtargetInfo & STI)146*0a6a1f1dSLionel Sambuc static MCInstPrinter *createSparcMCInstPrinter(const Target &T,
147*0a6a1f1dSLionel Sambuc unsigned SyntaxVariant,
148*0a6a1f1dSLionel Sambuc const MCAsmInfo &MAI,
149*0a6a1f1dSLionel Sambuc const MCInstrInfo &MII,
150*0a6a1f1dSLionel Sambuc const MCRegisterInfo &MRI,
151*0a6a1f1dSLionel Sambuc const MCSubtargetInfo &STI) {
152*0a6a1f1dSLionel Sambuc return new SparcInstPrinter(MAI, MII, MRI, STI);
153*0a6a1f1dSLionel Sambuc }
154*0a6a1f1dSLionel Sambuc
LLVMInitializeSparcTargetMC()155f4a2713aSLionel Sambuc extern "C" void LLVMInitializeSparcTargetMC() {
156f4a2713aSLionel Sambuc // Register the MC asm info.
157*0a6a1f1dSLionel Sambuc RegisterMCAsmInfoFn X(TheSparcTarget, createSparcMCAsmInfo);
158*0a6a1f1dSLionel Sambuc RegisterMCAsmInfoFn Y(TheSparcV9Target, createSparcV9MCAsmInfo);
159f4a2713aSLionel Sambuc
160f4a2713aSLionel Sambuc // Register the MC codegen info.
161f4a2713aSLionel Sambuc TargetRegistry::RegisterMCCodeGenInfo(TheSparcTarget,
162f4a2713aSLionel Sambuc createSparcMCCodeGenInfo);
163f4a2713aSLionel Sambuc TargetRegistry::RegisterMCCodeGenInfo(TheSparcV9Target,
164f4a2713aSLionel Sambuc createSparcV9MCCodeGenInfo);
165f4a2713aSLionel Sambuc
166f4a2713aSLionel Sambuc // Register the MC instruction info.
167f4a2713aSLionel Sambuc TargetRegistry::RegisterMCInstrInfo(TheSparcTarget, createSparcMCInstrInfo);
168*0a6a1f1dSLionel Sambuc TargetRegistry::RegisterMCInstrInfo(TheSparcV9Target, createSparcMCInstrInfo);
169f4a2713aSLionel Sambuc
170f4a2713aSLionel Sambuc // Register the MC register info.
171f4a2713aSLionel Sambuc TargetRegistry::RegisterMCRegInfo(TheSparcTarget, createSparcMCRegisterInfo);
172*0a6a1f1dSLionel Sambuc TargetRegistry::RegisterMCRegInfo(TheSparcV9Target,
173*0a6a1f1dSLionel Sambuc createSparcMCRegisterInfo);
174f4a2713aSLionel Sambuc
175f4a2713aSLionel Sambuc // Register the MC subtarget info.
176f4a2713aSLionel Sambuc TargetRegistry::RegisterMCSubtargetInfo(TheSparcTarget,
177f4a2713aSLionel Sambuc createSparcMCSubtargetInfo);
178*0a6a1f1dSLionel Sambuc TargetRegistry::RegisterMCSubtargetInfo(TheSparcV9Target,
179*0a6a1f1dSLionel Sambuc createSparcMCSubtargetInfo);
180*0a6a1f1dSLionel Sambuc
181*0a6a1f1dSLionel Sambuc // Register the MC Code Emitter.
182*0a6a1f1dSLionel Sambuc TargetRegistry::RegisterMCCodeEmitter(TheSparcTarget,
183*0a6a1f1dSLionel Sambuc createSparcMCCodeEmitter);
184*0a6a1f1dSLionel Sambuc TargetRegistry::RegisterMCCodeEmitter(TheSparcV9Target,
185*0a6a1f1dSLionel Sambuc createSparcMCCodeEmitter);
186*0a6a1f1dSLionel Sambuc
187*0a6a1f1dSLionel Sambuc //Register the asm backend.
188*0a6a1f1dSLionel Sambuc TargetRegistry::RegisterMCAsmBackend(TheSparcTarget,
189*0a6a1f1dSLionel Sambuc createSparcAsmBackend);
190*0a6a1f1dSLionel Sambuc TargetRegistry::RegisterMCAsmBackend(TheSparcV9Target,
191*0a6a1f1dSLionel Sambuc createSparcAsmBackend);
192*0a6a1f1dSLionel Sambuc
193*0a6a1f1dSLionel Sambuc // Register the object streamer.
194*0a6a1f1dSLionel Sambuc TargetRegistry::RegisterMCObjectStreamer(TheSparcTarget,
195*0a6a1f1dSLionel Sambuc createMCStreamer);
196*0a6a1f1dSLionel Sambuc TargetRegistry::RegisterMCObjectStreamer(TheSparcV9Target,
197*0a6a1f1dSLionel Sambuc createMCStreamer);
198*0a6a1f1dSLionel Sambuc
199*0a6a1f1dSLionel Sambuc // Register the asm streamer.
200*0a6a1f1dSLionel Sambuc TargetRegistry::RegisterAsmStreamer(TheSparcTarget,
201*0a6a1f1dSLionel Sambuc createMCAsmStreamer);
202*0a6a1f1dSLionel Sambuc TargetRegistry::RegisterAsmStreamer(TheSparcV9Target,
203*0a6a1f1dSLionel Sambuc createMCAsmStreamer);
204*0a6a1f1dSLionel Sambuc
205*0a6a1f1dSLionel Sambuc // Register the MCInstPrinter
206*0a6a1f1dSLionel Sambuc TargetRegistry::RegisterMCInstPrinter(TheSparcTarget,
207*0a6a1f1dSLionel Sambuc createSparcMCInstPrinter);
208*0a6a1f1dSLionel Sambuc TargetRegistry::RegisterMCInstPrinter(TheSparcV9Target,
209*0a6a1f1dSLionel Sambuc createSparcMCInstPrinter);
210f4a2713aSLionel Sambuc }
211