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 static MCAsmInfo *createSystemZMCAsmInfo(StringRef TT) {
31 MCAsmInfo *MAI = new SystemZMCAsmInfo(TT);
32 MachineLocation FPDst(MachineLocation::VirtualFP);
33 MachineLocation FPSrc(SystemZ::R15D, -SystemZMC::CFAOffsetFromInitialSP);
34 MAI->addInitialFrameState(0, FPDst, FPSrc);
38 static MCInstrInfo *createSystemZMCInstrInfo() {
39 MCInstrInfo *X = new MCInstrInfo();
40 InitSystemZMCInstrInfo(X);
44 static MCRegisterInfo *createSystemZMCRegisterInfo(StringRef TT) {
45 MCRegisterInfo *X = new MCRegisterInfo();
46 InitSystemZMCRegisterInfo(X, SystemZ::R14D);
50 static MCSubtargetInfo *createSystemZMCSubtargetInfo(StringRef TT,
53 MCSubtargetInfo *X = new MCSubtargetInfo();
54 InitSystemZMCSubtargetInfo(X, TT, CPU, FS);
58 static MCCodeGenInfo *createSystemZMCCodeGenInfo(StringRef TT, Reloc::Model RM,
60 CodeGenOpt::Level OL) {
61 MCCodeGenInfo *X = new MCCodeGenInfo();
63 // Static code is suitable for use in a dynamic executable; there is no
64 // separate DynamicNoPIC model.
65 if (RM == Reloc::Default || RM == Reloc::DynamicNoPIC)
68 // For SystemZ we define the models as follows:
70 // Small: BRASL can call any function and will use a stub if necessary.
71 // Locally-binding symbols will always be in range of LARL.
73 // Medium: BRASL can call any function and will use a stub if necessary.
74 // GOT slots and locally-defined text will always be in range
75 // of LARL, but other symbols might not be.
77 // Large: Equivalent to Medium for now.
79 // Kernel: Equivalent to Medium for now.
81 // This means that any PIC module smaller than 4GB meets the
82 // requirements of Small, so Small seems like the best default there.
84 // All symbols bind locally in a non-PIC module, so the choice is less
85 // obvious. There are two cases:
87 // - When creating an executable, PLTs and copy relocations allow
88 // us to treat external symbols as part of the executable.
89 // Any executable smaller than 4GB meets the requirements of Small,
90 // so that seems like the best default.
92 // - When creating JIT code, stubs will be in range of BRASL if the
93 // image is less than 4GB in size. GOT entries will likewise be
94 // in range of LARL. However, the JIT environment has no equivalent
95 // of copy relocs, so locally-binding data symbols might not be in
96 // the range of LARL. We need the Medium model in that case.
97 if (CM == CodeModel::Default)
98 CM = CodeModel::Small;
99 else if (CM == CodeModel::JITDefault)
100 CM = RM == Reloc::PIC_ ? CodeModel::Small : CodeModel::Medium;
101 X->InitMCCodeGenInfo(RM, CM, OL);
105 static MCInstPrinter *createSystemZMCInstPrinter(const Target &T,
106 unsigned SyntaxVariant,
107 const MCAsmInfo &MAI,
108 const MCInstrInfo &MII,
109 const MCRegisterInfo &MRI,
110 const MCSubtargetInfo &STI) {
111 return new SystemZInstPrinter(MAI, MII, MRI);
114 static MCStreamer *createSystemZMCObjectStreamer(const Target &T, StringRef TT,
118 MCCodeEmitter *Emitter,
121 return createELFStreamer(Ctx, MAB, OS, Emitter, RelaxAll, NoExecStack);
124 extern "C" void LLVMInitializeSystemZTargetMC() {
125 // Register the MCAsmInfo.
126 TargetRegistry::RegisterMCAsmInfo(TheSystemZTarget,
127 createSystemZMCAsmInfo);
129 // Register the MCCodeGenInfo.
130 TargetRegistry::RegisterMCCodeGenInfo(TheSystemZTarget,
131 createSystemZMCCodeGenInfo);
133 // Register the MCCodeEmitter.
134 TargetRegistry::RegisterMCCodeEmitter(TheSystemZTarget,
135 createSystemZMCCodeEmitter);
137 // Register the MCInstrInfo.
138 TargetRegistry::RegisterMCInstrInfo(TheSystemZTarget,
139 createSystemZMCInstrInfo);
141 // Register the MCRegisterInfo.
142 TargetRegistry::RegisterMCRegInfo(TheSystemZTarget,
143 createSystemZMCRegisterInfo);
145 // Register the MCSubtargetInfo.
146 TargetRegistry::RegisterMCSubtargetInfo(TheSystemZTarget,
147 createSystemZMCSubtargetInfo);
149 // Register the MCAsmBackend.
150 TargetRegistry::RegisterMCAsmBackend(TheSystemZTarget,
151 createSystemZMCAsmBackend);
153 // Register the MCInstPrinter.
154 TargetRegistry::RegisterMCInstPrinter(TheSystemZTarget,
155 createSystemZMCInstPrinter);
157 // Register the MCObjectStreamer;
158 TargetRegistry::RegisterMCObjectStreamer(TheSystemZTarget,
159 createSystemZMCObjectStreamer);