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(const MCRegisterInfo &MRI,
32 MCAsmInfo *MAI = new SystemZMCAsmInfo(TT);
33 MCCFIInstruction Inst =
34 MCCFIInstruction::createDefCfa(0, MRI.getDwarfRegNum(SystemZ::R15D, true),
35 SystemZMC::CFAOffsetFromInitialSP);
36 MAI->addInitialFrameState(Inst);
40 static MCInstrInfo *createSystemZMCInstrInfo() {
41 MCInstrInfo *X = new MCInstrInfo();
42 InitSystemZMCInstrInfo(X);
46 static MCRegisterInfo *createSystemZMCRegisterInfo(StringRef TT) {
47 MCRegisterInfo *X = new MCRegisterInfo();
48 InitSystemZMCRegisterInfo(X, SystemZ::R14D);
52 static MCSubtargetInfo *createSystemZMCSubtargetInfo(StringRef TT,
55 MCSubtargetInfo *X = new MCSubtargetInfo();
56 InitSystemZMCSubtargetInfo(X, TT, CPU, FS);
60 static MCCodeGenInfo *createSystemZMCCodeGenInfo(StringRef TT, Reloc::Model RM,
62 CodeGenOpt::Level OL) {
63 MCCodeGenInfo *X = new MCCodeGenInfo();
65 // Static code is suitable for use in a dynamic executable; there is no
66 // separate DynamicNoPIC model.
67 if (RM == Reloc::Default || RM == Reloc::DynamicNoPIC)
70 // For SystemZ we define the models as follows:
72 // Small: BRASL can call any function and will use a stub if necessary.
73 // Locally-binding symbols will always be in range of LARL.
75 // Medium: BRASL can call any function and will use a stub if necessary.
76 // GOT slots and locally-defined text will always be in range
77 // of LARL, but other symbols might not be.
79 // Large: Equivalent to Medium for now.
81 // Kernel: Equivalent to Medium for now.
83 // This means that any PIC module smaller than 4GB meets the
84 // requirements of Small, so Small seems like the best default there.
86 // All symbols bind locally in a non-PIC module, so the choice is less
87 // obvious. There are two cases:
89 // - When creating an executable, PLTs and copy relocations allow
90 // us to treat external symbols as part of the executable.
91 // Any executable smaller than 4GB meets the requirements of Small,
92 // so that seems like the best default.
94 // - When creating JIT code, stubs will be in range of BRASL if the
95 // image is less than 4GB in size. GOT entries will likewise be
96 // in range of LARL. However, the JIT environment has no equivalent
97 // of copy relocs, so locally-binding data symbols might not be in
98 // the range of LARL. We need the Medium model in that case.
99 if (CM == CodeModel::Default)
100 CM = CodeModel::Small;
101 else if (CM == CodeModel::JITDefault)
102 CM = RM == Reloc::PIC_ ? CodeModel::Small : CodeModel::Medium;
103 X->InitMCCodeGenInfo(RM, CM, OL);
107 static MCInstPrinter *createSystemZMCInstPrinter(const Target &T,
108 unsigned SyntaxVariant,
109 const MCAsmInfo &MAI,
110 const MCInstrInfo &MII,
111 const MCRegisterInfo &MRI,
112 const MCSubtargetInfo &STI) {
113 return new SystemZInstPrinter(MAI, MII, MRI);
116 static MCStreamer *createSystemZMCObjectStreamer(const Target &T, StringRef TT,
120 MCCodeEmitter *Emitter,
123 return createELFStreamer(Ctx, MAB, OS, Emitter, RelaxAll, NoExecStack);
126 extern "C" void LLVMInitializeSystemZTargetMC() {
127 // Register the MCAsmInfo.
128 TargetRegistry::RegisterMCAsmInfo(TheSystemZTarget,
129 createSystemZMCAsmInfo);
131 // Register the MCCodeGenInfo.
132 TargetRegistry::RegisterMCCodeGenInfo(TheSystemZTarget,
133 createSystemZMCCodeGenInfo);
135 // Register the MCCodeEmitter.
136 TargetRegistry::RegisterMCCodeEmitter(TheSystemZTarget,
137 createSystemZMCCodeEmitter);
139 // Register the MCInstrInfo.
140 TargetRegistry::RegisterMCInstrInfo(TheSystemZTarget,
141 createSystemZMCInstrInfo);
143 // Register the MCRegisterInfo.
144 TargetRegistry::RegisterMCRegInfo(TheSystemZTarget,
145 createSystemZMCRegisterInfo);
147 // Register the MCSubtargetInfo.
148 TargetRegistry::RegisterMCSubtargetInfo(TheSystemZTarget,
149 createSystemZMCSubtargetInfo);
151 // Register the MCAsmBackend.
152 TargetRegistry::RegisterMCAsmBackend(TheSystemZTarget,
153 createSystemZMCAsmBackend);
155 // Register the MCInstPrinter.
156 TargetRegistry::RegisterMCInstPrinter(TheSystemZTarget,
157 createSystemZMCInstPrinter);
159 // Register the MCObjectStreamer;
160 TargetRegistry::RegisterMCObjectStreamer(TheSystemZTarget,
161 createSystemZMCObjectStreamer);