LLVM API Documentation

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
MipsMCTargetDesc.cpp
Go to the documentation of this file.
1 //===-- MipsMCTargetDesc.cpp - Mips 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 Mips specific target descriptions.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #include "MipsMCTargetDesc.h"
16 #include "MipsMCAsmInfo.h"
17 #include "MipsTargetStreamer.h"
18 #include "llvm/MC/MCCodeGenInfo.h"
19 #include "llvm/MC/MCELF.h"
20 #include "llvm/MC/MCELFStreamer.h"
21 #include "llvm/MC/MCInstrInfo.h"
22 #include "llvm/MC/MCRegisterInfo.h"
24 #include "llvm/MC/MCSymbol.h"
30 
31 #define GET_INSTRINFO_MC_DESC
32 #include "MipsGenInstrInfo.inc"
33 
34 #define GET_SUBTARGETINFO_MC_DESC
35 #include "MipsGenSubtargetInfo.inc"
36 
37 #define GET_REGINFO_MC_DESC
38 #include "MipsGenRegisterInfo.inc"
39 
40 using namespace llvm;
41 
42 static std::string ParseMipsTriple(StringRef TT, StringRef CPU) {
43  std::string MipsArchFeature;
44  size_t DashPosition = 0;
45  StringRef TheTriple;
46 
47  // Let's see if there is a dash, like mips-unknown-linux.
48  DashPosition = TT.find('-');
49 
50  if (DashPosition == StringRef::npos) {
51  // No dash, we check the string size.
52  TheTriple = TT.substr(0);
53  } else {
54  // We are only interested in substring before dash.
55  TheTriple = TT.substr(0,DashPosition);
56  }
57 
58  if (TheTriple == "mips" || TheTriple == "mipsel") {
59  if (CPU.empty() || CPU == "mips32") {
60  MipsArchFeature = "+mips32";
61  } else if (CPU == "mips32r2") {
62  MipsArchFeature = "+mips32r2";
63  }
64  } else {
65  if (CPU.empty() || CPU == "mips64") {
66  MipsArchFeature = "+mips64";
67  } else if (CPU == "mips64r2") {
68  MipsArchFeature = "+mips64r2";
69  }
70  }
71  return MipsArchFeature;
72 }
73 
75  MCInstrInfo *X = new MCInstrInfo();
76  InitMipsMCInstrInfo(X);
77  return X;
78 }
79 
82  InitMipsMCRegisterInfo(X, Mips::RA);
83  return X;
84 }
85 
87  StringRef FS) {
88  std::string ArchFS = ParseMipsTriple(TT,CPU);
89  if (!FS.empty()) {
90  if (!ArchFS.empty())
91  ArchFS = ArchFS + "," + FS.str();
92  else
93  ArchFS = FS;
94  }
96  InitMipsMCSubtargetInfo(X, TT, CPU, ArchFS);
97  return X;
98 }
99 
101  MCAsmInfo *MAI = new MipsMCAsmInfo(TT);
102 
103  unsigned SP = MRI.getDwarfRegNum(Mips::SP, true);
105  MAI->addInitialFrameState(Inst);
106 
107  return MAI;
108 }
109 
111  CodeModel::Model CM,
112  CodeGenOpt::Level OL) {
113  MCCodeGenInfo *X = new MCCodeGenInfo();
114  if (CM == CodeModel::JITDefault)
115  RM = Reloc::Static;
116  else if (RM == Reloc::Default)
117  RM = Reloc::PIC_;
118  X->InitMCCodeGenInfo(RM, CM, OL);
119  return X;
120 }
121 
123  unsigned SyntaxVariant,
124  const MCAsmInfo &MAI,
125  const MCInstrInfo &MII,
126  const MCRegisterInfo &MRI,
127  const MCSubtargetInfo &STI) {
128  return new MipsInstPrinter(MAI, MII, MRI);
129 }
130 
132  MCContext &Context, MCAsmBackend &MAB,
133  raw_ostream &OS, MCCodeEmitter *Emitter,
134  bool RelaxAll, bool NoExecStack) {
136  return createELFStreamer(Context, S, MAB, OS, Emitter, RelaxAll, NoExecStack);
137 }
138 
139 static MCStreamer *
141  bool isVerboseAsm, bool useLoc, bool useCFI,
142  bool useDwarfDirectory, MCInstPrinter *InstPrint,
143  MCCodeEmitter *CE, MCAsmBackend *TAB, bool ShowInst) {
145 
146  return llvm::createAsmStreamer(Ctx, S, OS, isVerboseAsm, useLoc, useCFI,
147  useDwarfDirectory, InstPrint, CE, TAB,
148  ShowInst);
149 }
150 
151 extern "C" void LLVMInitializeMipsTargetMC() {
152  // Register the MC asm info.
157 
158  // Register the MC codegen info.
167 
168  // Register the MC instruction info.
174 
175  // Register the MC register info.
181 
182  // Register the MC Code Emitter
191 
192  // Register the object streamer.
198 
199  // Register the asm streamer.
204 
205  // Register the asm backend.
214 
215  // Register the MC subtarget info.
224 
225  // Register the MCInstPrinter.
234 }
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...
MCStreamer * createMCAsmStreamer(MCContext &Ctx, formatted_raw_ostream &OS, bool isVerboseAsm, bool useLoc, bool useCFI, bool useDwarfDirectory, MCInstPrinter *InstPrint, MCCodeEmitter *CE, MCAsmBackend *TAB, bool ShowInst)
size_t find(char C, size_t From=0) const
Definition: StringRef.h:233
StringRef substr(size_t Start, size_t N=npos) const
Definition: StringRef.h:392
std::string str() const
str - Get the contents as an std::string.
Definition: StringRef.h:181
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)
MCCodeEmitter * createMipsMCCodeEmitterEL(const MCInstrInfo &MCII, const MCRegisterInfo &MRI, const MCSubtargetInfo &STI, MCContext &Ctx)
static MCSubtargetInfo * createMipsMCSubtargetInfo(StringRef TT, StringRef CPU, StringRef FS)
MCAsmBackend * createMipsAsmBackendEB64(const Target &T, const MCRegisterInfo &MRI, StringRef TT, StringRef CPU)
void LLVMInitializeMipsTargetMC()
Target TheMips64elTarget
void addInitialFrameState(const MCCFIInstruction &Inst)
Definition: MCAsmInfo.h:535
static MCStreamer * createMCStreamer(const Target &T, StringRef TT, MCContext &Context, MCAsmBackend &MAB, raw_ostream &OS, MCCodeEmitter *Emitter, bool RelaxAll, bool NoExecStack)
void InitMCCodeGenInfo(Reloc::Model RM=Reloc::Default, CodeModel::Model CM=CodeModel::Default, CodeGenOpt::Level OL=CodeGenOpt::Default)
Target TheMips64Target
static MCRegisterInfo * createMipsMCRegisterInfo(StringRef TT)
static void RegisterMCAsmBackend(Target &T, Target::MCAsmBackendCtorTy Fn)
static MCInstrInfo * createMipsMCInstrInfo()
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)
const MCInstrInfo & MII
MCCodeEmitter - Generic instruction encoding interface.
Definition: MCCodeEmitter.h:22
static void RegisterAsmStreamer(Target &T, Target::AsmStreamerCtorTy Fn)
static MCAsmInfo * createMipsMCAsmInfo(const MCRegisterInfo &MRI, StringRef TT)
static void RegisterMCCodeGenInfo(Target &T, Target::MCCodeGenInfoCtorFnTy Fn)
static void RegisterMCSubtargetInfo(Target &T, Target::MCSubtargetInfoCtorFnTy Fn)
static void RegisterMCCodeEmitter(Target &T, Target::MCCodeEmitterCtorTy Fn)
MCAsmBackend * createMipsAsmBackendEB32(const Target &T, const MCRegisterInfo &MRI, StringRef TT, StringRef CPU)
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 void RegisterMCRegInfo(Target &T, Target::MCRegInfoCtorFnTy Fn)
static MCInstPrinter * createMipsMCInstPrinter(const Target &T, unsigned SyntaxVariant, const MCAsmInfo &MAI, const MCInstrInfo &MII, const MCRegisterInfo &MRI, const MCSubtargetInfo &STI)
MCAsmBackend * createMipsAsmBackendEL64(const Target &T, const MCRegisterInfo &MRI, StringRef TT, StringRef CPU)
MCAsmBackend * createMipsAsmBackendEL32(const Target &T, const MCRegisterInfo &MRI, StringRef TT, StringRef CPU)
static const size_t npos
Definition: StringRef.h:45
static void RegisterMCInstrInfo(Target &T, Target::MCInstrInfoCtorFnTy Fn)
Target TheMipselTarget
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"))
MCCodeEmitter * createMipsMCCodeEmitterEB(const MCInstrInfo &MCII, const MCRegisterInfo &MRI, const MCSubtargetInfo &STI, MCContext &Ctx)
static std::string ParseMipsTriple(StringRef TT, StringRef CPU)
const MCRegisterInfo & MRI
static MCCodeGenInfo * createMipsMCCodeGenInfo(StringRef TT, Reloc::Model RM, CodeModel::Model CM, CodeGenOpt::Level OL)
static GCMetadataPrinterRegistry::Add< OcamlGCMetadataPrinter > Y("ocaml","ocaml 3.10-compatible collector")
static RegisterPass< NVPTXAllocaHoisting > X("alloca-hoisting","Hoisting alloca instructions in non-entry ""blocks to the entry block")
Target TheMipsTarget
bool empty() const
empty - Check if the string is empty.
Definition: StringRef.h:110