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" |
| 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 | |
Rafael Espindola | 227144c | 2013-05-13 01:16:13 +0000 | [diff] [blame^] | 30 | static MCAsmInfo *createSystemZMCAsmInfo(const MCRegisterInfo &MRI, |
| 31 | StringRef TT) { |
Rafael Espindola | 140a837 | 2013-05-10 18:16:59 +0000 | [diff] [blame] | 32 | MCAsmInfo *MAI = new SystemZMCAsmInfo(TT); |
Rafael Espindola | 227144c | 2013-05-13 01:16:13 +0000 | [diff] [blame^] | 33 | MCCFIInstruction Inst = |
| 34 | MCCFIInstruction::createDefCfa(0, MRI.getDwarfRegNum(SystemZ::R15D, true), |
| 35 | SystemZMC::CFAOffsetFromInitialSP); |
| 36 | MAI->addInitialFrameState(Inst); |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 37 | return MAI; |
| 38 | } |
| 39 | |
| 40 | static MCInstrInfo *createSystemZMCInstrInfo() { |
| 41 | MCInstrInfo *X = new MCInstrInfo(); |
| 42 | InitSystemZMCInstrInfo(X); |
| 43 | return X; |
| 44 | } |
| 45 | |
| 46 | static MCRegisterInfo *createSystemZMCRegisterInfo(StringRef TT) { |
| 47 | MCRegisterInfo *X = new MCRegisterInfo(); |
| 48 | InitSystemZMCRegisterInfo(X, SystemZ::R14D); |
| 49 | return X; |
| 50 | } |
| 51 | |
| 52 | static MCSubtargetInfo *createSystemZMCSubtargetInfo(StringRef TT, |
| 53 | StringRef CPU, |
| 54 | StringRef FS) { |
| 55 | MCSubtargetInfo *X = new MCSubtargetInfo(); |
| 56 | InitSystemZMCSubtargetInfo(X, TT, CPU, FS); |
| 57 | return X; |
| 58 | } |
| 59 | |
| 60 | static MCCodeGenInfo *createSystemZMCCodeGenInfo(StringRef TT, Reloc::Model RM, |
| 61 | CodeModel::Model CM, |
Richard Sandiford | 9589691 | 2013-05-07 12:56:31 +0000 | [diff] [blame] | 62 | CodeGenOpt::Level OL) { |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 63 | MCCodeGenInfo *X = new MCCodeGenInfo(); |
| 64 | |
| 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) |
| 68 | RM = Reloc::Static; |
| 69 | |
| 70 | // For SystemZ we define the models as follows: |
| 71 | // |
| 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. |
| 74 | // |
| 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. |
| 78 | // |
| 79 | // Large: Equivalent to Medium for now. |
| 80 | // |
| 81 | // Kernel: Equivalent to Medium for now. |
| 82 | // |
| 83 | // This means that any PIC module smaller than 4GB meets the |
| 84 | // requirements of Small, so Small seems like the best default there. |
| 85 | // |
| 86 | // All symbols bind locally in a non-PIC module, so the choice is less |
| 87 | // obvious. There are two cases: |
| 88 | // |
| 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. |
| 93 | // |
| 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; |
Richard Sandiford | 9589691 | 2013-05-07 12:56:31 +0000 | [diff] [blame] | 103 | X->InitMCCodeGenInfo(RM, CM, OL); |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 104 | return X; |
| 105 | } |
| 106 | |
| 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); |
| 114 | } |
| 115 | |
| 116 | static MCStreamer *createSystemZMCObjectStreamer(const Target &T, StringRef TT, |
| 117 | MCContext &Ctx, |
| 118 | MCAsmBackend &MAB, |
| 119 | raw_ostream &OS, |
| 120 | MCCodeEmitter *Emitter, |
| 121 | bool RelaxAll, |
| 122 | bool NoExecStack) { |
| 123 | return createELFStreamer(Ctx, MAB, OS, Emitter, RelaxAll, NoExecStack); |
| 124 | } |
| 125 | |
| 126 | extern "C" void LLVMInitializeSystemZTargetMC() { |
| 127 | // Register the MCAsmInfo. |
| 128 | TargetRegistry::RegisterMCAsmInfo(TheSystemZTarget, |
| 129 | createSystemZMCAsmInfo); |
| 130 | |
| 131 | // Register the MCCodeGenInfo. |
| 132 | TargetRegistry::RegisterMCCodeGenInfo(TheSystemZTarget, |
| 133 | createSystemZMCCodeGenInfo); |
| 134 | |
| 135 | // Register the MCCodeEmitter. |
| 136 | TargetRegistry::RegisterMCCodeEmitter(TheSystemZTarget, |
| 137 | createSystemZMCCodeEmitter); |
| 138 | |
| 139 | // Register the MCInstrInfo. |
| 140 | TargetRegistry::RegisterMCInstrInfo(TheSystemZTarget, |
| 141 | createSystemZMCInstrInfo); |
| 142 | |
| 143 | // Register the MCRegisterInfo. |
| 144 | TargetRegistry::RegisterMCRegInfo(TheSystemZTarget, |
| 145 | createSystemZMCRegisterInfo); |
| 146 | |
| 147 | // Register the MCSubtargetInfo. |
| 148 | TargetRegistry::RegisterMCSubtargetInfo(TheSystemZTarget, |
| 149 | createSystemZMCSubtargetInfo); |
| 150 | |
| 151 | // Register the MCAsmBackend. |
| 152 | TargetRegistry::RegisterMCAsmBackend(TheSystemZTarget, |
| 153 | createSystemZMCAsmBackend); |
| 154 | |
| 155 | // Register the MCInstPrinter. |
| 156 | TargetRegistry::RegisterMCInstPrinter(TheSystemZTarget, |
| 157 | createSystemZMCInstPrinter); |
| 158 | |
| 159 | // Register the MCObjectStreamer; |
| 160 | TargetRegistry::RegisterMCObjectStreamer(TheSystemZTarget, |
| 161 | createSystemZMCObjectStreamer); |
| 162 | } |