LLVM API Documentation

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PPCMCTargetDesc.cpp
Go to the documentation of this file.
1 //===-- PPCMCTargetDesc.cpp - PowerPC Target Descriptions -----------------===//
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"
16 #include "PPCMCAsmInfo.h"
17 #include "PPCTargetStreamer.h"
18 #include "llvm/MC/MCCodeGenInfo.h"
19 #include "llvm/MC/MCInstrInfo.h"
20 #include "llvm/MC/MCRegisterInfo.h"
21 #include "llvm/MC/MCStreamer.h"
23 #include "llvm/MC/MCSymbol.h"
28 
29 #define GET_INSTRINFO_MC_DESC
30 #include "PPCGenInstrInfo.inc"
31 
32 #define GET_SUBTARGETINFO_MC_DESC
33 #include "PPCGenSubtargetInfo.inc"
34 
35 #define GET_REGINFO_MC_DESC
36 #include "PPCGenRegisterInfo.inc"
37 
38 using namespace llvm;
39 
40 // Pin the vtable to this file.
42 
44  MCInstrInfo *X = new MCInstrInfo();
45  InitPPCMCInstrInfo(X);
46  return X;
47 }
48 
50  Triple TheTriple(TT);
51  bool isPPC64 = (TheTriple.getArch() == Triple::ppc64 ||
52  TheTriple.getArch() == Triple::ppc64le);
53  unsigned Flavour = isPPC64 ? 0 : 1;
54  unsigned RA = isPPC64 ? PPC::LR8 : PPC::LR;
55 
57  InitPPCMCRegisterInfo(X, RA, Flavour, Flavour);
58  return X;
59 }
60 
62  StringRef FS) {
64  InitPPCMCSubtargetInfo(X, TT, CPU, FS);
65  return X;
66 }
67 
69  Triple TheTriple(TT);
70  bool isPPC64 = (TheTriple.getArch() == Triple::ppc64 ||
71  TheTriple.getArch() == Triple::ppc64le);
72 
73  MCAsmInfo *MAI;
74  if (TheTriple.isOSDarwin())
75  MAI = new PPCMCAsmInfoDarwin(isPPC64);
76  else
77  MAI = new PPCLinuxMCAsmInfo(isPPC64);
78 
79  // Initial state of the frame pointer is R1.
80  unsigned Reg = isPPC64 ? PPC::X1 : PPC::R1;
81  MCCFIInstruction Inst =
82  MCCFIInstruction::createDefCfa(0, MRI.getDwarfRegNum(Reg, true), 0);
83  MAI->addInitialFrameState(Inst);
84 
85  return MAI;
86 }
87 
90  CodeGenOpt::Level OL) {
91  MCCodeGenInfo *X = new MCCodeGenInfo();
92 
93  if (RM == Reloc::Default) {
94  Triple T(TT);
95  if (T.isOSDarwin())
97  else
98  RM = Reloc::Static;
99  }
100  if (CM == CodeModel::Default) {
101  Triple T(TT);
102  if (!T.isOSDarwin() &&
103  (T.getArch() == Triple::ppc64 || T.getArch() == Triple::ppc64le))
104  CM = CodeModel::Medium;
105  }
106  X->InitMCCodeGenInfo(RM, CM, OL);
107  return X;
108 }
109 
110 namespace {
111 class PPCTargetAsmStreamer : public PPCTargetStreamer {
113 
114 public:
115  PPCTargetAsmStreamer(formatted_raw_ostream &OS) : OS(OS) {}
116  virtual void emitTCEntry(const MCSymbol &S) {
117  OS << "\t.tc ";
118  OS << S.getName();
119  OS << "[TC],";
120  OS << S.getName();
121  OS << '\n';
122  }
123 };
124 
125 class PPCTargetELFStreamer : public PPCTargetStreamer {
126  virtual void emitTCEntry(const MCSymbol &S) {
127  // Creates a R_PPC64_TOC relocation
128  Streamer->EmitSymbolValue(&S, 8);
129  }
130 };
131 }
132 
133 // This is duplicated code. Refactor this.
135  MCContext &Ctx, MCAsmBackend &MAB,
136  raw_ostream &OS,
137  MCCodeEmitter *Emitter,
138  bool RelaxAll,
139  bool NoExecStack) {
140  if (Triple(TT).isOSDarwin())
141  return createMachOStreamer(Ctx, MAB, OS, Emitter, RelaxAll);
142 
143  PPCTargetStreamer *S = new PPCTargetELFStreamer();
144  return createELFStreamer(Ctx, S, MAB, OS, Emitter, RelaxAll, NoExecStack);
145 }
146 
147 static MCStreamer *
149  bool isVerboseAsm, bool useLoc, bool useCFI,
150  bool useDwarfDirectory, MCInstPrinter *InstPrint,
151  MCCodeEmitter *CE, MCAsmBackend *TAB, bool ShowInst) {
152  PPCTargetStreamer *S = new PPCTargetAsmStreamer(OS);
153 
154  return llvm::createAsmStreamer(Ctx, S, OS, isVerboseAsm, useLoc, useCFI,
155  useDwarfDirectory, InstPrint, CE, TAB,
156  ShowInst);
157 }
158 
160  unsigned SyntaxVariant,
161  const MCAsmInfo &MAI,
162  const MCInstrInfo &MII,
163  const MCRegisterInfo &MRI,
164  const MCSubtargetInfo &STI) {
165  bool isDarwin = Triple(STI.getTargetTriple()).isOSDarwin();
166  return new PPCInstPrinter(MAI, MII, MRI, isDarwin);
167 }
168 
169 extern "C" void LLVMInitializePowerPCTargetMC() {
170  // Register the MC asm info.
174 
175  // Register the MC codegen info.
180 
181  // Register the MC instruction info.
186 
187  // Register the MC register info.
191 
192  // Register the MC subtarget info.
199 
200  // Register the MC Code Emitter
205 
206  // Register the asm backend.
210 
211  // Register the object streamer.
215 
216  // Register the asm streamer.
220 
221  // Register the MCInstPrinter.
226 }
int getDwarfRegNum(unsigned RegNum, bool isEH) const
Map a target register to an equivalent dwarf register number. Returns -1 if there is no equivalent va...
static MCCodeGenInfo * createPPCMCCodeGenInfo(StringRef TT, Reloc::Model RM, CodeModel::Model CM, CodeGenOpt::Level OL)
MCStreamer * createMCAsmStreamer(MCContext &Ctx, formatted_raw_ostream &OS, bool isVerboseAsm, bool useLoc, bool useCFI, bool useDwarfDirectory, MCInstPrinter *InstPrint, MCCodeEmitter *CE, MCAsmBackend *TAB, bool ShowInst)
static void RegisterMCInstPrinter(Target &T, Target::MCInstPrinterCtorTy Fn)
MCStreamer * createELFStreamer(MCContext &Ctx, MCTargetStreamer *TargetStreamer, MCAsmBackend &TAB, raw_ostream &OS, MCCodeEmitter *CE, bool RelaxAll, bool NoExecStack)
MCStreamer * createMachOStreamer(MCContext &Ctx, MCAsmBackend &TAB, raw_ostream &OS, MCCodeEmitter *CE, bool RelaxAll=false)
MCCodeEmitter * createPPCMCCodeEmitter(const MCInstrInfo &MCII, const MCRegisterInfo &MRI, const MCSubtargetInfo &STI, MCContext &Ctx)
void addInitialFrameState(const MCCFIInstruction &Inst)
Definition: MCAsmInfo.h:535
#define T
void InitMCCodeGenInfo(Reloc::Model RM=Reloc::Default, CodeModel::Model CM=CodeModel::Default, CodeGenOpt::Level OL=CodeGenOpt::Default)
ArchType getArch() const
getArch - Get the parsed architecture type of this triple.
Definition: Triple.h:172
void LLVMInitializePowerPCTargetMC()
static MCRegisterInfo * createPPCMCRegisterInfo(StringRef TT)
static void RegisterMCAsmBackend(Target &T, Target::MCAsmBackendCtorTy Fn)
static MCStreamer * createMCStreamer(const Target &T, StringRef TT, MCContext &Ctx, MCAsmBackend &MAB, raw_ostream &OS, MCCodeEmitter *Emitter, bool RelaxAll, bool NoExecStack)
static MCCFIInstruction createDefCfa(MCSymbol *L, unsigned Register, int Offset)
.cfi_def_cfa defines a rule for computing CFA as: take address from Register and add Offset to it...
Definition: MCDwarf.h:321
static void RegisterMCObjectStreamer(Target &T, Target::MCObjectStreamerCtorTy Fn)
MCAsmBackend * createPPCAsmBackend(const Target &T, const MCRegisterInfo &MRI, StringRef TT, StringRef CPU)
const MCInstrInfo & MII
MCCodeEmitter - Generic instruction encoding interface.
Definition: MCCodeEmitter.h:22
static void RegisterAsmStreamer(Target &T, Target::AsmStreamerCtorTy Fn)
static void RegisterMCCodeGenInfo(Target &T, Target::MCCodeGenInfoCtorFnTy Fn)
StringRef getTargetTriple() const
getTargetTriple - Return the target triple string.
static MCInstPrinter * createPPCMCInstPrinter(const Target &T, unsigned SyntaxVariant, const MCAsmInfo &MAI, const MCInstrInfo &MII, const MCRegisterInfo &MRI, const MCSubtargetInfo &STI)
static void RegisterMCSubtargetInfo(Target &T, Target::MCSubtargetInfoCtorFnTy Fn)
static MCInstrInfo * createPPCMCInstrInfo()
bool isOSDarwin() const
isOSDarwin - Is this a "Darwin" OS (OS X or iOS).
Definition: Triple.h:313
static void RegisterMCCodeEmitter(Target &T, Target::MCCodeEmitterCtorTy Fn)
Target ThePPC32Target
Target ThePPC64LETarget
MCStreamer * createAsmStreamer(MCContext &Ctx, MCTargetStreamer *TargetStreamer, formatted_raw_ostream &OS, bool isVerboseAsm, bool useLoc, bool useCFI, bool useDwarfDirectory, MCInstPrinter *InstPrint=0, MCCodeEmitter *CE=0, MCAsmBackend *TAB=0, bool ShowInst=false)
static MCAsmInfo * createPPCMCAsmInfo(const MCRegisterInfo &MRI, StringRef TT)
static void RegisterMCRegInfo(Target &T, Target::MCRegInfoCtorFnTy Fn)
StringRef getName() const
getName - Get the symbol name.
Definition: MCSymbol.h:70
static void RegisterMCInstrInfo(Target &T, Target::MCInstrInfoCtorFnTy Fn)
MCAsmBackend - Generic interface to target specific assembler backends.
Definition: MCAsmBackend.h:34
cl::opt< bool > RelaxAll("mc-relax-all", cl::desc("When used with filetype=obj, ""relax all fixups in the emitted object file"))
Target ThePPC64Target
const MCRegisterInfo & MRI
static RegisterPass< NVPTXAllocaHoisting > X("alloca-hoisting","Hoisting alloca instructions in non-entry ""blocks to the entry block")
static MCSubtargetInfo * createPPCMCSubtargetInfo(StringRef TT, StringRef CPU, StringRef FS)