1 //===-- PPCMCTargetDesc.cpp - PowerPC Target Descriptions -------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file provides PowerPC specific target descriptions.
12 //===----------------------------------------------------------------------===//
14 #include "PPCMCTargetDesc.h"
15 #include "PPCMCAsmInfo.h"
16 #include "llvm/MC/MachineLocation.h"
17 #include "llvm/MC/MCInstrInfo.h"
18 #include "llvm/MC/MCRegisterInfo.h"
19 #include "llvm/MC/MCStreamer.h"
20 #include "llvm/MC/MCSubtargetInfo.h"
21 #include "llvm/Target/TargetRegistry.h"
23 #define GET_INSTRINFO_MC_DESC
24 #include "PPCGenInstrInfo.inc"
26 #define GET_SUBTARGETINFO_MC_DESC
27 #include "PPCGenSubtargetInfo.inc"
29 #define GET_REGINFO_MC_DESC
30 #include "PPCGenRegisterInfo.inc"
34 static MCInstrInfo *createPPCMCInstrInfo() {
35 MCInstrInfo *X = new MCInstrInfo();
36 InitPPCMCInstrInfo(X);
40 static MCRegisterInfo *createPPCMCRegisterInfo(StringRef TT) {
42 bool isPPC64 = (TheTriple.getArch() == Triple::ppc64);
43 unsigned Flavour = isPPC64 ? 0 : 1;
44 unsigned RA = isPPC64 ? PPC::LR8 : PPC::LR;
46 MCRegisterInfo *X = new MCRegisterInfo();
47 InitPPCMCRegisterInfo(X, RA, Flavour, Flavour);
51 static MCSubtargetInfo *createPPCMCSubtargetInfo(StringRef TT, StringRef CPU,
53 MCSubtargetInfo *X = new MCSubtargetInfo();
54 InitPPCMCSubtargetInfo(X, TT, CPU, FS);
58 static MCAsmInfo *createPPCMCAsmInfo(const Target &T, StringRef TT) {
60 bool isPPC64 = TheTriple.getArch() == Triple::ppc64;
63 if (TheTriple.isOSDarwin())
64 MAI = new PPCMCAsmInfoDarwin(isPPC64);
66 MAI = new PPCLinuxMCAsmInfo(isPPC64);
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);
76 static MCCodeGenInfo *createPPCMCCodeGenInfo(StringRef TT, Reloc::Model RM,
77 CodeModel::Model CM) {
78 MCCodeGenInfo *X = new MCCodeGenInfo();
80 if (RM == Reloc::Default) {
83 RM = Reloc::DynamicNoPIC;
87 X->InitMCCodeGenInfo(RM, CM);
91 // This is duplicated code. Refactor this.
92 static MCStreamer *createMCStreamer(const Target &T, const std::string &TT,
93 MCContext &Ctx, TargetAsmBackend &TAB,
95 MCCodeEmitter *Emitter,
98 if (Triple(TT).isOSDarwin())
99 return createMachOStreamer(Ctx, TAB, OS, Emitter, RelaxAll);
104 extern "C" void LLVMInitializePowerPCTargetMC() {
105 // Register the MC asm info.
106 RegisterMCAsmInfoFn C(ThePPC32Target, createPPCMCAsmInfo);
107 RegisterMCAsmInfoFn D(ThePPC64Target, createPPCMCAsmInfo);
109 // Register the MC codegen info.
110 TargetRegistry::RegisterMCCodeGenInfo(ThePPC32Target, createPPCMCCodeGenInfo);
111 TargetRegistry::RegisterMCCodeGenInfo(ThePPC64Target, createPPCMCCodeGenInfo);
113 // Register the MC instruction info.
114 TargetRegistry::RegisterMCInstrInfo(ThePPC32Target, createPPCMCInstrInfo);
115 TargetRegistry::RegisterMCInstrInfo(ThePPC64Target, createPPCMCInstrInfo);
117 // Register the MC register info.
118 TargetRegistry::RegisterMCRegInfo(ThePPC32Target, createPPCMCRegisterInfo);
119 TargetRegistry::RegisterMCRegInfo(ThePPC64Target, createPPCMCRegisterInfo);
121 // Register the MC subtarget info.
122 TargetRegistry::RegisterMCSubtargetInfo(ThePPC32Target,
123 createPPCMCSubtargetInfo);
124 TargetRegistry::RegisterMCSubtargetInfo(ThePPC64Target,
125 createPPCMCSubtargetInfo);
127 // Register the MC Code Emitter
128 TargetRegistry::RegisterCodeEmitter(ThePPC32Target, createPPCMCCodeEmitter);
129 TargetRegistry::RegisterCodeEmitter(ThePPC64Target, createPPCMCCodeEmitter);
131 // Register the asm backend.
132 TargetRegistry::RegisterAsmBackend(ThePPC32Target, createPPCAsmBackend);
133 TargetRegistry::RegisterAsmBackend(ThePPC64Target, createPPCAsmBackend);
135 // Register the object streamer.
136 TargetRegistry::RegisterObjectStreamer(ThePPC32Target, createMCStreamer);
137 TargetRegistry::RegisterObjectStreamer(ThePPC64Target, createMCStreamer);