1 //===-- AArch64MCTargetDesc.cpp - AArch64 Target Descriptions ---*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file provides AArch64 specific target descriptions.
12 //===----------------------------------------------------------------------===//
14 #include "AArch64MCTargetDesc.h"
15 #include "AArch64ELFStreamer.h"
16 #include "AArch64MCAsmInfo.h"
17 #include "InstPrinter/AArch64InstPrinter.h"
18 #include "llvm/MC/MCCodeGenInfo.h"
19 #include "llvm/MC/MCInstrInfo.h"
20 #include "llvm/MC/MCRegisterInfo.h"
21 #include "llvm/MC/MCStreamer.h"
22 #include "llvm/MC/MCSubtargetInfo.h"
23 #include "llvm/Support/ErrorHandling.h"
24 #include "llvm/Support/TargetRegistry.h"
28 #define GET_INSTRINFO_MC_DESC
29 #include "AArch64GenInstrInfo.inc"
31 #define GET_SUBTARGETINFO_MC_DESC
32 #include "AArch64GenSubtargetInfo.inc"
34 #define GET_REGINFO_MC_DESC
35 #include "AArch64GenRegisterInfo.inc"
37 static MCInstrInfo *createAArch64MCInstrInfo() {
38 MCInstrInfo *X = new MCInstrInfo();
39 InitAArch64MCInstrInfo(X);
43 static MCSubtargetInfo *
44 createAArch64MCSubtargetInfo(StringRef TT, StringRef CPU, StringRef FS) {
45 MCSubtargetInfo *X = new MCSubtargetInfo();
50 InitAArch64MCSubtargetInfo(X, TT, CPU, FS);
54 static MCRegisterInfo *createAArch64MCRegisterInfo(StringRef Triple) {
55 MCRegisterInfo *X = new MCRegisterInfo();
56 InitAArch64MCRegisterInfo(X, AArch64::LR);
60 static MCAsmInfo *createAArch64MCAsmInfo(const MCRegisterInfo &MRI,
65 if (TheTriple.isOSDarwin())
66 MAI = new AArch64MCAsmInfoDarwin();
68 assert(TheTriple.isOSBinFormatELF() && "Only expect Darwin or ELF");
69 MAI = new AArch64MCAsmInfoELF(TT);
72 // Initial state of the frame pointer is SP.
73 unsigned Reg = MRI.getDwarfRegNum(AArch64::SP, true);
74 MCCFIInstruction Inst = MCCFIInstruction::createDefCfa(nullptr, Reg, 0);
75 MAI->addInitialFrameState(Inst);
80 static MCCodeGenInfo *createAArch64MCCodeGenInfo(StringRef TT, Reloc::Model RM,
82 CodeGenOpt::Level OL) {
84 assert((TheTriple.isOSBinFormatELF() || TheTriple.isOSBinFormatMachO()) &&
85 "Only expect Darwin and ELF targets");
87 if (CM == CodeModel::Default)
88 CM = CodeModel::Small;
89 // The default MCJIT memory managers make no guarantees about where they can
90 // find an executable page; JITed code needs to be able to refer to globals
91 // no matter how far away they are.
92 else if (CM == CodeModel::JITDefault)
93 CM = CodeModel::Large;
94 else if (CM != CodeModel::Small && CM != CodeModel::Large)
96 "Only small and large code models are allowed on AArch64");
98 // AArch64 Darwin is always PIC.
99 if (TheTriple.isOSDarwin())
101 // On ELF platforms the default static relocation model has a smart enough
102 // linker to cope with referencing external symbols defined in a shared
103 // library. Hence DynamicNoPIC doesn't need to be promoted to PIC.
104 else if (RM == Reloc::Default || RM == Reloc::DynamicNoPIC)
107 MCCodeGenInfo *X = new MCCodeGenInfo();
108 X->initMCCodeGenInfo(RM, CM, OL);
112 static MCInstPrinter *createAArch64MCInstPrinter(const Triple &T,
113 unsigned SyntaxVariant,
114 const MCAsmInfo &MAI,
115 const MCInstrInfo &MII,
116 const MCRegisterInfo &MRI) {
117 if (SyntaxVariant == 0)
118 return new AArch64InstPrinter(MAI, MII, MRI);
119 if (SyntaxVariant == 1)
120 return new AArch64AppleInstPrinter(MAI, MII, MRI);
125 static MCStreamer *createELFStreamer(const Triple &T, MCContext &Ctx,
126 MCAsmBackend &TAB, raw_pwrite_stream &OS,
127 MCCodeEmitter *Emitter, bool RelaxAll) {
128 return createAArch64ELFStreamer(Ctx, TAB, OS, Emitter, RelaxAll);
131 static MCStreamer *createMachOStreamer(MCContext &Ctx, MCAsmBackend &TAB,
132 raw_pwrite_stream &OS,
133 MCCodeEmitter *Emitter, bool RelaxAll,
134 bool DWARFMustBeAtTheEnd) {
135 return createMachOStreamer(Ctx, TAB, OS, Emitter, RelaxAll,
137 /*LabelSections*/ true);
140 // Force static initialization.
141 extern "C" void LLVMInitializeAArch64TargetMC() {
143 {&TheAArch64leTarget, &TheAArch64beTarget, &TheARM64Target}) {
144 // Register the MC asm info.
145 RegisterMCAsmInfoFn X(*T, createAArch64MCAsmInfo);
147 // Register the MC codegen info.
148 TargetRegistry::RegisterMCCodeGenInfo(*T, createAArch64MCCodeGenInfo);
150 // Register the MC instruction info.
151 TargetRegistry::RegisterMCInstrInfo(*T, createAArch64MCInstrInfo);
153 // Register the MC register info.
154 TargetRegistry::RegisterMCRegInfo(*T, createAArch64MCRegisterInfo);
156 // Register the MC subtarget info.
157 TargetRegistry::RegisterMCSubtargetInfo(*T, createAArch64MCSubtargetInfo);
159 // Register the MC Code Emitter
160 TargetRegistry::RegisterMCCodeEmitter(*T, createAArch64MCCodeEmitter);
162 // Register the obj streamers.
163 TargetRegistry::RegisterELFStreamer(*T, createELFStreamer);
164 TargetRegistry::RegisterMachOStreamer(*T, createMachOStreamer);
166 // Register the obj target streamer.
167 TargetRegistry::RegisterObjectTargetStreamer(
168 *T, createAArch64ObjectTargetStreamer);
170 // Register the asm streamer.
171 TargetRegistry::RegisterAsmTargetStreamer(*T,
172 createAArch64AsmTargetStreamer);
173 // Register the MCInstPrinter.
174 TargetRegistry::RegisterMCInstPrinter(*T, createAArch64MCInstPrinter);
177 // Register the asm backend.
178 for (Target *T : {&TheAArch64leTarget, &TheARM64Target})
179 TargetRegistry::RegisterMCAsmBackend(*T, createAArch64leAsmBackend);
180 TargetRegistry::RegisterMCAsmBackend(TheAArch64beTarget,
181 createAArch64beAsmBackend);