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