1 //===-- SystemZMCTargetDesc.cpp - SystemZ target descriptions -------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
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"
19 #define GET_INSTRINFO_MC_DESC
20 #include "SystemZGenInstrInfo.inc"
22 #define GET_SUBTARGETINFO_MC_DESC
23 #include "SystemZGenSubtargetInfo.inc"
25 #define GET_REGINFO_MC_DESC
26 #include "SystemZGenRegisterInfo.inc"
30 const unsigned SystemZMC::GR32Regs[16] = {
31 SystemZ::R0W, SystemZ::R1W, SystemZ::R2W, SystemZ::R3W,
32 SystemZ::R4W, SystemZ::R5W, SystemZ::R6W, SystemZ::R7W,
33 SystemZ::R8W, SystemZ::R9W, SystemZ::R10W, SystemZ::R11W,
34 SystemZ::R12W, SystemZ::R13W, SystemZ::R14W, SystemZ::R15W
37 const unsigned SystemZMC::GR64Regs[16] = {
38 SystemZ::R0D, SystemZ::R1D, SystemZ::R2D, SystemZ::R3D,
39 SystemZ::R4D, SystemZ::R5D, SystemZ::R6D, SystemZ::R7D,
40 SystemZ::R8D, SystemZ::R9D, SystemZ::R10D, SystemZ::R11D,
41 SystemZ::R12D, SystemZ::R13D, SystemZ::R14D, SystemZ::R15D
44 const unsigned SystemZMC::GR128Regs[16] = {
45 SystemZ::R0Q, 0, SystemZ::R2Q, 0,
46 SystemZ::R4Q, 0, SystemZ::R6Q, 0,
47 SystemZ::R8Q, 0, SystemZ::R10Q, 0,
48 SystemZ::R12Q, 0, SystemZ::R14Q, 0
51 const unsigned SystemZMC::FP32Regs[16] = {
52 SystemZ::F0S, SystemZ::F1S, SystemZ::F2S, SystemZ::F3S,
53 SystemZ::F4S, SystemZ::F5S, SystemZ::F6S, SystemZ::F7S,
54 SystemZ::F8S, SystemZ::F9S, SystemZ::F10S, SystemZ::F11S,
55 SystemZ::F12S, SystemZ::F13S, SystemZ::F14S, SystemZ::F15S
58 const unsigned SystemZMC::FP64Regs[16] = {
59 SystemZ::F0D, SystemZ::F1D, SystemZ::F2D, SystemZ::F3D,
60 SystemZ::F4D, SystemZ::F5D, SystemZ::F6D, SystemZ::F7D,
61 SystemZ::F8D, SystemZ::F9D, SystemZ::F10D, SystemZ::F11D,
62 SystemZ::F12D, SystemZ::F13D, SystemZ::F14D, SystemZ::F15D
65 const unsigned SystemZMC::FP128Regs[16] = {
66 SystemZ::F0Q, SystemZ::F1Q, 0, 0,
67 SystemZ::F4Q, SystemZ::F5Q, 0, 0,
68 SystemZ::F8Q, SystemZ::F9Q, 0, 0,
69 SystemZ::F12Q, SystemZ::F13Q, 0, 0
72 static MCAsmInfo *createSystemZMCAsmInfo(const MCRegisterInfo &MRI,
74 MCAsmInfo *MAI = new SystemZMCAsmInfo(TT);
75 MCCFIInstruction Inst =
76 MCCFIInstruction::createDefCfa(0, MRI.getDwarfRegNum(SystemZ::R15D, true),
77 SystemZMC::CFAOffsetFromInitialSP);
78 MAI->addInitialFrameState(Inst);
82 static MCInstrInfo *createSystemZMCInstrInfo() {
83 MCInstrInfo *X = new MCInstrInfo();
84 InitSystemZMCInstrInfo(X);
88 static MCRegisterInfo *createSystemZMCRegisterInfo(StringRef TT) {
89 MCRegisterInfo *X = new MCRegisterInfo();
90 InitSystemZMCRegisterInfo(X, SystemZ::R14D);
94 static MCSubtargetInfo *createSystemZMCSubtargetInfo(StringRef TT,
97 MCSubtargetInfo *X = new MCSubtargetInfo();
98 InitSystemZMCSubtargetInfo(X, TT, CPU, FS);
102 static MCCodeGenInfo *createSystemZMCCodeGenInfo(StringRef TT, Reloc::Model RM,
104 CodeGenOpt::Level OL) {
105 MCCodeGenInfo *X = new MCCodeGenInfo();
107 // Static code is suitable for use in a dynamic executable; there is no
108 // separate DynamicNoPIC model.
109 if (RM == Reloc::Default || RM == Reloc::DynamicNoPIC)
112 // For SystemZ we define the models as follows:
114 // Small: BRASL can call any function and will use a stub if necessary.
115 // Locally-binding symbols will always be in range of LARL.
117 // Medium: BRASL can call any function and will use a stub if necessary.
118 // GOT slots and locally-defined text will always be in range
119 // of LARL, but other symbols might not be.
121 // Large: Equivalent to Medium for now.
123 // Kernel: Equivalent to Medium for now.
125 // This means that any PIC module smaller than 4GB meets the
126 // requirements of Small, so Small seems like the best default there.
128 // All symbols bind locally in a non-PIC module, so the choice is less
129 // obvious. There are two cases:
131 // - When creating an executable, PLTs and copy relocations allow
132 // us to treat external symbols as part of the executable.
133 // Any executable smaller than 4GB meets the requirements of Small,
134 // so that seems like the best default.
136 // - When creating JIT code, stubs will be in range of BRASL if the
137 // image is less than 4GB in size. GOT entries will likewise be
138 // in range of LARL. However, the JIT environment has no equivalent
139 // of copy relocs, so locally-binding data symbols might not be in
140 // the range of LARL. We need the Medium model in that case.
141 if (CM == CodeModel::Default)
142 CM = CodeModel::Small;
143 else if (CM == CodeModel::JITDefault)
144 CM = RM == Reloc::PIC_ ? CodeModel::Small : CodeModel::Medium;
145 X->InitMCCodeGenInfo(RM, CM, OL);
149 static MCInstPrinter *createSystemZMCInstPrinter(const Target &T,
150 unsigned SyntaxVariant,
151 const MCAsmInfo &MAI,
152 const MCInstrInfo &MII,
153 const MCRegisterInfo &MRI,
154 const MCSubtargetInfo &STI) {
155 return new SystemZInstPrinter(MAI, MII, MRI);
158 static MCStreamer *createSystemZMCObjectStreamer(const Target &T, StringRef TT,
162 MCCodeEmitter *Emitter,
165 return createELFStreamer(Ctx, MAB, OS, Emitter, RelaxAll, NoExecStack);
168 extern "C" void LLVMInitializeSystemZTargetMC() {
169 // Register the MCAsmInfo.
170 TargetRegistry::RegisterMCAsmInfo(TheSystemZTarget,
171 createSystemZMCAsmInfo);
173 // Register the MCCodeGenInfo.
174 TargetRegistry::RegisterMCCodeGenInfo(TheSystemZTarget,
175 createSystemZMCCodeGenInfo);
177 // Register the MCCodeEmitter.
178 TargetRegistry::RegisterMCCodeEmitter(TheSystemZTarget,
179 createSystemZMCCodeEmitter);
181 // Register the MCInstrInfo.
182 TargetRegistry::RegisterMCInstrInfo(TheSystemZTarget,
183 createSystemZMCInstrInfo);
185 // Register the MCRegisterInfo.
186 TargetRegistry::RegisterMCRegInfo(TheSystemZTarget,
187 createSystemZMCRegisterInfo);
189 // Register the MCSubtargetInfo.
190 TargetRegistry::RegisterMCSubtargetInfo(TheSystemZTarget,
191 createSystemZMCSubtargetInfo);
193 // Register the MCAsmBackend.
194 TargetRegistry::RegisterMCAsmBackend(TheSystemZTarget,
195 createSystemZMCAsmBackend);
197 // Register the MCInstPrinter.
198 TargetRegistry::RegisterMCInstPrinter(TheSystemZTarget,
199 createSystemZMCInstPrinter);
201 // Register the MCObjectStreamer;
202 TargetRegistry::RegisterMCObjectStreamer(TheSystemZTarget,
203 createSystemZMCObjectStreamer);