blob: 9a4a290a550f4397080c7e14db596b782a0dbd98 [file] [log] [blame]
Ulrich Weigand5f613df2013-05-06 16:15:19 +00001//===-- SystemZMCTargetDesc.cpp - SystemZ target descriptions -------------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10#include "SystemZMCTargetDesc.h"
11#include "InstPrinter/SystemZInstPrinter.h"
12#include "SystemZMCAsmInfo.h"
13#include "llvm/MC/MCCodeGenInfo.h"
14#include "llvm/MC/MCInstrInfo.h"
15#include "llvm/MC/MCStreamer.h"
16#include "llvm/MC/MCSubtargetInfo.h"
17#include "llvm/Support/TargetRegistry.h"
18
19#define GET_INSTRINFO_MC_DESC
20#include "SystemZGenInstrInfo.inc"
21
22#define GET_SUBTARGETINFO_MC_DESC
23#include "SystemZGenSubtargetInfo.inc"
24
25#define GET_REGINFO_MC_DESC
26#include "SystemZGenRegisterInfo.inc"
27
28using namespace llvm;
29
Richard Sandiford7d37cd22013-05-14 09:36:44 +000030const unsigned SystemZMC::GR32Regs[16] = {
Richard Sandiford7789b082013-09-30 08:48:38 +000031 SystemZ::R0L, SystemZ::R1L, SystemZ::R2L, SystemZ::R3L,
32 SystemZ::R4L, SystemZ::R5L, SystemZ::R6L, SystemZ::R7L,
33 SystemZ::R8L, SystemZ::R9L, SystemZ::R10L, SystemZ::R11L,
34 SystemZ::R12L, SystemZ::R13L, SystemZ::R14L, SystemZ::R15L
Richard Sandiford7d37cd22013-05-14 09:36:44 +000035};
36
Richard Sandifordf9496062013-09-30 10:45:16 +000037const unsigned SystemZMC::GRH32Regs[16] = {
38 SystemZ::R0H, SystemZ::R1H, SystemZ::R2H, SystemZ::R3H,
39 SystemZ::R4H, SystemZ::R5H, SystemZ::R6H, SystemZ::R7H,
40 SystemZ::R8H, SystemZ::R9H, SystemZ::R10H, SystemZ::R11H,
41 SystemZ::R12H, SystemZ::R13H, SystemZ::R14H, SystemZ::R15H
42};
43
Richard Sandiford7d37cd22013-05-14 09:36:44 +000044const unsigned SystemZMC::GR64Regs[16] = {
45 SystemZ::R0D, SystemZ::R1D, SystemZ::R2D, SystemZ::R3D,
46 SystemZ::R4D, SystemZ::R5D, SystemZ::R6D, SystemZ::R7D,
47 SystemZ::R8D, SystemZ::R9D, SystemZ::R10D, SystemZ::R11D,
48 SystemZ::R12D, SystemZ::R13D, SystemZ::R14D, SystemZ::R15D
49};
50
51const unsigned SystemZMC::GR128Regs[16] = {
52 SystemZ::R0Q, 0, SystemZ::R2Q, 0,
53 SystemZ::R4Q, 0, SystemZ::R6Q, 0,
54 SystemZ::R8Q, 0, SystemZ::R10Q, 0,
55 SystemZ::R12Q, 0, SystemZ::R14Q, 0
56};
57
58const unsigned SystemZMC::FP32Regs[16] = {
59 SystemZ::F0S, SystemZ::F1S, SystemZ::F2S, SystemZ::F3S,
60 SystemZ::F4S, SystemZ::F5S, SystemZ::F6S, SystemZ::F7S,
61 SystemZ::F8S, SystemZ::F9S, SystemZ::F10S, SystemZ::F11S,
62 SystemZ::F12S, SystemZ::F13S, SystemZ::F14S, SystemZ::F15S
63};
64
65const unsigned SystemZMC::FP64Regs[16] = {
66 SystemZ::F0D, SystemZ::F1D, SystemZ::F2D, SystemZ::F3D,
67 SystemZ::F4D, SystemZ::F5D, SystemZ::F6D, SystemZ::F7D,
68 SystemZ::F8D, SystemZ::F9D, SystemZ::F10D, SystemZ::F11D,
69 SystemZ::F12D, SystemZ::F13D, SystemZ::F14D, SystemZ::F15D
70};
71
72const unsigned SystemZMC::FP128Regs[16] = {
73 SystemZ::F0Q, SystemZ::F1Q, 0, 0,
74 SystemZ::F4Q, SystemZ::F5Q, 0, 0,
75 SystemZ::F8Q, SystemZ::F9Q, 0, 0,
76 SystemZ::F12Q, SystemZ::F13Q, 0, 0
77};
78
Richard Sandiford35ec4e3562013-09-25 10:11:07 +000079unsigned SystemZMC::getFirstReg(unsigned Reg) {
80 static unsigned Map[SystemZ::NUM_TARGET_REGS];
81 static bool Initialized = false;
82 if (!Initialized) {
83 for (unsigned I = 0; I < 16; ++I) {
84 Map[GR32Regs[I]] = I;
85 Map[GR64Regs[I]] = I;
86 Map[GR128Regs[I]] = I;
87 Map[FP32Regs[I]] = I;
88 Map[FP64Regs[I]] = I;
89 Map[FP128Regs[I]] = I;
90 }
91 }
92 assert(Reg < SystemZ::NUM_TARGET_REGS);
93 return Map[Reg];
94}
95
Rafael Espindola227144c2013-05-13 01:16:13 +000096static MCAsmInfo *createSystemZMCAsmInfo(const MCRegisterInfo &MRI,
97 StringRef TT) {
Rafael Espindola140a8372013-05-10 18:16:59 +000098 MCAsmInfo *MAI = new SystemZMCAsmInfo(TT);
Rafael Espindola227144c2013-05-13 01:16:13 +000099 MCCFIInstruction Inst =
100 MCCFIInstruction::createDefCfa(0, MRI.getDwarfRegNum(SystemZ::R15D, true),
101 SystemZMC::CFAOffsetFromInitialSP);
102 MAI->addInitialFrameState(Inst);
Ulrich Weigand5f613df2013-05-06 16:15:19 +0000103 return MAI;
104}
105
106static MCInstrInfo *createSystemZMCInstrInfo() {
107 MCInstrInfo *X = new MCInstrInfo();
108 InitSystemZMCInstrInfo(X);
109 return X;
110}
111
112static MCRegisterInfo *createSystemZMCRegisterInfo(StringRef TT) {
113 MCRegisterInfo *X = new MCRegisterInfo();
114 InitSystemZMCRegisterInfo(X, SystemZ::R14D);
115 return X;
116}
117
118static MCSubtargetInfo *createSystemZMCSubtargetInfo(StringRef TT,
119 StringRef CPU,
120 StringRef FS) {
121 MCSubtargetInfo *X = new MCSubtargetInfo();
122 InitSystemZMCSubtargetInfo(X, TT, CPU, FS);
123 return X;
124}
125
126static MCCodeGenInfo *createSystemZMCCodeGenInfo(StringRef TT, Reloc::Model RM,
127 CodeModel::Model CM,
Richard Sandiford95896912013-05-07 12:56:31 +0000128 CodeGenOpt::Level OL) {
Ulrich Weigand5f613df2013-05-06 16:15:19 +0000129 MCCodeGenInfo *X = new MCCodeGenInfo();
130
131 // Static code is suitable for use in a dynamic executable; there is no
132 // separate DynamicNoPIC model.
133 if (RM == Reloc::Default || RM == Reloc::DynamicNoPIC)
134 RM = Reloc::Static;
135
136 // For SystemZ we define the models as follows:
137 //
138 // Small: BRASL can call any function and will use a stub if necessary.
139 // Locally-binding symbols will always be in range of LARL.
140 //
141 // Medium: BRASL can call any function and will use a stub if necessary.
142 // GOT slots and locally-defined text will always be in range
143 // of LARL, but other symbols might not be.
144 //
145 // Large: Equivalent to Medium for now.
146 //
147 // Kernel: Equivalent to Medium for now.
148 //
149 // This means that any PIC module smaller than 4GB meets the
150 // requirements of Small, so Small seems like the best default there.
151 //
152 // All symbols bind locally in a non-PIC module, so the choice is less
153 // obvious. There are two cases:
154 //
155 // - When creating an executable, PLTs and copy relocations allow
156 // us to treat external symbols as part of the executable.
157 // Any executable smaller than 4GB meets the requirements of Small,
158 // so that seems like the best default.
159 //
160 // - When creating JIT code, stubs will be in range of BRASL if the
161 // image is less than 4GB in size. GOT entries will likewise be
162 // in range of LARL. However, the JIT environment has no equivalent
163 // of copy relocs, so locally-binding data symbols might not be in
164 // the range of LARL. We need the Medium model in that case.
165 if (CM == CodeModel::Default)
166 CM = CodeModel::Small;
167 else if (CM == CodeModel::JITDefault)
168 CM = RM == Reloc::PIC_ ? CodeModel::Small : CodeModel::Medium;
Richard Sandiford95896912013-05-07 12:56:31 +0000169 X->InitMCCodeGenInfo(RM, CM, OL);
Ulrich Weigand5f613df2013-05-06 16:15:19 +0000170 return X;
171}
172
173static MCInstPrinter *createSystemZMCInstPrinter(const Target &T,
174 unsigned SyntaxVariant,
175 const MCAsmInfo &MAI,
176 const MCInstrInfo &MII,
177 const MCRegisterInfo &MRI,
178 const MCSubtargetInfo &STI) {
179 return new SystemZInstPrinter(MAI, MII, MRI);
180}
181
182static MCStreamer *createSystemZMCObjectStreamer(const Target &T, StringRef TT,
183 MCContext &Ctx,
184 MCAsmBackend &MAB,
185 raw_ostream &OS,
186 MCCodeEmitter *Emitter,
187 bool RelaxAll,
188 bool NoExecStack) {
189 return createELFStreamer(Ctx, MAB, OS, Emitter, RelaxAll, NoExecStack);
190}
191
192extern "C" void LLVMInitializeSystemZTargetMC() {
193 // Register the MCAsmInfo.
194 TargetRegistry::RegisterMCAsmInfo(TheSystemZTarget,
195 createSystemZMCAsmInfo);
196
197 // Register the MCCodeGenInfo.
198 TargetRegistry::RegisterMCCodeGenInfo(TheSystemZTarget,
199 createSystemZMCCodeGenInfo);
200
201 // Register the MCCodeEmitter.
202 TargetRegistry::RegisterMCCodeEmitter(TheSystemZTarget,
203 createSystemZMCCodeEmitter);
204
205 // Register the MCInstrInfo.
206 TargetRegistry::RegisterMCInstrInfo(TheSystemZTarget,
207 createSystemZMCInstrInfo);
208
209 // Register the MCRegisterInfo.
210 TargetRegistry::RegisterMCRegInfo(TheSystemZTarget,
211 createSystemZMCRegisterInfo);
212
213 // Register the MCSubtargetInfo.
214 TargetRegistry::RegisterMCSubtargetInfo(TheSystemZTarget,
215 createSystemZMCSubtargetInfo);
216
217 // Register the MCAsmBackend.
218 TargetRegistry::RegisterMCAsmBackend(TheSystemZTarget,
219 createSystemZMCAsmBackend);
220
221 // Register the MCInstPrinter.
222 TargetRegistry::RegisterMCInstPrinter(TheSystemZTarget,
223 createSystemZMCInstPrinter);
224
225 // Register the MCObjectStreamer;
226 TargetRegistry::RegisterMCObjectStreamer(TheSystemZTarget,
227 createSystemZMCObjectStreamer);
228}