Jia Liu | b22310f | 2012-02-18 12:03:15 +0000 | [diff] [blame] | 1 | //===-- PPCMCTargetDesc.cpp - PowerPC Target Descriptions -----------------===// |
Evan Cheng | bc153d4 | 2011-07-14 20:59:42 +0000 | [diff] [blame] | 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 | // This file provides PowerPC specific target descriptions. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | #include "PPCMCTargetDesc.h" |
Evan Cheng | 61faa55 | 2011-07-25 21:20:24 +0000 | [diff] [blame] | 15 | #include "InstPrinter/PPCInstPrinter.h" |
Chandler Carruth | ed0881b | 2012-12-03 16:50:05 +0000 | [diff] [blame] | 16 | #include "PPCMCAsmInfo.h" |
Evan Cheng | 4d6c9d7 | 2011-08-23 20:15:21 +0000 | [diff] [blame] | 17 | #include "llvm/MC/MCCodeGenInfo.h" |
Evan Cheng | bc153d4 | 2011-07-14 20:59:42 +0000 | [diff] [blame] | 18 | #include "llvm/MC/MCInstrInfo.h" |
| 19 | #include "llvm/MC/MCRegisterInfo.h" |
Evan Cheng | 61d4a20 | 2011-07-25 19:53:23 +0000 | [diff] [blame] | 20 | #include "llvm/MC/MCStreamer.h" |
Evan Cheng | bc153d4 | 2011-07-14 20:59:42 +0000 | [diff] [blame] | 21 | #include "llvm/MC/MCSubtargetInfo.h" |
Chandler Carruth | ed0881b | 2012-12-03 16:50:05 +0000 | [diff] [blame] | 22 | #include "llvm/MC/MachineLocation.h" |
Craig Topper | c4965bc | 2012-02-05 07:21:30 +0000 | [diff] [blame] | 23 | #include "llvm/Support/ErrorHandling.h" |
Evan Cheng | 2bb4035 | 2011-08-24 18:08:43 +0000 | [diff] [blame] | 24 | #include "llvm/Support/TargetRegistry.h" |
Evan Cheng | bc153d4 | 2011-07-14 20:59:42 +0000 | [diff] [blame] | 25 | |
| 26 | #define GET_INSTRINFO_MC_DESC |
| 27 | #include "PPCGenInstrInfo.inc" |
| 28 | |
| 29 | #define GET_SUBTARGETINFO_MC_DESC |
| 30 | #include "PPCGenSubtargetInfo.inc" |
| 31 | |
| 32 | #define GET_REGINFO_MC_DESC |
| 33 | #include "PPCGenRegisterInfo.inc" |
| 34 | |
| 35 | using namespace llvm; |
| 36 | |
Evan Cheng | 1705ab0 | 2011-07-14 23:50:31 +0000 | [diff] [blame] | 37 | static MCInstrInfo *createPPCMCInstrInfo() { |
Evan Cheng | bc153d4 | 2011-07-14 20:59:42 +0000 | [diff] [blame] | 38 | MCInstrInfo *X = new MCInstrInfo(); |
| 39 | InitPPCMCInstrInfo(X); |
| 40 | return X; |
| 41 | } |
| 42 | |
Evan Cheng | d60fa58b | 2011-07-18 20:57:22 +0000 | [diff] [blame] | 43 | static MCRegisterInfo *createPPCMCRegisterInfo(StringRef TT) { |
| 44 | Triple TheTriple(TT); |
Bill Schmidt | 0a9170d | 2013-07-26 01:35:43 +0000 | [diff] [blame^] | 45 | bool isPPC64 = (TheTriple.getArch() == Triple::ppc64 || |
| 46 | TheTriple.getArch() == Triple::ppc64le); |
Evan Cheng | d60fa58b | 2011-07-18 20:57:22 +0000 | [diff] [blame] | 47 | unsigned Flavour = isPPC64 ? 0 : 1; |
| 48 | unsigned RA = isPPC64 ? PPC::LR8 : PPC::LR; |
| 49 | |
| 50 | MCRegisterInfo *X = new MCRegisterInfo(); |
| 51 | InitPPCMCRegisterInfo(X, RA, Flavour, Flavour); |
| 52 | return X; |
| 53 | } |
| 54 | |
Evan Cheng | 1705ab0 | 2011-07-14 23:50:31 +0000 | [diff] [blame] | 55 | static MCSubtargetInfo *createPPCMCSubtargetInfo(StringRef TT, StringRef CPU, |
| 56 | StringRef FS) { |
Evan Cheng | bc153d4 | 2011-07-14 20:59:42 +0000 | [diff] [blame] | 57 | MCSubtargetInfo *X = new MCSubtargetInfo(); |
| 58 | InitPPCMCSubtargetInfo(X, TT, CPU, FS); |
| 59 | return X; |
| 60 | } |
| 61 | |
Rafael Espindola | 227144c | 2013-05-13 01:16:13 +0000 | [diff] [blame] | 62 | static MCAsmInfo *createPPCMCAsmInfo(const MCRegisterInfo &MRI, StringRef TT) { |
Evan Cheng | 1705ab0 | 2011-07-14 23:50:31 +0000 | [diff] [blame] | 63 | Triple TheTriple(TT); |
Bill Schmidt | 0a9170d | 2013-07-26 01:35:43 +0000 | [diff] [blame^] | 64 | bool isPPC64 = (TheTriple.getArch() == Triple::ppc64 || |
| 65 | TheTriple.getArch() == Triple::ppc64le); |
Evan Cheng | 67c033e | 2011-07-18 22:29:13 +0000 | [diff] [blame] | 66 | |
| 67 | MCAsmInfo *MAI; |
Evan Cheng | 1705ab0 | 2011-07-14 23:50:31 +0000 | [diff] [blame] | 68 | if (TheTriple.isOSDarwin()) |
Evan Cheng | 67c033e | 2011-07-18 22:29:13 +0000 | [diff] [blame] | 69 | MAI = new PPCMCAsmInfoDarwin(isPPC64); |
| 70 | else |
| 71 | MAI = new PPCLinuxMCAsmInfo(isPPC64); |
| 72 | |
| 73 | // Initial state of the frame pointer is R1. |
Rafael Espindola | 227144c | 2013-05-13 01:16:13 +0000 | [diff] [blame] | 74 | unsigned Reg = isPPC64 ? PPC::X1 : PPC::R1; |
| 75 | MCCFIInstruction Inst = |
| 76 | MCCFIInstruction::createDefCfa(0, MRI.getDwarfRegNum(Reg, true), 0); |
| 77 | MAI->addInitialFrameState(Inst); |
Evan Cheng | 67c033e | 2011-07-18 22:29:13 +0000 | [diff] [blame] | 78 | |
| 79 | return MAI; |
Evan Cheng | 1705ab0 | 2011-07-14 23:50:31 +0000 | [diff] [blame] | 80 | } |
| 81 | |
Evan Cheng | 6376593 | 2011-07-23 00:01:04 +0000 | [diff] [blame] | 82 | static MCCodeGenInfo *createPPCMCCodeGenInfo(StringRef TT, Reloc::Model RM, |
Evan Cheng | ecb2908 | 2011-11-16 08:38:26 +0000 | [diff] [blame] | 83 | CodeModel::Model CM, |
| 84 | CodeGenOpt::Level OL) { |
Evan Cheng | 2129f59 | 2011-07-19 06:37:02 +0000 | [diff] [blame] | 85 | MCCodeGenInfo *X = new MCCodeGenInfo(); |
| 86 | |
| 87 | if (RM == Reloc::Default) { |
| 88 | Triple T(TT); |
| 89 | if (T.isOSDarwin()) |
| 90 | RM = Reloc::DynamicNoPIC; |
| 91 | else |
| 92 | RM = Reloc::Static; |
| 93 | } |
Bill Schmidt | e0a68a5 | 2012-11-27 23:36:26 +0000 | [diff] [blame] | 94 | if (CM == CodeModel::Default) { |
| 95 | Triple T(TT); |
Bill Schmidt | 0a9170d | 2013-07-26 01:35:43 +0000 | [diff] [blame^] | 96 | if (!T.isOSDarwin() && |
| 97 | (T.getArch() == Triple::ppc64 || T.getArch() == Triple::ppc64le)) |
Bill Schmidt | e0a68a5 | 2012-11-27 23:36:26 +0000 | [diff] [blame] | 98 | CM = CodeModel::Medium; |
| 99 | } |
Evan Cheng | ecb2908 | 2011-11-16 08:38:26 +0000 | [diff] [blame] | 100 | X->InitMCCodeGenInfo(RM, CM, OL); |
Evan Cheng | 2129f59 | 2011-07-19 06:37:02 +0000 | [diff] [blame] | 101 | return X; |
| 102 | } |
| 103 | |
Evan Cheng | 61d4a20 | 2011-07-25 19:53:23 +0000 | [diff] [blame] | 104 | // This is duplicated code. Refactor this. |
Evan Cheng | 3a79225 | 2011-07-26 00:42:34 +0000 | [diff] [blame] | 105 | static MCStreamer *createMCStreamer(const Target &T, StringRef TT, |
Evan Cheng | 5928e69 | 2011-07-25 23:24:55 +0000 | [diff] [blame] | 106 | MCContext &Ctx, MCAsmBackend &MAB, |
Evan Cheng | 61d4a20 | 2011-07-25 19:53:23 +0000 | [diff] [blame] | 107 | raw_ostream &OS, |
| 108 | MCCodeEmitter *Emitter, |
| 109 | bool RelaxAll, |
| 110 | bool NoExecStack) { |
| 111 | if (Triple(TT).isOSDarwin()) |
Evan Cheng | 5928e69 | 2011-07-25 23:24:55 +0000 | [diff] [blame] | 112 | return createMachOStreamer(Ctx, MAB, OS, Emitter, RelaxAll); |
Evan Cheng | 61d4a20 | 2011-07-25 19:53:23 +0000 | [diff] [blame] | 113 | |
Roman Divacky | e6a11dc | 2011-08-02 15:54:03 +0000 | [diff] [blame] | 114 | return createELFStreamer(Ctx, MAB, OS, Emitter, RelaxAll, NoExecStack); |
Evan Cheng | 61d4a20 | 2011-07-25 19:53:23 +0000 | [diff] [blame] | 115 | } |
| 116 | |
Evan Cheng | 61faa55 | 2011-07-25 21:20:24 +0000 | [diff] [blame] | 117 | static MCInstPrinter *createPPCMCInstPrinter(const Target &T, |
| 118 | unsigned SyntaxVariant, |
James Molloy | 4c493e8 | 2011-09-07 17:24:38 +0000 | [diff] [blame] | 119 | const MCAsmInfo &MAI, |
Craig Topper | 54bfde7 | 2012-04-02 06:09:36 +0000 | [diff] [blame] | 120 | const MCInstrInfo &MII, |
Jim Grosbach | fd93a59 | 2012-03-05 19:33:20 +0000 | [diff] [blame] | 121 | const MCRegisterInfo &MRI, |
James Molloy | 4c493e8 | 2011-09-07 17:24:38 +0000 | [diff] [blame] | 122 | const MCSubtargetInfo &STI) { |
Ulrich Weigand | 266db7f | 2013-07-08 20:20:51 +0000 | [diff] [blame] | 123 | bool isDarwin = Triple(STI.getTargetTriple()).isOSDarwin(); |
| 124 | return new PPCInstPrinter(MAI, MII, MRI, isDarwin); |
Evan Cheng | 61faa55 | 2011-07-25 21:20:24 +0000 | [diff] [blame] | 125 | } |
| 126 | |
Evan Cheng | 8c886a4 | 2011-07-22 21:58:54 +0000 | [diff] [blame] | 127 | extern "C" void LLVMInitializePowerPCTargetMC() { |
| 128 | // Register the MC asm info. |
| 129 | RegisterMCAsmInfoFn C(ThePPC32Target, createPPCMCAsmInfo); |
| 130 | RegisterMCAsmInfoFn D(ThePPC64Target, createPPCMCAsmInfo); |
Bill Schmidt | 0a9170d | 2013-07-26 01:35:43 +0000 | [diff] [blame^] | 131 | RegisterMCAsmInfoFn E(ThePPC64LETarget, createPPCMCAsmInfo); |
Evan Cheng | 8c886a4 | 2011-07-22 21:58:54 +0000 | [diff] [blame] | 132 | |
| 133 | // Register the MC codegen info. |
Evan Cheng | 2129f59 | 2011-07-19 06:37:02 +0000 | [diff] [blame] | 134 | TargetRegistry::RegisterMCCodeGenInfo(ThePPC32Target, createPPCMCCodeGenInfo); |
| 135 | TargetRegistry::RegisterMCCodeGenInfo(ThePPC64Target, createPPCMCCodeGenInfo); |
Bill Schmidt | 0a9170d | 2013-07-26 01:35:43 +0000 | [diff] [blame^] | 136 | TargetRegistry::RegisterMCCodeGenInfo(ThePPC64LETarget, |
| 137 | createPPCMCCodeGenInfo); |
Evan Cheng | 8c886a4 | 2011-07-22 21:58:54 +0000 | [diff] [blame] | 138 | |
| 139 | // Register the MC instruction info. |
| 140 | TargetRegistry::RegisterMCInstrInfo(ThePPC32Target, createPPCMCInstrInfo); |
| 141 | TargetRegistry::RegisterMCInstrInfo(ThePPC64Target, createPPCMCInstrInfo); |
Bill Schmidt | 0a9170d | 2013-07-26 01:35:43 +0000 | [diff] [blame^] | 142 | TargetRegistry::RegisterMCInstrInfo(ThePPC64LETarget, |
| 143 | createPPCMCInstrInfo); |
Evan Cheng | 8c886a4 | 2011-07-22 21:58:54 +0000 | [diff] [blame] | 144 | |
| 145 | // Register the MC register info. |
| 146 | TargetRegistry::RegisterMCRegInfo(ThePPC32Target, createPPCMCRegisterInfo); |
| 147 | TargetRegistry::RegisterMCRegInfo(ThePPC64Target, createPPCMCRegisterInfo); |
Bill Schmidt | 0a9170d | 2013-07-26 01:35:43 +0000 | [diff] [blame^] | 148 | TargetRegistry::RegisterMCRegInfo(ThePPC64LETarget, createPPCMCRegisterInfo); |
Evan Cheng | 8c886a4 | 2011-07-22 21:58:54 +0000 | [diff] [blame] | 149 | |
| 150 | // Register the MC subtarget info. |
| 151 | TargetRegistry::RegisterMCSubtargetInfo(ThePPC32Target, |
| 152 | createPPCMCSubtargetInfo); |
| 153 | TargetRegistry::RegisterMCSubtargetInfo(ThePPC64Target, |
| 154 | createPPCMCSubtargetInfo); |
Bill Schmidt | 0a9170d | 2013-07-26 01:35:43 +0000 | [diff] [blame^] | 155 | TargetRegistry::RegisterMCSubtargetInfo(ThePPC64LETarget, |
| 156 | createPPCMCSubtargetInfo); |
Evan Cheng | 61d4a20 | 2011-07-25 19:53:23 +0000 | [diff] [blame] | 157 | |
| 158 | // Register the MC Code Emitter |
Evan Cheng | 3a79225 | 2011-07-26 00:42:34 +0000 | [diff] [blame] | 159 | TargetRegistry::RegisterMCCodeEmitter(ThePPC32Target, createPPCMCCodeEmitter); |
| 160 | TargetRegistry::RegisterMCCodeEmitter(ThePPC64Target, createPPCMCCodeEmitter); |
Bill Schmidt | 0a9170d | 2013-07-26 01:35:43 +0000 | [diff] [blame^] | 161 | TargetRegistry::RegisterMCCodeEmitter(ThePPC64LETarget, |
| 162 | createPPCMCCodeEmitter); |
Evan Cheng | 61d4a20 | 2011-07-25 19:53:23 +0000 | [diff] [blame] | 163 | |
| 164 | // Register the asm backend. |
Evan Cheng | 5928e69 | 2011-07-25 23:24:55 +0000 | [diff] [blame] | 165 | TargetRegistry::RegisterMCAsmBackend(ThePPC32Target, createPPCAsmBackend); |
| 166 | TargetRegistry::RegisterMCAsmBackend(ThePPC64Target, createPPCAsmBackend); |
Bill Schmidt | 0a9170d | 2013-07-26 01:35:43 +0000 | [diff] [blame^] | 167 | TargetRegistry::RegisterMCAsmBackend(ThePPC64LETarget, createPPCAsmBackend); |
Evan Cheng | 61d4a20 | 2011-07-25 19:53:23 +0000 | [diff] [blame] | 168 | |
| 169 | // Register the object streamer. |
Evan Cheng | 3a79225 | 2011-07-26 00:42:34 +0000 | [diff] [blame] | 170 | TargetRegistry::RegisterMCObjectStreamer(ThePPC32Target, createMCStreamer); |
| 171 | TargetRegistry::RegisterMCObjectStreamer(ThePPC64Target, createMCStreamer); |
Bill Schmidt | 0a9170d | 2013-07-26 01:35:43 +0000 | [diff] [blame^] | 172 | TargetRegistry::RegisterMCObjectStreamer(ThePPC64LETarget, createMCStreamer); |
Evan Cheng | 61faa55 | 2011-07-25 21:20:24 +0000 | [diff] [blame] | 173 | |
| 174 | // Register the MCInstPrinter. |
| 175 | TargetRegistry::RegisterMCInstPrinter(ThePPC32Target, createPPCMCInstPrinter); |
| 176 | TargetRegistry::RegisterMCInstPrinter(ThePPC64Target, createPPCMCInstPrinter); |
Bill Schmidt | 0a9170d | 2013-07-26 01:35:43 +0000 | [diff] [blame^] | 177 | TargetRegistry::RegisterMCInstPrinter(ThePPC64LETarget, |
| 178 | createPPCMCInstPrinter); |
Evan Cheng | 2129f59 | 2011-07-19 06:37:02 +0000 | [diff] [blame] | 179 | } |