LLVM  6.0.0svn
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"
17 #include "AArch64WinCOFFStreamer.h"
19 #include "llvm/MC/MCAsmBackend.h"
20 #include "llvm/MC/MCCodeEmitter.h"
22 #include "llvm/MC/MCInstrInfo.h"
23 #include "llvm/MC/MCRegisterInfo.h"
24 #include "llvm/MC/MCStreamer.h"
28 
29 using namespace llvm;
30 
31 #define GET_INSTRINFO_MC_DESC
32 #include "AArch64GenInstrInfo.inc"
33 
34 #define GET_SUBTARGETINFO_MC_DESC
35 #include "AArch64GenSubtargetInfo.inc"
36 
37 #define GET_REGINFO_MC_DESC
38 #include "AArch64GenRegisterInfo.inc"
39 
41  MCInstrInfo *X = new MCInstrInfo();
42  InitAArch64MCInstrInfo(X);
43  return X;
44 }
45 
46 static MCSubtargetInfo *
48  if (CPU.empty())
49  CPU = "generic";
50 
51  return createAArch64MCSubtargetInfoImpl(TT, CPU, FS);
52 }
53 
55  for (unsigned Reg = AArch64::NoRegister + 1;
56  Reg < AArch64::NUM_TARGET_REGS; ++Reg) {
57  unsigned CV = MRI->getEncodingValue(Reg);
58  MRI->mapLLVMRegToCVReg(Reg, CV);
59  }
60 }
61 
64  InitAArch64MCRegisterInfo(X, AArch64::LR);
66  return X;
67 }
68 
70  const Triple &TheTriple) {
71  MCAsmInfo *MAI;
72  if (TheTriple.isOSBinFormatMachO())
73  MAI = new AArch64MCAsmInfoDarwin();
74  else if (TheTriple.isWindowsMSVCEnvironment())
76  else if (TheTriple.isOSBinFormatCOFF())
77  MAI = new AArch64MCAsmInfoGNUCOFF();
78  else {
79  assert(TheTriple.isOSBinFormatELF() && "Invalid target");
80  MAI = new AArch64MCAsmInfoELF(TheTriple);
81  }
82 
83  // Initial state of the frame pointer is SP.
84  unsigned Reg = MRI.getDwarfRegNum(AArch64::SP, true);
85  MCCFIInstruction Inst = MCCFIInstruction::createDefCfa(nullptr, Reg, 0);
86  MAI->addInitialFrameState(Inst);
87 
88  return MAI;
89 }
90 
92  unsigned SyntaxVariant,
93  const MCAsmInfo &MAI,
94  const MCInstrInfo &MII,
95  const MCRegisterInfo &MRI) {
96  if (SyntaxVariant == 0)
97  return new AArch64InstPrinter(MAI, MII, MRI);
98  if (SyntaxVariant == 1)
99  return new AArch64AppleInstPrinter(MAI, MII, MRI);
100 
101  return nullptr;
102 }
103 
105  std::unique_ptr<MCAsmBackend> &&TAB,
106  raw_pwrite_stream &OS,
107  std::unique_ptr<MCCodeEmitter> &&Emitter,
108  bool RelaxAll) {
109  return createAArch64ELFStreamer(Ctx, std::move(TAB), OS, std::move(Emitter),
110  RelaxAll);
111 }
112 
114  std::unique_ptr<MCAsmBackend> &&TAB,
115  raw_pwrite_stream &OS,
116  std::unique_ptr<MCCodeEmitter> &&Emitter,
117  bool RelaxAll,
118  bool DWARFMustBeAtTheEnd) {
119  return createMachOStreamer(Ctx, std::move(TAB), OS, std::move(Emitter),
120  RelaxAll, DWARFMustBeAtTheEnd,
121  /*LabelSections*/ true);
122 }
123 
124 static MCStreamer *
125 createWinCOFFStreamer(MCContext &Ctx, std::unique_ptr<MCAsmBackend> &&TAB,
126  raw_pwrite_stream &OS,
127  std::unique_ptr<MCCodeEmitter> &&Emitter, bool RelaxAll,
129  return createAArch64WinCOFFStreamer(Ctx, std::move(TAB), OS,
130  std::move(Emitter), RelaxAll,
131  IncrementalLinkerCompatible);
132 }
133 
135  return new MCInstrAnalysis(Info);
136 }
137 
138 // Force static initialization.
139 extern "C" void LLVMInitializeAArch64TargetMC() {
141  &getTheARM64Target()}) {
142  // Register the MC asm info.
144 
145  // Register the MC instruction info.
147 
148  // Register the MC register info.
150 
151  // Register the MC subtarget info.
153 
154  // Register the MC instruction analyzer.
156 
157  // Register the MC Code Emitter
159 
160  // Register the obj streamers.
164 
165  // Register the obj target streamer.
168 
169  // Register the asm streamer.
172  // Register the MCInstPrinter.
174  }
175 
176  // Register the asm backend.
181 }
Target & getTheAArch64beTarget()
static GCMetadataPrinterRegistry::Add< ErlangGCPrinter > X("erlang", "erlang-compatible garbage collector")
static MCInstrAnalysis * createAArch64InstrAnalysis(const MCInstrInfo *Info)
Compute iterated dominance frontiers using a linear time algorithm.
Definition: AllocatorList.h:24
bool isOSBinFormatELF() const
Tests whether the OS uses the ELF binary format.
Definition: Triple.h:588
Target & getTheAArch64leTarget()
static void RegisterMCInstrAnalysis(Target &T, Target::MCInstrAnalysisCtorFnTy Fn)
RegisterMCInstrAnalysis - Register a MCInstrAnalysis implementation for the given target...
MCStreamer * createMachOStreamer(MCContext &Ctx, std::unique_ptr< MCAsmBackend > &&TAB, raw_pwrite_stream &OS, std::unique_ptr< MCCodeEmitter > &&CE, bool RelaxAll, bool DWARFMustBeAtTheEnd, bool LabelSections=false)
MCELFStreamer * createAArch64ELFStreamer(MCContext &Context, std::unique_ptr< MCAsmBackend > TAB, raw_pwrite_stream &OS, std::unique_ptr< MCCodeEmitter > Emitter, bool RelaxAll)
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.
int getDwarfRegNum(unsigned RegNum, bool isEH) const
Map a target register to an equivalent dwarf register number.
Target & getTheARM64Target()
static void RegisterCOFFStreamer(Target &T, Target::COFFStreamerCtorTy Fn)
Context object for machine code objects.
Definition: MCContext.h:59
void addInitialFrameState(const MCCFIInstruction &Inst)
Definition: MCAsmInfo.h:582
cl::opt< bool > RelaxAll("mc-relax-all", cl::desc("When used with filetype=obj, " "relax all fixups in the emitted object file"))
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE bool empty() const
empty - Check if the string is empty.
Definition: StringRef.h:133
static MCSubtargetInfo * createAArch64MCSubtargetInfo(const Triple &TT, StringRef CPU, StringRef FS)
static MCStreamer * createWinCOFFStreamer(MCContext &Ctx, std::unique_ptr< MCAsmBackend > &&TAB, raw_pwrite_stream &OS, std::unique_ptr< MCCodeEmitter > &&Emitter, bool RelaxAll, bool IncrementalLinkerCompatible)
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:56
MCWinCOFFStreamer * createAArch64WinCOFFStreamer(MCContext &Context, std::unique_ptr< MCAsmBackend > MAB, raw_pwrite_stream &OS, std::unique_ptr< MCCodeEmitter > Emitter, bool RelaxAll, bool IncrementalLinkerCompatible)
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:169
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:377
static MCRegisterInfo * createAArch64MCRegisterInfo(const Triple &Triple)
bool isOSBinFormatCOFF() const
Tests whether the OS uses the COFF binary format.
Definition: Triple.h:593
static void RegisterMachOStreamer(Target &T, Target::MachOStreamerCtorTy Fn)
cl::opt< bool > IncrementalLinkerCompatible("incremental-linker-compatible", cl::desc("When used with filetype=obj, " "emit an object file which can be used with an incremental linker"))
static MCAsmInfo * createAArch64MCAsmInfo(const MCRegisterInfo &MRI, const Triple &TheTriple)
Interface to description of machine instruction set.
Definition: MCInstrInfo.h:24
MCStreamer * createELFStreamer(MCContext &Ctx, std::unique_ptr< MCAsmBackend > &&TAB, raw_pwrite_stream &OS, std::unique_ptr< MCCodeEmitter > &&CE, bool RelaxAll)
Takes ownership of TAB and CE.
bool isOSBinFormatMachO() const
Tests whether the environment is MachO.
Definition: Triple.h:598
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.
static void RegisterMCRegInfo(Target &T, Target::MCRegInfoCtorFnTy Fn)
RegisterMCRegInfo - Register a MCRegisterInfo implementation for the given target.
Target - Wrapper for Target specific information.
void initLLVMToCVRegMapping(MCRegisterInfo *MRI)
This is an instance of a target assembly language printer that converts an MCInst to valid target ass...
Definition: MCInstPrinter.h:41
uint16_t getEncodingValue(unsigned RegNo) const
Returns the encoding for RegNo.
void mapLLVMRegToCVReg(unsigned LLVMReg, int CVReg)
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:337
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
RegisterMCAsmInfoFn - Helper template for registering a target assembly info implementation.
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:49
bool isWindowsMSVCEnvironment() const
Checks if the environment could be MSVC.
Definition: Triple.h:523
void LLVMInitializeAArch64TargetMC()