LLVM  4.0.0
AArch64MCTargetDesc.cpp
Go to the documentation of this file.
1 //===-- AArch64MCTargetDesc.cpp - AArch64 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 AArch64 specific target descriptions.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #include "AArch64MCTargetDesc.h"
15 #include "AArch64ELFStreamer.h"
16 #include "AArch64MCAsmInfo.h"
19 #include "llvm/MC/MCInstrInfo.h"
20 #include "llvm/MC/MCRegisterInfo.h"
21 #include "llvm/MC/MCStreamer.h"
25 
26 using namespace llvm;
27 
28 #define GET_INSTRINFO_MC_DESC
29 #include "AArch64GenInstrInfo.inc"
30 
31 #define GET_SUBTARGETINFO_MC_DESC
32 #include "AArch64GenSubtargetInfo.inc"
33 
34 #define GET_REGINFO_MC_DESC
35 #include "AArch64GenRegisterInfo.inc"
36 
38  MCInstrInfo *X = new MCInstrInfo();
39  InitAArch64MCInstrInfo(X);
40  return X;
41 }
42 
43 static MCSubtargetInfo *
45  if (CPU.empty())
46  CPU = "generic";
47 
48  return createAArch64MCSubtargetInfoImpl(TT, CPU, FS);
49 }
50 
53  InitAArch64MCRegisterInfo(X, AArch64::LR);
54  return X;
55 }
56 
58  const Triple &TheTriple) {
59  MCAsmInfo *MAI;
60  if (TheTriple.isOSBinFormatMachO())
61  MAI = new AArch64MCAsmInfoDarwin();
62  else {
63  assert(TheTriple.isOSBinFormatELF() && "Only expect Darwin or ELF");
64  MAI = new AArch64MCAsmInfoELF(TheTriple);
65  }
66 
67  // Initial state of the frame pointer is SP.
68  unsigned Reg = MRI.getDwarfRegNum(AArch64::SP, true);
69  MCCFIInstruction Inst = MCCFIInstruction::createDefCfa(nullptr, Reg, 0);
70  MAI->addInitialFrameState(Inst);
71 
72  return MAI;
73 }
74 
75 static void adjustCodeGenOpts(const Triple &TT, Reloc::Model RM,
76  CodeModel::Model &CM) {
78  "Only expect Darwin and ELF targets");
79 
80  if (CM == CodeModel::Default)
81  CM = CodeModel::Small;
82  // The default MCJIT memory managers make no guarantees about where they can
83  // find an executable page; JITed code needs to be able to refer to globals
84  // no matter how far away they are.
85  else if (CM == CodeModel::JITDefault)
86  CM = CodeModel::Large;
87  else if (CM != CodeModel::Small && CM != CodeModel::Large)
89  "Only small and large code models are allowed on AArch64");
90 }
91 
93  unsigned SyntaxVariant,
94  const MCAsmInfo &MAI,
95  const MCInstrInfo &MII,
96  const MCRegisterInfo &MRI) {
97  if (SyntaxVariant == 0)
98  return new AArch64InstPrinter(MAI, MII, MRI);
99  if (SyntaxVariant == 1)
100  return new AArch64AppleInstPrinter(MAI, MII, MRI);
101 
102  return nullptr;
103 }
104 
107  MCCodeEmitter *Emitter, bool RelaxAll) {
108  return createAArch64ELFStreamer(Ctx, TAB, OS, Emitter, RelaxAll);
109 }
110 
112  raw_pwrite_stream &OS,
113  MCCodeEmitter *Emitter, bool RelaxAll,
114  bool DWARFMustBeAtTheEnd) {
115  return createMachOStreamer(Ctx, TAB, OS, Emitter, RelaxAll,
116  DWARFMustBeAtTheEnd,
117  /*LabelSections*/ true);
118 }
119 
121  return new MCInstrAnalysis(Info);
122 }
123 
124 // Force static initialization.
125 extern "C" void LLVMInitializeAArch64TargetMC() {
127  &getTheARM64Target()}) {
128  // Register the MC asm info.
130 
131  // Register the MC codegen info.
133 
134  // Register the MC instruction info.
136 
137  // Register the MC register info.
139 
140  // Register the MC subtarget info.
142 
143  // Register the MC instruction analyzer.
145 
146  // Register the MC Code Emitter
148 
149  // Register the obj streamers.
152 
153  // Register the obj target streamer.
156 
157  // Register the asm streamer.
160  // Register the MCInstPrinter.
162  }
163 
164  // Register the asm backend.
169 }
Target & getTheAArch64beTarget()
int getDwarfRegNum(unsigned RegNum, bool isEH) const
Map a target register to an equivalent dwarf register number.
bool isOSBinFormatMachO() const
Tests whether the environment is MachO.
Definition: Triple.h:575
static MCInstrAnalysis * createAArch64InstrAnalysis(const MCInstrInfo *Info)
LLVM_ATTRIBUTE_NORETURN void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
Target & getTheAArch64leTarget()
static void RegisterMCInstrAnalysis(Target &T, Target::MCInstrAnalysisCtorFnTy Fn)
RegisterMCInstrAnalysis - Register a MCInstrAnalysis implementation for the given target...
static MCInstrInfo * createAArch64MCInstrInfo()
static void RegisterMCInstPrinter(Target &T, Target::MCInstPrinterCtorTy Fn)
RegisterMCInstPrinter - Register a MCInstPrinter implementation for the given target.
static void RegisterAsmTargetStreamer(Target &T, Target::AsmTargetStreamerCtorTy Fn)
Reg
All possible values of the reg field in the ModR/M byte.
Target & getTheARM64Target()
Context object for machine code objects.
Definition: MCContext.h:51
void addInitialFrameState(const MCCFIInstruction &Inst)
Definition: MCAsmInfo.h:565
static MCSubtargetInfo * createAArch64MCSubtargetInfo(const Triple &TT, StringRef CPU, StringRef FS)
MCRegisterInfo base class - We assume that the target defines a static array of MCRegisterDesc object...
This class is intended to be used as a base class for asm properties and features specific to the tar...
Definition: MCAsmInfo.h:57
static void RegisterMCAsmBackend(Target &T, Target::MCAsmBackendCtorTy Fn)
RegisterMCAsmBackend - Register a MCAsmBackend implementation for the given target.
Streaming machine code generation interface.
Definition: MCStreamer.h:161
unsigned const MachineRegisterInfo * MRI
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:369
static MCRegisterInfo * createAArch64MCRegisterInfo(const Triple &Triple)
static void RegisterMachOStreamer(Target &T, Target::MachOStreamerCtorTy Fn)
MCCodeEmitter - Generic instruction encoding interface.
Definition: MCCodeEmitter.h:23
static MCAsmInfo * createAArch64MCAsmInfo(const MCRegisterInfo &MRI, const Triple &TheTriple)
Interface to description of machine instruction set.
Definition: MCInstrInfo.h:24
MCELFStreamer * createAArch64ELFStreamer(MCContext &Context, MCAsmBackend &TAB, raw_pwrite_stream &OS, MCCodeEmitter *Emitter, bool RelaxAll)
static GCMetadataPrinterRegistry::Add< ErlangGCPrinter > X("erlang","erlang-compatible garbage collector")
static void registerMCAdjustCodeGenOpts(Target &T, Target::MCAdjustCodeGenOptsFnTy Fn)
static void adjustCodeGenOpts(const Triple &TT, Reloc::Model RM, CodeModel::Model &CM)
static MCInstPrinter * createAArch64MCInstPrinter(const Triple &T, unsigned SyntaxVariant, const MCAsmInfo &MAI, const MCInstrInfo &MII, const MCRegisterInfo &MRI)
static void RegisterMCSubtargetInfo(Target &T, Target::MCSubtargetInfoCtorFnTy Fn)
RegisterMCSubtargetInfo - Register a MCSubtargetInfo implementation for the given target...
static void RegisterObjectTargetStreamer(Target &T, Target::ObjectTargetStreamerCtorTy Fn)
Triple - Helper class for working with autoconf configuration names.
Definition: Triple.h:44
MCTargetStreamer * createAArch64ObjectTargetStreamer(MCStreamer &S, const MCSubtargetInfo &STI)
MCCodeEmitter * createAArch64MCCodeEmitter(const MCInstrInfo &MCII, const MCRegisterInfo &MRI, MCContext &Ctx)
static void RegisterMCCodeEmitter(Target &T, Target::MCCodeEmitterCtorTy Fn)
RegisterMCCodeEmitter - Register a MCCodeEmitter implementation for the given target.
MCStreamer * createELFStreamer(MCContext &Ctx, MCAsmBackend &TAB, raw_pwrite_stream &OS, MCCodeEmitter *CE, bool RelaxAll)
Takes ownership of TAB and CE.
static void RegisterMCRegInfo(Target &T, Target::MCRegInfoCtorFnTy Fn)
RegisterMCRegInfo - Register a MCRegisterInfo implementation for the given target.
Target - Wrapper for Target specific information.
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE bool empty() const
empty - Check if the string is empty.
Definition: StringRef.h:130
RegisterMCAsmInfoFn - Helper template for registering a target assembly info implementation.
This is an instance of a target assembly language printer that converts an MCInst to valid target ass...
Definition: MCInstPrinter.h:41
bool isOSBinFormatELF() const
Tests whether the OS uses the ELF binary format.
Definition: Triple.h:565
MCTargetStreamer * createAArch64AsmTargetStreamer(MCStreamer &S, formatted_raw_ostream &OS, MCInstPrinter *InstPrint, bool isVerboseAsm)
MCAsmBackend * createAArch64leAsmBackend(const Target &T, const MCRegisterInfo &MRI, const Triple &TT, StringRef CPU, const MCTargetOptions &Options)
static void RegisterMCInstrInfo(Target &T, Target::MCInstrInfoCtorFnTy Fn)
RegisterMCInstrInfo - Register a MCInstrInfo implementation for the given target. ...
MCSubtargetInfo - Generic base class for all target subtargets.
MCAsmBackend * createAArch64beAsmBackend(const Target &T, const MCRegisterInfo &MRI, const Triple &TT, StringRef CPU, const MCTargetOptions &Options)
static void RegisterELFStreamer(Target &T, Target::ELFStreamerCtorTy Fn)
An abstract base class for streams implementations that also support a pwrite operation.
Definition: raw_ostream.h:333
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
cl::opt< bool > RelaxAll("mc-relax-all", cl::desc("When used with filetype=obj, ""relax all fixups in the emitted object file"))
MCStreamer * createMachOStreamer(MCContext &Ctx, MCAsmBackend &TAB, raw_pwrite_stream &OS, MCCodeEmitter *CE, bool RelaxAll, bool DWARFMustBeAtTheEnd, bool LabelSections=false)
Generic interface to target specific assembler backends.
Definition: MCAsmBackend.h:36
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:47
void LLVMInitializeAArch64TargetMC()