1*9880d681SAndroid Build Coastguard Worker //===-- SystemZMCTargetDesc.cpp - SystemZ target descriptions -------------===//
2*9880d681SAndroid Build Coastguard Worker //
3*9880d681SAndroid Build Coastguard Worker // The LLVM Compiler Infrastructure
4*9880d681SAndroid Build Coastguard Worker //
5*9880d681SAndroid Build Coastguard Worker // This file is distributed under the University of Illinois Open Source
6*9880d681SAndroid Build Coastguard Worker // License. See LICENSE.TXT for details.
7*9880d681SAndroid Build Coastguard Worker //
8*9880d681SAndroid Build Coastguard Worker //===----------------------------------------------------------------------===//
9*9880d681SAndroid Build Coastguard Worker
10*9880d681SAndroid Build Coastguard Worker #include "SystemZMCTargetDesc.h"
11*9880d681SAndroid Build Coastguard Worker #include "InstPrinter/SystemZInstPrinter.h"
12*9880d681SAndroid Build Coastguard Worker #include "SystemZMCAsmInfo.h"
13*9880d681SAndroid Build Coastguard Worker #include "llvm/MC/MCInstrInfo.h"
14*9880d681SAndroid Build Coastguard Worker #include "llvm/MC/MCRegisterInfo.h"
15*9880d681SAndroid Build Coastguard Worker #include "llvm/MC/MCStreamer.h"
16*9880d681SAndroid Build Coastguard Worker #include "llvm/MC/MCSubtargetInfo.h"
17*9880d681SAndroid Build Coastguard Worker #include "llvm/Support/TargetRegistry.h"
18*9880d681SAndroid Build Coastguard Worker
19*9880d681SAndroid Build Coastguard Worker using namespace llvm;
20*9880d681SAndroid Build Coastguard Worker
21*9880d681SAndroid Build Coastguard Worker #define GET_INSTRINFO_MC_DESC
22*9880d681SAndroid Build Coastguard Worker #include "SystemZGenInstrInfo.inc"
23*9880d681SAndroid Build Coastguard Worker
24*9880d681SAndroid Build Coastguard Worker #define GET_SUBTARGETINFO_MC_DESC
25*9880d681SAndroid Build Coastguard Worker #include "SystemZGenSubtargetInfo.inc"
26*9880d681SAndroid Build Coastguard Worker
27*9880d681SAndroid Build Coastguard Worker #define GET_REGINFO_MC_DESC
28*9880d681SAndroid Build Coastguard Worker #include "SystemZGenRegisterInfo.inc"
29*9880d681SAndroid Build Coastguard Worker
30*9880d681SAndroid Build Coastguard Worker const unsigned SystemZMC::GR32Regs[16] = {
31*9880d681SAndroid Build Coastguard Worker SystemZ::R0L, SystemZ::R1L, SystemZ::R2L, SystemZ::R3L,
32*9880d681SAndroid Build Coastguard Worker SystemZ::R4L, SystemZ::R5L, SystemZ::R6L, SystemZ::R7L,
33*9880d681SAndroid Build Coastguard Worker SystemZ::R8L, SystemZ::R9L, SystemZ::R10L, SystemZ::R11L,
34*9880d681SAndroid Build Coastguard Worker SystemZ::R12L, SystemZ::R13L, SystemZ::R14L, SystemZ::R15L
35*9880d681SAndroid Build Coastguard Worker };
36*9880d681SAndroid Build Coastguard Worker
37*9880d681SAndroid Build Coastguard Worker const unsigned SystemZMC::GRH32Regs[16] = {
38*9880d681SAndroid Build Coastguard Worker SystemZ::R0H, SystemZ::R1H, SystemZ::R2H, SystemZ::R3H,
39*9880d681SAndroid Build Coastguard Worker SystemZ::R4H, SystemZ::R5H, SystemZ::R6H, SystemZ::R7H,
40*9880d681SAndroid Build Coastguard Worker SystemZ::R8H, SystemZ::R9H, SystemZ::R10H, SystemZ::R11H,
41*9880d681SAndroid Build Coastguard Worker SystemZ::R12H, SystemZ::R13H, SystemZ::R14H, SystemZ::R15H
42*9880d681SAndroid Build Coastguard Worker };
43*9880d681SAndroid Build Coastguard Worker
44*9880d681SAndroid Build Coastguard Worker const unsigned SystemZMC::GR64Regs[16] = {
45*9880d681SAndroid Build Coastguard Worker SystemZ::R0D, SystemZ::R1D, SystemZ::R2D, SystemZ::R3D,
46*9880d681SAndroid Build Coastguard Worker SystemZ::R4D, SystemZ::R5D, SystemZ::R6D, SystemZ::R7D,
47*9880d681SAndroid Build Coastguard Worker SystemZ::R8D, SystemZ::R9D, SystemZ::R10D, SystemZ::R11D,
48*9880d681SAndroid Build Coastguard Worker SystemZ::R12D, SystemZ::R13D, SystemZ::R14D, SystemZ::R15D
49*9880d681SAndroid Build Coastguard Worker };
50*9880d681SAndroid Build Coastguard Worker
51*9880d681SAndroid Build Coastguard Worker const unsigned SystemZMC::GR128Regs[16] = {
52*9880d681SAndroid Build Coastguard Worker SystemZ::R0Q, 0, SystemZ::R2Q, 0,
53*9880d681SAndroid Build Coastguard Worker SystemZ::R4Q, 0, SystemZ::R6Q, 0,
54*9880d681SAndroid Build Coastguard Worker SystemZ::R8Q, 0, SystemZ::R10Q, 0,
55*9880d681SAndroid Build Coastguard Worker SystemZ::R12Q, 0, SystemZ::R14Q, 0
56*9880d681SAndroid Build Coastguard Worker };
57*9880d681SAndroid Build Coastguard Worker
58*9880d681SAndroid Build Coastguard Worker const unsigned SystemZMC::FP32Regs[16] = {
59*9880d681SAndroid Build Coastguard Worker SystemZ::F0S, SystemZ::F1S, SystemZ::F2S, SystemZ::F3S,
60*9880d681SAndroid Build Coastguard Worker SystemZ::F4S, SystemZ::F5S, SystemZ::F6S, SystemZ::F7S,
61*9880d681SAndroid Build Coastguard Worker SystemZ::F8S, SystemZ::F9S, SystemZ::F10S, SystemZ::F11S,
62*9880d681SAndroid Build Coastguard Worker SystemZ::F12S, SystemZ::F13S, SystemZ::F14S, SystemZ::F15S
63*9880d681SAndroid Build Coastguard Worker };
64*9880d681SAndroid Build Coastguard Worker
65*9880d681SAndroid Build Coastguard Worker const unsigned SystemZMC::FP64Regs[16] = {
66*9880d681SAndroid Build Coastguard Worker SystemZ::F0D, SystemZ::F1D, SystemZ::F2D, SystemZ::F3D,
67*9880d681SAndroid Build Coastguard Worker SystemZ::F4D, SystemZ::F5D, SystemZ::F6D, SystemZ::F7D,
68*9880d681SAndroid Build Coastguard Worker SystemZ::F8D, SystemZ::F9D, SystemZ::F10D, SystemZ::F11D,
69*9880d681SAndroid Build Coastguard Worker SystemZ::F12D, SystemZ::F13D, SystemZ::F14D, SystemZ::F15D
70*9880d681SAndroid Build Coastguard Worker };
71*9880d681SAndroid Build Coastguard Worker
72*9880d681SAndroid Build Coastguard Worker const unsigned SystemZMC::FP128Regs[16] = {
73*9880d681SAndroid Build Coastguard Worker SystemZ::F0Q, SystemZ::F1Q, 0, 0,
74*9880d681SAndroid Build Coastguard Worker SystemZ::F4Q, SystemZ::F5Q, 0, 0,
75*9880d681SAndroid Build Coastguard Worker SystemZ::F8Q, SystemZ::F9Q, 0, 0,
76*9880d681SAndroid Build Coastguard Worker SystemZ::F12Q, SystemZ::F13Q, 0, 0
77*9880d681SAndroid Build Coastguard Worker };
78*9880d681SAndroid Build Coastguard Worker
79*9880d681SAndroid Build Coastguard Worker const unsigned SystemZMC::VR32Regs[32] = {
80*9880d681SAndroid Build Coastguard Worker SystemZ::F0S, SystemZ::F1S, SystemZ::F2S, SystemZ::F3S,
81*9880d681SAndroid Build Coastguard Worker SystemZ::F4S, SystemZ::F5S, SystemZ::F6S, SystemZ::F7S,
82*9880d681SAndroid Build Coastguard Worker SystemZ::F8S, SystemZ::F9S, SystemZ::F10S, SystemZ::F11S,
83*9880d681SAndroid Build Coastguard Worker SystemZ::F12S, SystemZ::F13S, SystemZ::F14S, SystemZ::F15S,
84*9880d681SAndroid Build Coastguard Worker SystemZ::F16S, SystemZ::F17S, SystemZ::F18S, SystemZ::F19S,
85*9880d681SAndroid Build Coastguard Worker SystemZ::F20S, SystemZ::F21S, SystemZ::F22S, SystemZ::F23S,
86*9880d681SAndroid Build Coastguard Worker SystemZ::F24S, SystemZ::F25S, SystemZ::F26S, SystemZ::F27S,
87*9880d681SAndroid Build Coastguard Worker SystemZ::F28S, SystemZ::F29S, SystemZ::F30S, SystemZ::F31S
88*9880d681SAndroid Build Coastguard Worker };
89*9880d681SAndroid Build Coastguard Worker
90*9880d681SAndroid Build Coastguard Worker const unsigned SystemZMC::VR64Regs[32] = {
91*9880d681SAndroid Build Coastguard Worker SystemZ::F0D, SystemZ::F1D, SystemZ::F2D, SystemZ::F3D,
92*9880d681SAndroid Build Coastguard Worker SystemZ::F4D, SystemZ::F5D, SystemZ::F6D, SystemZ::F7D,
93*9880d681SAndroid Build Coastguard Worker SystemZ::F8D, SystemZ::F9D, SystemZ::F10D, SystemZ::F11D,
94*9880d681SAndroid Build Coastguard Worker SystemZ::F12D, SystemZ::F13D, SystemZ::F14D, SystemZ::F15D,
95*9880d681SAndroid Build Coastguard Worker SystemZ::F16D, SystemZ::F17D, SystemZ::F18D, SystemZ::F19D,
96*9880d681SAndroid Build Coastguard Worker SystemZ::F20D, SystemZ::F21D, SystemZ::F22D, SystemZ::F23D,
97*9880d681SAndroid Build Coastguard Worker SystemZ::F24D, SystemZ::F25D, SystemZ::F26D, SystemZ::F27D,
98*9880d681SAndroid Build Coastguard Worker SystemZ::F28D, SystemZ::F29D, SystemZ::F30D, SystemZ::F31D
99*9880d681SAndroid Build Coastguard Worker };
100*9880d681SAndroid Build Coastguard Worker
101*9880d681SAndroid Build Coastguard Worker const unsigned SystemZMC::VR128Regs[32] = {
102*9880d681SAndroid Build Coastguard Worker SystemZ::V0, SystemZ::V1, SystemZ::V2, SystemZ::V3,
103*9880d681SAndroid Build Coastguard Worker SystemZ::V4, SystemZ::V5, SystemZ::V6, SystemZ::V7,
104*9880d681SAndroid Build Coastguard Worker SystemZ::V8, SystemZ::V9, SystemZ::V10, SystemZ::V11,
105*9880d681SAndroid Build Coastguard Worker SystemZ::V12, SystemZ::V13, SystemZ::V14, SystemZ::V15,
106*9880d681SAndroid Build Coastguard Worker SystemZ::V16, SystemZ::V17, SystemZ::V18, SystemZ::V19,
107*9880d681SAndroid Build Coastguard Worker SystemZ::V20, SystemZ::V21, SystemZ::V22, SystemZ::V23,
108*9880d681SAndroid Build Coastguard Worker SystemZ::V24, SystemZ::V25, SystemZ::V26, SystemZ::V27,
109*9880d681SAndroid Build Coastguard Worker SystemZ::V28, SystemZ::V29, SystemZ::V30, SystemZ::V31
110*9880d681SAndroid Build Coastguard Worker };
111*9880d681SAndroid Build Coastguard Worker
getFirstReg(unsigned Reg)112*9880d681SAndroid Build Coastguard Worker unsigned SystemZMC::getFirstReg(unsigned Reg) {
113*9880d681SAndroid Build Coastguard Worker static unsigned Map[SystemZ::NUM_TARGET_REGS];
114*9880d681SAndroid Build Coastguard Worker static bool Initialized = false;
115*9880d681SAndroid Build Coastguard Worker if (!Initialized) {
116*9880d681SAndroid Build Coastguard Worker for (unsigned I = 0; I < 16; ++I) {
117*9880d681SAndroid Build Coastguard Worker Map[GR32Regs[I]] = I;
118*9880d681SAndroid Build Coastguard Worker Map[GRH32Regs[I]] = I;
119*9880d681SAndroid Build Coastguard Worker Map[GR64Regs[I]] = I;
120*9880d681SAndroid Build Coastguard Worker Map[GR128Regs[I]] = I;
121*9880d681SAndroid Build Coastguard Worker Map[FP128Regs[I]] = I;
122*9880d681SAndroid Build Coastguard Worker }
123*9880d681SAndroid Build Coastguard Worker for (unsigned I = 0; I < 32; ++I) {
124*9880d681SAndroid Build Coastguard Worker Map[VR32Regs[I]] = I;
125*9880d681SAndroid Build Coastguard Worker Map[VR64Regs[I]] = I;
126*9880d681SAndroid Build Coastguard Worker Map[VR128Regs[I]] = I;
127*9880d681SAndroid Build Coastguard Worker }
128*9880d681SAndroid Build Coastguard Worker }
129*9880d681SAndroid Build Coastguard Worker assert(Reg < SystemZ::NUM_TARGET_REGS);
130*9880d681SAndroid Build Coastguard Worker return Map[Reg];
131*9880d681SAndroid Build Coastguard Worker }
132*9880d681SAndroid Build Coastguard Worker
createSystemZMCAsmInfo(const MCRegisterInfo & MRI,const Triple & TT)133*9880d681SAndroid Build Coastguard Worker static MCAsmInfo *createSystemZMCAsmInfo(const MCRegisterInfo &MRI,
134*9880d681SAndroid Build Coastguard Worker const Triple &TT) {
135*9880d681SAndroid Build Coastguard Worker MCAsmInfo *MAI = new SystemZMCAsmInfo(TT);
136*9880d681SAndroid Build Coastguard Worker MCCFIInstruction Inst =
137*9880d681SAndroid Build Coastguard Worker MCCFIInstruction::createDefCfa(nullptr,
138*9880d681SAndroid Build Coastguard Worker MRI.getDwarfRegNum(SystemZ::R15D, true),
139*9880d681SAndroid Build Coastguard Worker SystemZMC::CFAOffsetFromInitialSP);
140*9880d681SAndroid Build Coastguard Worker MAI->addInitialFrameState(Inst);
141*9880d681SAndroid Build Coastguard Worker return MAI;
142*9880d681SAndroid Build Coastguard Worker }
143*9880d681SAndroid Build Coastguard Worker
createSystemZMCInstrInfo()144*9880d681SAndroid Build Coastguard Worker static MCInstrInfo *createSystemZMCInstrInfo() {
145*9880d681SAndroid Build Coastguard Worker MCInstrInfo *X = new MCInstrInfo();
146*9880d681SAndroid Build Coastguard Worker InitSystemZMCInstrInfo(X);
147*9880d681SAndroid Build Coastguard Worker return X;
148*9880d681SAndroid Build Coastguard Worker }
149*9880d681SAndroid Build Coastguard Worker
createSystemZMCRegisterInfo(const Triple & TT)150*9880d681SAndroid Build Coastguard Worker static MCRegisterInfo *createSystemZMCRegisterInfo(const Triple &TT) {
151*9880d681SAndroid Build Coastguard Worker MCRegisterInfo *X = new MCRegisterInfo();
152*9880d681SAndroid Build Coastguard Worker InitSystemZMCRegisterInfo(X, SystemZ::R14D);
153*9880d681SAndroid Build Coastguard Worker return X;
154*9880d681SAndroid Build Coastguard Worker }
155*9880d681SAndroid Build Coastguard Worker
156*9880d681SAndroid Build Coastguard Worker static MCSubtargetInfo *
createSystemZMCSubtargetInfo(const Triple & TT,StringRef CPU,StringRef FS)157*9880d681SAndroid Build Coastguard Worker createSystemZMCSubtargetInfo(const Triple &TT, StringRef CPU, StringRef FS) {
158*9880d681SAndroid Build Coastguard Worker return createSystemZMCSubtargetInfoImpl(TT, CPU, FS);
159*9880d681SAndroid Build Coastguard Worker }
160*9880d681SAndroid Build Coastguard Worker
adjustCodeGenOpts(const Triple & TT,Reloc::Model RM,CodeModel::Model & CM)161*9880d681SAndroid Build Coastguard Worker static void adjustCodeGenOpts(const Triple &TT, Reloc::Model RM,
162*9880d681SAndroid Build Coastguard Worker CodeModel::Model &CM) {
163*9880d681SAndroid Build Coastguard Worker // For SystemZ we define the models as follows:
164*9880d681SAndroid Build Coastguard Worker //
165*9880d681SAndroid Build Coastguard Worker // Small: BRASL can call any function and will use a stub if necessary.
166*9880d681SAndroid Build Coastguard Worker // Locally-binding symbols will always be in range of LARL.
167*9880d681SAndroid Build Coastguard Worker //
168*9880d681SAndroid Build Coastguard Worker // Medium: BRASL can call any function and will use a stub if necessary.
169*9880d681SAndroid Build Coastguard Worker // GOT slots and locally-defined text will always be in range
170*9880d681SAndroid Build Coastguard Worker // of LARL, but other symbols might not be.
171*9880d681SAndroid Build Coastguard Worker //
172*9880d681SAndroid Build Coastguard Worker // Large: Equivalent to Medium for now.
173*9880d681SAndroid Build Coastguard Worker //
174*9880d681SAndroid Build Coastguard Worker // Kernel: Equivalent to Medium for now.
175*9880d681SAndroid Build Coastguard Worker //
176*9880d681SAndroid Build Coastguard Worker // This means that any PIC module smaller than 4GB meets the
177*9880d681SAndroid Build Coastguard Worker // requirements of Small, so Small seems like the best default there.
178*9880d681SAndroid Build Coastguard Worker //
179*9880d681SAndroid Build Coastguard Worker // All symbols bind locally in a non-PIC module, so the choice is less
180*9880d681SAndroid Build Coastguard Worker // obvious. There are two cases:
181*9880d681SAndroid Build Coastguard Worker //
182*9880d681SAndroid Build Coastguard Worker // - When creating an executable, PLTs and copy relocations allow
183*9880d681SAndroid Build Coastguard Worker // us to treat external symbols as part of the executable.
184*9880d681SAndroid Build Coastguard Worker // Any executable smaller than 4GB meets the requirements of Small,
185*9880d681SAndroid Build Coastguard Worker // so that seems like the best default.
186*9880d681SAndroid Build Coastguard Worker //
187*9880d681SAndroid Build Coastguard Worker // - When creating JIT code, stubs will be in range of BRASL if the
188*9880d681SAndroid Build Coastguard Worker // image is less than 4GB in size. GOT entries will likewise be
189*9880d681SAndroid Build Coastguard Worker // in range of LARL. However, the JIT environment has no equivalent
190*9880d681SAndroid Build Coastguard Worker // of copy relocs, so locally-binding data symbols might not be in
191*9880d681SAndroid Build Coastguard Worker // the range of LARL. We need the Medium model in that case.
192*9880d681SAndroid Build Coastguard Worker if (CM == CodeModel::Default)
193*9880d681SAndroid Build Coastguard Worker CM = CodeModel::Small;
194*9880d681SAndroid Build Coastguard Worker else if (CM == CodeModel::JITDefault)
195*9880d681SAndroid Build Coastguard Worker CM = RM == Reloc::PIC_ ? CodeModel::Small : CodeModel::Medium;
196*9880d681SAndroid Build Coastguard Worker }
197*9880d681SAndroid Build Coastguard Worker
createSystemZMCInstPrinter(const Triple & T,unsigned SyntaxVariant,const MCAsmInfo & MAI,const MCInstrInfo & MII,const MCRegisterInfo & MRI)198*9880d681SAndroid Build Coastguard Worker static MCInstPrinter *createSystemZMCInstPrinter(const Triple &T,
199*9880d681SAndroid Build Coastguard Worker unsigned SyntaxVariant,
200*9880d681SAndroid Build Coastguard Worker const MCAsmInfo &MAI,
201*9880d681SAndroid Build Coastguard Worker const MCInstrInfo &MII,
202*9880d681SAndroid Build Coastguard Worker const MCRegisterInfo &MRI) {
203*9880d681SAndroid Build Coastguard Worker return new SystemZInstPrinter(MAI, MII, MRI);
204*9880d681SAndroid Build Coastguard Worker }
205*9880d681SAndroid Build Coastguard Worker
LLVMInitializeSystemZTargetMC()206*9880d681SAndroid Build Coastguard Worker extern "C" void LLVMInitializeSystemZTargetMC() {
207*9880d681SAndroid Build Coastguard Worker // Register the MCAsmInfo.
208*9880d681SAndroid Build Coastguard Worker TargetRegistry::RegisterMCAsmInfo(TheSystemZTarget,
209*9880d681SAndroid Build Coastguard Worker createSystemZMCAsmInfo);
210*9880d681SAndroid Build Coastguard Worker
211*9880d681SAndroid Build Coastguard Worker // Register the adjustCodeGenOpts.
212*9880d681SAndroid Build Coastguard Worker TargetRegistry::registerMCAdjustCodeGenOpts(TheSystemZTarget,
213*9880d681SAndroid Build Coastguard Worker adjustCodeGenOpts);
214*9880d681SAndroid Build Coastguard Worker
215*9880d681SAndroid Build Coastguard Worker // Register the MCCodeEmitter.
216*9880d681SAndroid Build Coastguard Worker TargetRegistry::RegisterMCCodeEmitter(TheSystemZTarget,
217*9880d681SAndroid Build Coastguard Worker createSystemZMCCodeEmitter);
218*9880d681SAndroid Build Coastguard Worker
219*9880d681SAndroid Build Coastguard Worker // Register the MCInstrInfo.
220*9880d681SAndroid Build Coastguard Worker TargetRegistry::RegisterMCInstrInfo(TheSystemZTarget,
221*9880d681SAndroid Build Coastguard Worker createSystemZMCInstrInfo);
222*9880d681SAndroid Build Coastguard Worker
223*9880d681SAndroid Build Coastguard Worker // Register the MCRegisterInfo.
224*9880d681SAndroid Build Coastguard Worker TargetRegistry::RegisterMCRegInfo(TheSystemZTarget,
225*9880d681SAndroid Build Coastguard Worker createSystemZMCRegisterInfo);
226*9880d681SAndroid Build Coastguard Worker
227*9880d681SAndroid Build Coastguard Worker // Register the MCSubtargetInfo.
228*9880d681SAndroid Build Coastguard Worker TargetRegistry::RegisterMCSubtargetInfo(TheSystemZTarget,
229*9880d681SAndroid Build Coastguard Worker createSystemZMCSubtargetInfo);
230*9880d681SAndroid Build Coastguard Worker
231*9880d681SAndroid Build Coastguard Worker // Register the MCAsmBackend.
232*9880d681SAndroid Build Coastguard Worker TargetRegistry::RegisterMCAsmBackend(TheSystemZTarget,
233*9880d681SAndroid Build Coastguard Worker createSystemZMCAsmBackend);
234*9880d681SAndroid Build Coastguard Worker
235*9880d681SAndroid Build Coastguard Worker // Register the MCInstPrinter.
236*9880d681SAndroid Build Coastguard Worker TargetRegistry::RegisterMCInstPrinter(TheSystemZTarget,
237*9880d681SAndroid Build Coastguard Worker createSystemZMCInstPrinter);
238*9880d681SAndroid Build Coastguard Worker }
239