Evan Cheng | c60f9b7 | 2011-07-14 20:59:42 +0000 | [diff] [blame] | 1 | //===-- PPCMCTargetDesc.cpp - PowerPC Target Descriptions -------*- C++ -*-===// |
| 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 | 1abf2cb | 2011-07-14 23:50:31 +0000 | [diff] [blame] | 15 | #include "PPCMCAsmInfo.h" |
Evan Cheng | 2d28617 | 2011-07-18 22:29:13 +0000 | [diff] [blame] | 16 | #include "llvm/MC/MachineLocation.h" |
Evan Cheng | c60f9b7 | 2011-07-14 20:59:42 +0000 | [diff] [blame] | 17 | #include "llvm/MC/MCInstrInfo.h" |
| 18 | #include "llvm/MC/MCRegisterInfo.h" |
Evan Cheng | 966aeb5 | 2011-07-25 19:53:23 +0000 | [diff] [blame^] | 19 | #include "llvm/MC/MCStreamer.h" |
Evan Cheng | c60f9b7 | 2011-07-14 20:59:42 +0000 | [diff] [blame] | 20 | #include "llvm/MC/MCSubtargetInfo.h" |
| 21 | #include "llvm/Target/TargetRegistry.h" |
| 22 | |
| 23 | #define GET_INSTRINFO_MC_DESC |
| 24 | #include "PPCGenInstrInfo.inc" |
| 25 | |
| 26 | #define GET_SUBTARGETINFO_MC_DESC |
| 27 | #include "PPCGenSubtargetInfo.inc" |
| 28 | |
| 29 | #define GET_REGINFO_MC_DESC |
| 30 | #include "PPCGenRegisterInfo.inc" |
| 31 | |
| 32 | using namespace llvm; |
| 33 | |
Evan Cheng | 1abf2cb | 2011-07-14 23:50:31 +0000 | [diff] [blame] | 34 | static MCInstrInfo *createPPCMCInstrInfo() { |
Evan Cheng | c60f9b7 | 2011-07-14 20:59:42 +0000 | [diff] [blame] | 35 | MCInstrInfo *X = new MCInstrInfo(); |
| 36 | InitPPCMCInstrInfo(X); |
| 37 | return X; |
| 38 | } |
| 39 | |
Evan Cheng | 0e6a052 | 2011-07-18 20:57:22 +0000 | [diff] [blame] | 40 | static MCRegisterInfo *createPPCMCRegisterInfo(StringRef TT) { |
| 41 | Triple TheTriple(TT); |
| 42 | bool isPPC64 = (TheTriple.getArch() == Triple::ppc64); |
| 43 | unsigned Flavour = isPPC64 ? 0 : 1; |
| 44 | unsigned RA = isPPC64 ? PPC::LR8 : PPC::LR; |
| 45 | |
| 46 | MCRegisterInfo *X = new MCRegisterInfo(); |
| 47 | InitPPCMCRegisterInfo(X, RA, Flavour, Flavour); |
| 48 | return X; |
| 49 | } |
| 50 | |
Evan Cheng | 1abf2cb | 2011-07-14 23:50:31 +0000 | [diff] [blame] | 51 | static MCSubtargetInfo *createPPCMCSubtargetInfo(StringRef TT, StringRef CPU, |
| 52 | StringRef FS) { |
Evan Cheng | c60f9b7 | 2011-07-14 20:59:42 +0000 | [diff] [blame] | 53 | MCSubtargetInfo *X = new MCSubtargetInfo(); |
| 54 | InitPPCMCSubtargetInfo(X, TT, CPU, FS); |
| 55 | return X; |
| 56 | } |
| 57 | |
Evan Cheng | 2d28617 | 2011-07-18 22:29:13 +0000 | [diff] [blame] | 58 | static MCAsmInfo *createPPCMCAsmInfo(const Target &T, StringRef TT) { |
Evan Cheng | 1abf2cb | 2011-07-14 23:50:31 +0000 | [diff] [blame] | 59 | Triple TheTriple(TT); |
| 60 | bool isPPC64 = TheTriple.getArch() == Triple::ppc64; |
Evan Cheng | 2d28617 | 2011-07-18 22:29:13 +0000 | [diff] [blame] | 61 | |
| 62 | MCAsmInfo *MAI; |
Evan Cheng | 1abf2cb | 2011-07-14 23:50:31 +0000 | [diff] [blame] | 63 | if (TheTriple.isOSDarwin()) |
Evan Cheng | 2d28617 | 2011-07-18 22:29:13 +0000 | [diff] [blame] | 64 | MAI = new PPCMCAsmInfoDarwin(isPPC64); |
| 65 | else |
| 66 | MAI = new PPCLinuxMCAsmInfo(isPPC64); |
| 67 | |
| 68 | // Initial state of the frame pointer is R1. |
| 69 | MachineLocation Dst(MachineLocation::VirtualFP); |
| 70 | MachineLocation Src(PPC::R1, 0); |
| 71 | MAI->addInitialFrameState(0, Dst, Src); |
| 72 | |
| 73 | return MAI; |
Evan Cheng | 1abf2cb | 2011-07-14 23:50:31 +0000 | [diff] [blame] | 74 | } |
| 75 | |
Evan Cheng | 7f8dff6 | 2011-07-23 00:01:04 +0000 | [diff] [blame] | 76 | static MCCodeGenInfo *createPPCMCCodeGenInfo(StringRef TT, Reloc::Model RM, |
| 77 | CodeModel::Model CM) { |
Evan Cheng | 4396613 | 2011-07-19 06:37:02 +0000 | [diff] [blame] | 78 | MCCodeGenInfo *X = new MCCodeGenInfo(); |
| 79 | |
| 80 | if (RM == Reloc::Default) { |
| 81 | Triple T(TT); |
| 82 | if (T.isOSDarwin()) |
| 83 | RM = Reloc::DynamicNoPIC; |
| 84 | else |
| 85 | RM = Reloc::Static; |
| 86 | } |
Evan Cheng | 34ad6db | 2011-07-20 07:51:56 +0000 | [diff] [blame] | 87 | X->InitMCCodeGenInfo(RM, CM); |
Evan Cheng | 4396613 | 2011-07-19 06:37:02 +0000 | [diff] [blame] | 88 | return X; |
| 89 | } |
| 90 | |
Evan Cheng | 966aeb5 | 2011-07-25 19:53:23 +0000 | [diff] [blame^] | 91 | // This is duplicated code. Refactor this. |
| 92 | static MCStreamer *createMCStreamer(const Target &T, const std::string &TT, |
| 93 | MCContext &Ctx, TargetAsmBackend &TAB, |
| 94 | raw_ostream &OS, |
| 95 | MCCodeEmitter *Emitter, |
| 96 | bool RelaxAll, |
| 97 | bool NoExecStack) { |
| 98 | if (Triple(TT).isOSDarwin()) |
| 99 | return createMachOStreamer(Ctx, TAB, OS, Emitter, RelaxAll); |
| 100 | |
| 101 | return NULL; |
| 102 | } |
| 103 | |
Evan Cheng | e78085a | 2011-07-22 21:58:54 +0000 | [diff] [blame] | 104 | extern "C" void LLVMInitializePowerPCTargetMC() { |
| 105 | // Register the MC asm info. |
| 106 | RegisterMCAsmInfoFn C(ThePPC32Target, createPPCMCAsmInfo); |
| 107 | RegisterMCAsmInfoFn D(ThePPC64Target, createPPCMCAsmInfo); |
| 108 | |
| 109 | // Register the MC codegen info. |
Evan Cheng | 4396613 | 2011-07-19 06:37:02 +0000 | [diff] [blame] | 110 | TargetRegistry::RegisterMCCodeGenInfo(ThePPC32Target, createPPCMCCodeGenInfo); |
| 111 | TargetRegistry::RegisterMCCodeGenInfo(ThePPC64Target, createPPCMCCodeGenInfo); |
Evan Cheng | e78085a | 2011-07-22 21:58:54 +0000 | [diff] [blame] | 112 | |
| 113 | // Register the MC instruction info. |
| 114 | TargetRegistry::RegisterMCInstrInfo(ThePPC32Target, createPPCMCInstrInfo); |
| 115 | TargetRegistry::RegisterMCInstrInfo(ThePPC64Target, createPPCMCInstrInfo); |
| 116 | |
| 117 | // Register the MC register info. |
| 118 | TargetRegistry::RegisterMCRegInfo(ThePPC32Target, createPPCMCRegisterInfo); |
| 119 | TargetRegistry::RegisterMCRegInfo(ThePPC64Target, createPPCMCRegisterInfo); |
| 120 | |
| 121 | // Register the MC subtarget info. |
| 122 | TargetRegistry::RegisterMCSubtargetInfo(ThePPC32Target, |
| 123 | createPPCMCSubtargetInfo); |
| 124 | TargetRegistry::RegisterMCSubtargetInfo(ThePPC64Target, |
| 125 | createPPCMCSubtargetInfo); |
Evan Cheng | 966aeb5 | 2011-07-25 19:53:23 +0000 | [diff] [blame^] | 126 | |
| 127 | // Register the MC Code Emitter |
| 128 | TargetRegistry::RegisterCodeEmitter(ThePPC32Target, createPPCMCCodeEmitter); |
| 129 | TargetRegistry::RegisterCodeEmitter(ThePPC64Target, createPPCMCCodeEmitter); |
| 130 | |
| 131 | // Register the asm backend. |
| 132 | TargetRegistry::RegisterAsmBackend(ThePPC32Target, createPPCAsmBackend); |
| 133 | TargetRegistry::RegisterAsmBackend(ThePPC64Target, createPPCAsmBackend); |
| 134 | |
| 135 | // Register the object streamer. |
| 136 | TargetRegistry::RegisterObjectStreamer(ThePPC32Target, createMCStreamer); |
| 137 | TargetRegistry::RegisterObjectStreamer(ThePPC64Target, createMCStreamer); |
Evan Cheng | 4396613 | 2011-07-19 06:37:02 +0000 | [diff] [blame] | 138 | } |