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 "InstPrinter/PPCInstPrinter.h"
17 #include "llvm/MC/MachineLocation.h"
18 #include "llvm/MC/MCInstrInfo.h"
19 #include "llvm/MC/MCRegisterInfo.h"
20 #include "llvm/MC/MCStreamer.h"
21 #include "llvm/MC/MCSubtargetInfo.h"
22 #include "llvm/Target/TargetRegistry.h"
24 #define GET_INSTRINFO_MC_DESC
25 #include "PPCGenInstrInfo.inc"
27 #define GET_SUBTARGETINFO_MC_DESC
28 #include "PPCGenSubtargetInfo.inc"
30 #define GET_REGINFO_MC_DESC
31 #include "PPCGenRegisterInfo.inc"
35 static MCInstrInfo *createPPCMCInstrInfo() {
36 MCInstrInfo *X = new MCInstrInfo();
37 InitPPCMCInstrInfo(X);
41 static MCRegisterInfo *createPPCMCRegisterInfo(StringRef TT) {
43 bool isPPC64 = (TheTriple.getArch() == Triple::ppc64);
44 unsigned Flavour = isPPC64 ? 0 : 1;
45 unsigned RA = isPPC64 ? PPC::LR8 : PPC::LR;
47 MCRegisterInfo *X = new MCRegisterInfo();
48 InitPPCMCRegisterInfo(X, RA, Flavour, Flavour);
52 static MCSubtargetInfo *createPPCMCSubtargetInfo(StringRef TT, StringRef CPU,
54 MCSubtargetInfo *X = new MCSubtargetInfo();
55 InitPPCMCSubtargetInfo(X, TT, CPU, FS);
59 static MCAsmInfo *createPPCMCAsmInfo(const Target &T, StringRef TT) {
61 bool isPPC64 = TheTriple.getArch() == Triple::ppc64;
64 if (TheTriple.isOSDarwin())
65 MAI = new PPCMCAsmInfoDarwin(isPPC64);
67 MAI = new PPCLinuxMCAsmInfo(isPPC64);
69 // Initial state of the frame pointer is R1.
70 MachineLocation Dst(MachineLocation::VirtualFP);
71 MachineLocation Src(PPC::R1, 0);
72 MAI->addInitialFrameState(0, Dst, Src);
77 static MCCodeGenInfo *createPPCMCCodeGenInfo(StringRef TT, Reloc::Model RM,
78 CodeModel::Model CM) {
79 MCCodeGenInfo *X = new MCCodeGenInfo();
81 if (RM == Reloc::Default) {
84 RM = Reloc::DynamicNoPIC;
88 X->InitMCCodeGenInfo(RM, CM);
92 // This is duplicated code. Refactor this.
93 static MCStreamer *createMCStreamer(const Target &T, StringRef TT,
94 MCContext &Ctx, MCAsmBackend &MAB,
96 MCCodeEmitter *Emitter,
99 if (Triple(TT).isOSDarwin())
100 return createMachOStreamer(Ctx, MAB, OS, Emitter, RelaxAll);
105 static MCInstPrinter *createPPCMCInstPrinter(const Target &T,
106 unsigned SyntaxVariant,
107 const MCAsmInfo &MAI) {
108 return new PPCInstPrinter(MAI, SyntaxVariant);
111 extern "C" void LLVMInitializePowerPCTargetMC() {
112 // Register the MC asm info.
113 RegisterMCAsmInfoFn C(ThePPC32Target, createPPCMCAsmInfo);
114 RegisterMCAsmInfoFn D(ThePPC64Target, createPPCMCAsmInfo);
116 // Register the MC codegen info.
117 TargetRegistry::RegisterMCCodeGenInfo(ThePPC32Target, createPPCMCCodeGenInfo);
118 TargetRegistry::RegisterMCCodeGenInfo(ThePPC64Target, createPPCMCCodeGenInfo);
120 // Register the MC instruction info.
121 TargetRegistry::RegisterMCInstrInfo(ThePPC32Target, createPPCMCInstrInfo);
122 TargetRegistry::RegisterMCInstrInfo(ThePPC64Target, createPPCMCInstrInfo);
124 // Register the MC register info.
125 TargetRegistry::RegisterMCRegInfo(ThePPC32Target, createPPCMCRegisterInfo);
126 TargetRegistry::RegisterMCRegInfo(ThePPC64Target, createPPCMCRegisterInfo);
128 // Register the MC subtarget info.
129 TargetRegistry::RegisterMCSubtargetInfo(ThePPC32Target,
130 createPPCMCSubtargetInfo);
131 TargetRegistry::RegisterMCSubtargetInfo(ThePPC64Target,
132 createPPCMCSubtargetInfo);
134 // Register the MC Code Emitter
135 TargetRegistry::RegisterMCCodeEmitter(ThePPC32Target, createPPCMCCodeEmitter);
136 TargetRegistry::RegisterMCCodeEmitter(ThePPC64Target, createPPCMCCodeEmitter);
138 // Register the asm backend.
139 TargetRegistry::RegisterMCAsmBackend(ThePPC32Target, createPPCAsmBackend);
140 TargetRegistry::RegisterMCAsmBackend(ThePPC64Target, createPPCAsmBackend);
142 // Register the object streamer.
143 TargetRegistry::RegisterMCObjectStreamer(ThePPC32Target, createMCStreamer);
144 TargetRegistry::RegisterMCObjectStreamer(ThePPC64Target, createMCStreamer);
146 // Register the MCInstPrinter.
147 TargetRegistry::RegisterMCInstPrinter(ThePPC32Target, createPPCMCInstPrinter);
148 TargetRegistry::RegisterMCInstPrinter(ThePPC64Target, createPPCMCInstPrinter);