LLVM API Documentation

SparcMCTargetDesc.cpp
Go to the documentation of this file.
00001 //===-- SparcMCTargetDesc.cpp - Sparc Target Descriptions -----------------===//
00002 //
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file is distributed under the University of Illinois Open Source
00006 // License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 //
00010 // This file provides Sparc specific target descriptions.
00011 //
00012 //===----------------------------------------------------------------------===//
00013 
00014 #include "SparcMCTargetDesc.h"
00015 #include "InstPrinter/SparcInstPrinter.h"
00016 #include "SparcMCAsmInfo.h"
00017 #include "SparcTargetStreamer.h"
00018 #include "llvm/MC/MCCodeGenInfo.h"
00019 #include "llvm/MC/MCInstrInfo.h"
00020 #include "llvm/MC/MCRegisterInfo.h"
00021 #include "llvm/MC/MCSubtargetInfo.h"
00022 #include "llvm/Support/ErrorHandling.h"
00023 #include "llvm/Support/TargetRegistry.h"
00024 
00025 using namespace llvm;
00026 
00027 #define GET_INSTRINFO_MC_DESC
00028 #include "SparcGenInstrInfo.inc"
00029 
00030 #define GET_SUBTARGETINFO_MC_DESC
00031 #include "SparcGenSubtargetInfo.inc"
00032 
00033 #define GET_REGINFO_MC_DESC
00034 #include "SparcGenRegisterInfo.inc"
00035 
00036 static MCAsmInfo *createSparcMCAsmInfo(const MCRegisterInfo &MRI,
00037                                        StringRef TT) {
00038   MCAsmInfo *MAI = new SparcELFMCAsmInfo(TT);
00039   unsigned Reg = MRI.getDwarfRegNum(SP::O6, true);
00040   MCCFIInstruction Inst = MCCFIInstruction::createDefCfa(nullptr, Reg, 0);
00041   MAI->addInitialFrameState(Inst);
00042   return MAI;
00043 }
00044 
00045 static MCAsmInfo *createSparcV9MCAsmInfo(const MCRegisterInfo &MRI,
00046                                        StringRef TT) {
00047   MCAsmInfo *MAI = new SparcELFMCAsmInfo(TT);
00048   unsigned Reg = MRI.getDwarfRegNum(SP::O6, true);
00049   MCCFIInstruction Inst = MCCFIInstruction::createDefCfa(nullptr, Reg, 2047);
00050   MAI->addInitialFrameState(Inst);
00051   return MAI;
00052 }
00053 
00054 static MCInstrInfo *createSparcMCInstrInfo() {
00055   MCInstrInfo *X = new MCInstrInfo();
00056   InitSparcMCInstrInfo(X);
00057   return X;
00058 }
00059 
00060 static MCRegisterInfo *createSparcMCRegisterInfo(StringRef TT) {
00061   MCRegisterInfo *X = new MCRegisterInfo();
00062   InitSparcMCRegisterInfo(X, SP::O7);
00063   return X;
00064 }
00065 
00066 static MCSubtargetInfo *createSparcMCSubtargetInfo(StringRef TT, StringRef CPU,
00067                                                    StringRef FS) {
00068   MCSubtargetInfo *X = new MCSubtargetInfo();
00069   Triple TheTriple(TT);
00070   if (CPU.empty())
00071     CPU = (TheTriple.getArch() == Triple::sparcv9) ? "v9" : "v8";
00072   InitSparcMCSubtargetInfo(X, TT, CPU, FS);
00073   return X;
00074 }
00075 
00076 // Code models. Some only make sense for 64-bit code.
00077 //
00078 // SunCC  Reloc   CodeModel  Constraints
00079 // abs32  Static  Small      text+data+bss linked below 2^32 bytes
00080 // abs44  Static  Medium     text+data+bss linked below 2^44 bytes
00081 // abs64  Static  Large      text smaller than 2^31 bytes
00082 // pic13  PIC_    Small      GOT < 2^13 bytes
00083 // pic32  PIC_    Medium     GOT < 2^32 bytes
00084 //
00085 // All code models require that the text segment is smaller than 2GB.
00086 
00087 static MCCodeGenInfo *createSparcMCCodeGenInfo(StringRef TT, Reloc::Model RM,
00088                                                CodeModel::Model CM,
00089                                                CodeGenOpt::Level OL) {
00090   MCCodeGenInfo *X = new MCCodeGenInfo();
00091 
00092   // The default 32-bit code model is abs32/pic32 and the default 32-bit
00093   // code model for JIT is abs32.
00094   switch (CM) {
00095   default: break;
00096   case CodeModel::Default:
00097   case CodeModel::JITDefault: CM = CodeModel::Small; break;
00098   }
00099 
00100   X->InitMCCodeGenInfo(RM, CM, OL);
00101   return X;
00102 }
00103 
00104 static MCCodeGenInfo *createSparcV9MCCodeGenInfo(StringRef TT, Reloc::Model RM,
00105                                                  CodeModel::Model CM,
00106                                                  CodeGenOpt::Level OL) {
00107   MCCodeGenInfo *X = new MCCodeGenInfo();
00108 
00109   // The default 64-bit code model is abs44/pic32 and the default 64-bit
00110   // code model for JIT is abs64.
00111   switch (CM) {
00112   default:  break;
00113   case CodeModel::Default:
00114     CM = RM == Reloc::PIC_ ? CodeModel::Small : CodeModel::Medium;
00115     break;
00116   case CodeModel::JITDefault:
00117     CM = CodeModel::Large;
00118     break;
00119   }
00120 
00121   X->InitMCCodeGenInfo(RM, CM, OL);
00122   return X;
00123 }
00124 
00125 static MCStreamer *createMCStreamer(const Target &T, StringRef TT,
00126                                     MCContext &Context, MCAsmBackend &MAB,
00127                                     raw_ostream &OS, MCCodeEmitter *Emitter,
00128                                     const MCSubtargetInfo &STI, bool RelaxAll,
00129                                     bool NoExecStack) {
00130   MCStreamer *S =
00131       createELFStreamer(Context, MAB, OS, Emitter, RelaxAll, NoExecStack);
00132   new SparcTargetELFStreamer(*S);
00133   return S;
00134 }
00135 
00136 static MCStreamer *
00137 createMCAsmStreamer(MCContext &Ctx, formatted_raw_ostream &OS,
00138                     bool isVerboseAsm, bool useDwarfDirectory,
00139                     MCInstPrinter *InstPrint, MCCodeEmitter *CE,
00140                     MCAsmBackend *TAB, bool ShowInst) {
00141 
00142   MCStreamer *S = llvm::createAsmStreamer(
00143       Ctx, OS, isVerboseAsm, useDwarfDirectory, InstPrint, CE, TAB, ShowInst);
00144   new SparcTargetAsmStreamer(*S, OS);
00145   return S;
00146 }
00147 
00148 static MCInstPrinter *createSparcMCInstPrinter(const Target &T,
00149                                               unsigned SyntaxVariant,
00150                                               const MCAsmInfo &MAI,
00151                                               const MCInstrInfo &MII,
00152                                               const MCRegisterInfo &MRI,
00153                                               const MCSubtargetInfo &STI) {
00154   return new SparcInstPrinter(MAI, MII, MRI, STI);
00155 }
00156 
00157 extern "C" void LLVMInitializeSparcTargetMC() {
00158   // Register the MC asm info.
00159   RegisterMCAsmInfoFn X(TheSparcTarget, createSparcMCAsmInfo);
00160   RegisterMCAsmInfoFn Y(TheSparcV9Target, createSparcV9MCAsmInfo);
00161 
00162   // Register the MC codegen info.
00163   TargetRegistry::RegisterMCCodeGenInfo(TheSparcTarget,
00164                                        createSparcMCCodeGenInfo);
00165   TargetRegistry::RegisterMCCodeGenInfo(TheSparcV9Target,
00166                                        createSparcV9MCCodeGenInfo);
00167 
00168   // Register the MC instruction info.
00169   TargetRegistry::RegisterMCInstrInfo(TheSparcTarget, createSparcMCInstrInfo);
00170   TargetRegistry::RegisterMCInstrInfo(TheSparcV9Target, createSparcMCInstrInfo);
00171 
00172   // Register the MC register info.
00173   TargetRegistry::RegisterMCRegInfo(TheSparcTarget, createSparcMCRegisterInfo);
00174   TargetRegistry::RegisterMCRegInfo(TheSparcV9Target,
00175                                     createSparcMCRegisterInfo);
00176 
00177   // Register the MC subtarget info.
00178   TargetRegistry::RegisterMCSubtargetInfo(TheSparcTarget,
00179                                           createSparcMCSubtargetInfo);
00180   TargetRegistry::RegisterMCSubtargetInfo(TheSparcV9Target,
00181                                           createSparcMCSubtargetInfo);
00182 
00183   // Register the MC Code Emitter.
00184   TargetRegistry::RegisterMCCodeEmitter(TheSparcTarget,
00185                                         createSparcMCCodeEmitter);
00186   TargetRegistry::RegisterMCCodeEmitter(TheSparcV9Target,
00187                                         createSparcMCCodeEmitter);
00188 
00189   //Register the asm backend.
00190   TargetRegistry::RegisterMCAsmBackend(TheSparcTarget,
00191                                        createSparcAsmBackend);
00192   TargetRegistry::RegisterMCAsmBackend(TheSparcV9Target,
00193                                        createSparcAsmBackend);
00194 
00195   // Register the object streamer.
00196   TargetRegistry::RegisterMCObjectStreamer(TheSparcTarget,
00197                                            createMCStreamer);
00198   TargetRegistry::RegisterMCObjectStreamer(TheSparcV9Target,
00199                                            createMCStreamer);
00200 
00201   // Register the asm streamer.
00202   TargetRegistry::RegisterAsmStreamer(TheSparcTarget,
00203                                       createMCAsmStreamer);
00204   TargetRegistry::RegisterAsmStreamer(TheSparcV9Target,
00205                                       createMCAsmStreamer);
00206 
00207   // Register the MCInstPrinter
00208   TargetRegistry::RegisterMCInstPrinter(TheSparcTarget,
00209                                         createSparcMCInstPrinter);
00210   TargetRegistry::RegisterMCInstPrinter(TheSparcV9Target,
00211                                         createSparcMCInstPrinter);
00212 }