1 //===-- 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 28 using namespace llvm; 29 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 35 }; 36 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 42 }; 43 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 49 }; 50 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 56 }; 57 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 63 }; 64 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 70 }; 71 72 static MCAsmInfo *createSystemZMCAsmInfo(const MCRegisterInfo &MRI, 73 StringRef TT) { 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); 79 return MAI; 80 } 81 82 static MCInstrInfo *createSystemZMCInstrInfo() { 83 MCInstrInfo *X = new MCInstrInfo(); 84 InitSystemZMCInstrInfo(X); 85 return X; 86 } 87 88 static MCRegisterInfo *createSystemZMCRegisterInfo(StringRef TT) { 89 MCRegisterInfo *X = new MCRegisterInfo(); 90 InitSystemZMCRegisterInfo(X, SystemZ::R14D); 91 return X; 92 } 93 94 static MCSubtargetInfo *createSystemZMCSubtargetInfo(StringRef TT, 95 StringRef CPU, 96 StringRef FS) { 97 MCSubtargetInfo *X = new MCSubtargetInfo(); 98 InitSystemZMCSubtargetInfo(X, TT, CPU, FS); 99 return X; 100 } 101 102 static MCCodeGenInfo *createSystemZMCCodeGenInfo(StringRef TT, Reloc::Model RM, 103 CodeModel::Model CM, 104 CodeGenOpt::Level OL) { 105 MCCodeGenInfo *X = new MCCodeGenInfo(); 106 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) 110 RM = Reloc::Static; 111 112 // For SystemZ we define the models as follows: 113 // 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. 116 // 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. 120 // 121 // Large: Equivalent to Medium for now. 122 // 123 // Kernel: Equivalent to Medium for now. 124 // 125 // This means that any PIC module smaller than 4GB meets the 126 // requirements of Small, so Small seems like the best default there. 127 // 128 // All symbols bind locally in a non-PIC module, so the choice is less 129 // obvious. There are two cases: 130 // 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. 135 // 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); 146 return X; 147 } 148 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); 156 } 157 158 static MCStreamer *createSystemZMCObjectStreamer(const Target &T, StringRef TT, 159 MCContext &Ctx, 160 MCAsmBackend &MAB, 161 raw_ostream &OS, 162 MCCodeEmitter *Emitter, 163 bool RelaxAll, 164 bool NoExecStack) { 165 return createELFStreamer(Ctx, MAB, OS, Emitter, RelaxAll, NoExecStack); 166 } 167 168 extern "C" void LLVMInitializeSystemZTargetMC() { 169 // Register the MCAsmInfo. 170 TargetRegistry::RegisterMCAsmInfo(TheSystemZTarget, 171 createSystemZMCAsmInfo); 172 173 // Register the MCCodeGenInfo. 174 TargetRegistry::RegisterMCCodeGenInfo(TheSystemZTarget, 175 createSystemZMCCodeGenInfo); 176 177 // Register the MCCodeEmitter. 178 TargetRegistry::RegisterMCCodeEmitter(TheSystemZTarget, 179 createSystemZMCCodeEmitter); 180 181 // Register the MCInstrInfo. 182 TargetRegistry::RegisterMCInstrInfo(TheSystemZTarget, 183 createSystemZMCInstrInfo); 184 185 // Register the MCRegisterInfo. 186 TargetRegistry::RegisterMCRegInfo(TheSystemZTarget, 187 createSystemZMCRegisterInfo); 188 189 // Register the MCSubtargetInfo. 190 TargetRegistry::RegisterMCSubtargetInfo(TheSystemZTarget, 191 createSystemZMCSubtargetInfo); 192 193 // Register the MCAsmBackend. 194 TargetRegistry::RegisterMCAsmBackend(TheSystemZTarget, 195 createSystemZMCAsmBackend); 196 197 // Register the MCInstPrinter. 198 TargetRegistry::RegisterMCInstPrinter(TheSystemZTarget, 199 createSystemZMCInstPrinter); 200 201 // Register the MCObjectStreamer; 202 TargetRegistry::RegisterMCObjectStreamer(TheSystemZTarget, 203 createSystemZMCObjectStreamer); 204 } 205