PPCMCTargetDesc.cpp revision 7f8dff65717b1e4090ba4a648f9ec4f037a66c1e
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"
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/MCSubtargetInfo.h"
20#include "llvm/Target/TargetRegistry.h"
21
22#define GET_INSTRINFO_MC_DESC
23#include "PPCGenInstrInfo.inc"
24
25#define GET_SUBTARGETINFO_MC_DESC
26#include "PPCGenSubtargetInfo.inc"
27
28#define GET_REGINFO_MC_DESC
29#include "PPCGenRegisterInfo.inc"
30
31using namespace llvm;
32
33static MCInstrInfo *createPPCMCInstrInfo() {
34  MCInstrInfo *X = new MCInstrInfo();
35  InitPPCMCInstrInfo(X);
36  return X;
37}
38
39static MCRegisterInfo *createPPCMCRegisterInfo(StringRef TT) {
40  Triple TheTriple(TT);
41  bool isPPC64 = (TheTriple.getArch() == Triple::ppc64);
42  unsigned Flavour = isPPC64 ? 0 : 1;
43  unsigned RA = isPPC64 ? PPC::LR8 : PPC::LR;
44
45  MCRegisterInfo *X = new MCRegisterInfo();
46  InitPPCMCRegisterInfo(X, RA, Flavour, Flavour);
47  return X;
48}
49
50static MCSubtargetInfo *createPPCMCSubtargetInfo(StringRef TT, StringRef CPU,
51                                                 StringRef FS) {
52  MCSubtargetInfo *X = new MCSubtargetInfo();
53  InitPPCMCSubtargetInfo(X, TT, CPU, FS);
54  return X;
55}
56
57static MCAsmInfo *createPPCMCAsmInfo(const Target &T, StringRef TT) {
58  Triple TheTriple(TT);
59  bool isPPC64 = TheTriple.getArch() == Triple::ppc64;
60
61  MCAsmInfo *MAI;
62  if (TheTriple.isOSDarwin())
63    MAI = new PPCMCAsmInfoDarwin(isPPC64);
64  else
65    MAI = new PPCLinuxMCAsmInfo(isPPC64);
66
67  // Initial state of the frame pointer is R1.
68  MachineLocation Dst(MachineLocation::VirtualFP);
69  MachineLocation Src(PPC::R1, 0);
70  MAI->addInitialFrameState(0, Dst, Src);
71
72  return MAI;
73}
74
75static MCCodeGenInfo *createPPCMCCodeGenInfo(StringRef TT, Reloc::Model RM,
76                                             CodeModel::Model CM) {
77  MCCodeGenInfo *X = new MCCodeGenInfo();
78
79  if (RM == Reloc::Default) {
80    Triple T(TT);
81    if (T.isOSDarwin())
82      RM = Reloc::DynamicNoPIC;
83    else
84      RM = Reloc::Static;
85  }
86  X->InitMCCodeGenInfo(RM, CM);
87  return X;
88}
89
90extern "C" void LLVMInitializePowerPCTargetMC() {
91  // Register the MC asm info.
92  RegisterMCAsmInfoFn C(ThePPC32Target, createPPCMCAsmInfo);
93  RegisterMCAsmInfoFn D(ThePPC64Target, createPPCMCAsmInfo);
94
95  // Register the MC codegen info.
96  TargetRegistry::RegisterMCCodeGenInfo(ThePPC32Target, createPPCMCCodeGenInfo);
97  TargetRegistry::RegisterMCCodeGenInfo(ThePPC64Target, createPPCMCCodeGenInfo);
98
99  // Register the MC instruction info.
100  TargetRegistry::RegisterMCInstrInfo(ThePPC32Target, createPPCMCInstrInfo);
101  TargetRegistry::RegisterMCInstrInfo(ThePPC64Target, createPPCMCInstrInfo);
102
103  // Register the MC register info.
104  TargetRegistry::RegisterMCRegInfo(ThePPC32Target, createPPCMCRegisterInfo);
105  TargetRegistry::RegisterMCRegInfo(ThePPC64Target, createPPCMCRegisterInfo);
106
107  // Register the MC subtarget info.
108  TargetRegistry::RegisterMCSubtargetInfo(ThePPC32Target,
109                                          createPPCMCSubtargetInfo);
110  TargetRegistry::RegisterMCSubtargetInfo(ThePPC64Target,
111                                          createPPCMCSubtargetInfo);
112}
113