LLVM API Documentation

AArch64MCTargetDesc.cpp
Go to the documentation of this file.
00001 //===-- AArch64MCTargetDesc.cpp - AArch64 Target Descriptions ---*- C++ -*-===//
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 AArch64 specific target descriptions.
00011 //
00012 //===----------------------------------------------------------------------===//
00013 
00014 #include "AArch64MCTargetDesc.h"
00015 #include "AArch64ELFStreamer.h"
00016 #include "AArch64MCAsmInfo.h"
00017 #include "InstPrinter/AArch64InstPrinter.h"
00018 #include "llvm/MC/MCCodeGenInfo.h"
00019 #include "llvm/MC/MCInstrInfo.h"
00020 #include "llvm/MC/MCRegisterInfo.h"
00021 #include "llvm/MC/MCStreamer.h"
00022 #include "llvm/MC/MCSubtargetInfo.h"
00023 #include "llvm/Support/ErrorHandling.h"
00024 #include "llvm/Support/TargetRegistry.h"
00025 
00026 using namespace llvm;
00027 
00028 #define GET_INSTRINFO_MC_DESC
00029 #include "AArch64GenInstrInfo.inc"
00030 
00031 #define GET_SUBTARGETINFO_MC_DESC
00032 #include "AArch64GenSubtargetInfo.inc"
00033 
00034 #define GET_REGINFO_MC_DESC
00035 #include "AArch64GenRegisterInfo.inc"
00036 
00037 static MCInstrInfo *createAArch64MCInstrInfo() {
00038   MCInstrInfo *X = new MCInstrInfo();
00039   InitAArch64MCInstrInfo(X);
00040   return X;
00041 }
00042 
00043 static MCSubtargetInfo *
00044 createAArch64MCSubtargetInfo(StringRef TT, StringRef CPU, StringRef FS) {
00045   MCSubtargetInfo *X = new MCSubtargetInfo();
00046 
00047   if (CPU.empty())
00048     CPU = "generic";
00049 
00050   InitAArch64MCSubtargetInfo(X, TT, CPU, FS);
00051   return X;
00052 }
00053 
00054 static MCRegisterInfo *createAArch64MCRegisterInfo(StringRef Triple) {
00055   MCRegisterInfo *X = new MCRegisterInfo();
00056   InitAArch64MCRegisterInfo(X, AArch64::LR);
00057   return X;
00058 }
00059 
00060 static MCAsmInfo *createAArch64MCAsmInfo(const MCRegisterInfo &MRI,
00061                                          StringRef TT) {
00062   Triple TheTriple(TT);
00063 
00064   MCAsmInfo *MAI;
00065   if (TheTriple.isOSDarwin())
00066     MAI = new AArch64MCAsmInfoDarwin();
00067   else {
00068     assert(TheTriple.isOSBinFormatELF() && "Only expect Darwin or ELF");
00069     MAI = new AArch64MCAsmInfoELF(TT);
00070   }
00071 
00072   // Initial state of the frame pointer is SP.
00073   unsigned Reg = MRI.getDwarfRegNum(AArch64::SP, true);
00074   MCCFIInstruction Inst = MCCFIInstruction::createDefCfa(nullptr, Reg, 0);
00075   MAI->addInitialFrameState(Inst);
00076 
00077   return MAI;
00078 }
00079 
00080 static MCCodeGenInfo *createAArch64MCCodeGenInfo(StringRef TT, Reloc::Model RM,
00081                                                  CodeModel::Model CM,
00082                                                  CodeGenOpt::Level OL) {
00083   Triple TheTriple(TT);
00084   assert((TheTriple.isOSBinFormatELF() || TheTriple.isOSBinFormatMachO()) &&
00085          "Only expect Darwin and ELF targets");
00086 
00087   if (CM == CodeModel::Default)
00088     CM = CodeModel::Small;
00089   // The default MCJIT memory managers make no guarantees about where they can
00090   // find an executable page; JITed code needs to be able to refer to globals
00091   // no matter how far away they are.
00092   else if (CM == CodeModel::JITDefault)
00093     CM = CodeModel::Large;
00094   else if (CM != CodeModel::Small && CM != CodeModel::Large)
00095     report_fatal_error(
00096         "Only small and large code models are allowed on AArch64");
00097 
00098   // AArch64 Darwin is always PIC.
00099   if (TheTriple.isOSDarwin())
00100     RM = Reloc::PIC_;
00101   // On ELF platforms the default static relocation model has a smart enough
00102   // linker to cope with referencing external symbols defined in a shared
00103   // library. Hence DynamicNoPIC doesn't need to be promoted to PIC.
00104   else if (RM == Reloc::Default || RM == Reloc::DynamicNoPIC)
00105     RM = Reloc::Static;
00106 
00107   MCCodeGenInfo *X = new MCCodeGenInfo();
00108   X->InitMCCodeGenInfo(RM, CM, OL);
00109   return X;
00110 }
00111 
00112 static MCInstPrinter *createAArch64MCInstPrinter(const Target &T,
00113                                                  unsigned SyntaxVariant,
00114                                                  const MCAsmInfo &MAI,
00115                                                  const MCInstrInfo &MII,
00116                                                  const MCRegisterInfo &MRI,
00117                                                  const MCSubtargetInfo &STI) {
00118   if (SyntaxVariant == 0)
00119     return new AArch64InstPrinter(MAI, MII, MRI, STI);
00120   if (SyntaxVariant == 1)
00121     return new AArch64AppleInstPrinter(MAI, MII, MRI, STI);
00122 
00123   return nullptr;
00124 }
00125 
00126 static MCStreamer *createMCStreamer(const Target &T, StringRef TT,
00127                                     MCContext &Ctx, MCAsmBackend &TAB,
00128                                     raw_ostream &OS, MCCodeEmitter *Emitter,
00129                                     const MCSubtargetInfo &STI, bool RelaxAll,
00130                                     bool NoExecStack) {
00131   Triple TheTriple(TT);
00132 
00133   if (TheTriple.isOSDarwin())
00134     return createMachOStreamer(Ctx, TAB, OS, Emitter, RelaxAll,
00135                                /*LabelSections*/ true);
00136 
00137   return createAArch64ELFStreamer(Ctx, TAB, OS, Emitter, RelaxAll, NoExecStack);
00138 }
00139 
00140 // Force static initialization.
00141 extern "C" void LLVMInitializeAArch64TargetMC() {
00142   // Register the MC asm info.
00143   RegisterMCAsmInfoFn X(TheAArch64leTarget, createAArch64MCAsmInfo);
00144   RegisterMCAsmInfoFn Y(TheAArch64beTarget, createAArch64MCAsmInfo);
00145   RegisterMCAsmInfoFn Z(TheARM64Target, createAArch64MCAsmInfo);
00146 
00147   // Register the MC codegen info.
00148   TargetRegistry::RegisterMCCodeGenInfo(TheAArch64leTarget,
00149                                         createAArch64MCCodeGenInfo);
00150   TargetRegistry::RegisterMCCodeGenInfo(TheAArch64beTarget,
00151                                         createAArch64MCCodeGenInfo);
00152   TargetRegistry::RegisterMCCodeGenInfo(TheARM64Target,
00153                                         createAArch64MCCodeGenInfo);
00154 
00155   // Register the MC instruction info.
00156   TargetRegistry::RegisterMCInstrInfo(TheAArch64leTarget,
00157                                       createAArch64MCInstrInfo);
00158   TargetRegistry::RegisterMCInstrInfo(TheAArch64beTarget,
00159                                       createAArch64MCInstrInfo);
00160   TargetRegistry::RegisterMCInstrInfo(TheARM64Target,
00161                                       createAArch64MCInstrInfo);
00162 
00163   // Register the MC register info.
00164   TargetRegistry::RegisterMCRegInfo(TheAArch64leTarget,
00165                                     createAArch64MCRegisterInfo);
00166   TargetRegistry::RegisterMCRegInfo(TheAArch64beTarget,
00167                                     createAArch64MCRegisterInfo);
00168   TargetRegistry::RegisterMCRegInfo(TheARM64Target,
00169                                     createAArch64MCRegisterInfo);
00170 
00171   // Register the MC subtarget info.
00172   TargetRegistry::RegisterMCSubtargetInfo(TheAArch64leTarget,
00173                                           createAArch64MCSubtargetInfo);
00174   TargetRegistry::RegisterMCSubtargetInfo(TheAArch64beTarget,
00175                                           createAArch64MCSubtargetInfo);
00176   TargetRegistry::RegisterMCSubtargetInfo(TheARM64Target,
00177                                           createAArch64MCSubtargetInfo);
00178 
00179   // Register the asm backend.
00180   TargetRegistry::RegisterMCAsmBackend(TheAArch64leTarget,
00181                                        createAArch64leAsmBackend);
00182   TargetRegistry::RegisterMCAsmBackend(TheAArch64beTarget,
00183                                        createAArch64beAsmBackend);
00184   TargetRegistry::RegisterMCAsmBackend(TheARM64Target,
00185                                        createAArch64leAsmBackend);
00186 
00187   // Register the MC Code Emitter
00188   TargetRegistry::RegisterMCCodeEmitter(TheAArch64leTarget,
00189                                         createAArch64MCCodeEmitter);
00190   TargetRegistry::RegisterMCCodeEmitter(TheAArch64beTarget,
00191                                         createAArch64MCCodeEmitter);
00192   TargetRegistry::RegisterMCCodeEmitter(TheARM64Target,
00193                                         createAArch64MCCodeEmitter);
00194 
00195   // Register the object streamer.
00196   TargetRegistry::RegisterMCObjectStreamer(TheAArch64leTarget,
00197                                            createMCStreamer);
00198   TargetRegistry::RegisterMCObjectStreamer(TheAArch64beTarget,
00199                                            createMCStreamer);
00200   TargetRegistry::RegisterMCObjectStreamer(TheARM64Target, createMCStreamer);
00201 
00202   // Register the MCInstPrinter.
00203   TargetRegistry::RegisterMCInstPrinter(TheAArch64leTarget,
00204                                         createAArch64MCInstPrinter);
00205   TargetRegistry::RegisterMCInstPrinter(TheAArch64beTarget,
00206                                         createAArch64MCInstPrinter);
00207   TargetRegistry::RegisterMCInstPrinter(TheARM64Target,
00208                                         createAArch64MCInstPrinter);
00209 }