1 //===-- ARM64MCTargetDesc.cpp - ARM64 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 ARM64 specific target descriptions.
12 //===----------------------------------------------------------------------===//
14 #include "ARM64MCTargetDesc.h"
15 #include "ARM64ELFStreamer.h"
16 #include "ARM64MCAsmInfo.h"
17 #include "InstPrinter/ARM64InstPrinter.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"
26 #define GET_INSTRINFO_MC_DESC
27 #include "ARM64GenInstrInfo.inc"
29 #define GET_SUBTARGETINFO_MC_DESC
30 #include "ARM64GenSubtargetInfo.inc"
32 #define GET_REGINFO_MC_DESC
33 #include "ARM64GenRegisterInfo.inc"
37 static MCInstrInfo *createARM64MCInstrInfo() {
38 MCInstrInfo *X = new MCInstrInfo();
39 InitARM64MCInstrInfo(X);
43 static MCSubtargetInfo *createARM64MCSubtargetInfo(StringRef TT, StringRef CPU,
45 MCSubtargetInfo *X = new MCSubtargetInfo();
46 InitARM64MCSubtargetInfo(X, TT, CPU, FS);
50 static MCRegisterInfo *createARM64MCRegisterInfo(StringRef Triple) {
51 MCRegisterInfo *X = new MCRegisterInfo();
52 InitARM64MCRegisterInfo(X, ARM64::LR);
56 static MCAsmInfo *createARM64MCAsmInfo(const MCRegisterInfo &MRI,
61 if (TheTriple.isOSDarwin())
62 MAI = new ARM64MCAsmInfoDarwin();
64 assert(TheTriple.isOSBinFormatELF() && "Only expect Darwin or ELF");
65 MAI = new ARM64MCAsmInfoELF();
68 // Initial state of the frame pointer is SP.
69 unsigned Reg = MRI.getDwarfRegNum(ARM64::SP, true);
70 MCCFIInstruction Inst = MCCFIInstruction::createDefCfa(0, Reg, 0);
71 MAI->addInitialFrameState(Inst);
76 MCCodeGenInfo *createARM64MCCodeGenInfo(StringRef TT, Reloc::Model RM,
78 CodeGenOpt::Level OL) {
80 assert((TheTriple.isOSBinFormatELF() || TheTriple.isOSBinFormatMachO()) &&
81 "Only expect Darwin and ELF targets");
83 if (CM == CodeModel::Default)
84 CM = CodeModel::Small;
85 // The default MCJIT memory managers make no guarantees about where they can
86 // find an executable page; JITed code needs to be able to refer to globals
87 // no matter how far away they are.
88 else if (CM == CodeModel::JITDefault)
89 CM = CodeModel::Large;
90 else if (CM != CodeModel::Small && CM != CodeModel::Large)
91 report_fatal_error("Only small and large code models are allowed on ARM64");
93 // ARM64 Darwin is always PIC.
94 if (TheTriple.isOSDarwin())
96 // On ELF platforms the default static relocation model has a smart enough
97 // linker to cope with referencing external symbols defined in a shared
98 // library. Hence DynamicNoPIC doesn't need to be promoted to PIC.
99 else if (RM == Reloc::Default || RM == Reloc::DynamicNoPIC)
102 MCCodeGenInfo *X = new MCCodeGenInfo();
103 X->InitMCCodeGenInfo(RM, CM, OL);
107 static MCInstPrinter *createARM64MCInstPrinter(const Target &T,
108 unsigned SyntaxVariant,
109 const MCAsmInfo &MAI,
110 const MCInstrInfo &MII,
111 const MCRegisterInfo &MRI,
112 const MCSubtargetInfo &STI) {
113 if (SyntaxVariant == 0)
114 return new ARM64InstPrinter(MAI, MII, MRI, STI);
115 if (SyntaxVariant == 1)
116 return new ARM64AppleInstPrinter(MAI, MII, MRI, STI);
121 static MCStreamer *createMCStreamer(const Target &T, StringRef TT,
122 MCContext &Ctx, MCAsmBackend &TAB,
123 raw_ostream &OS, MCCodeEmitter *Emitter,
124 const MCSubtargetInfo &STI, bool RelaxAll,
126 Triple TheTriple(TT);
128 if (TheTriple.isOSDarwin())
129 return createMachOStreamer(Ctx, TAB, OS, Emitter, RelaxAll,
130 /*LabelSections*/ true);
132 return createARM64ELFStreamer(Ctx, TAB, OS, Emitter, RelaxAll, NoExecStack);
135 // Force static initialization.
136 extern "C" void LLVMInitializeARM64TargetMC() {
137 // Register the MC asm info.
138 RegisterMCAsmInfoFn X(TheARM64Target, createARM64MCAsmInfo);
140 // Register the MC codegen info.
141 TargetRegistry::RegisterMCCodeGenInfo(TheARM64Target,
142 createARM64MCCodeGenInfo);
144 // Register the MC instruction info.
145 TargetRegistry::RegisterMCInstrInfo(TheARM64Target, createARM64MCInstrInfo);
147 // Register the MC register info.
148 TargetRegistry::RegisterMCRegInfo(TheARM64Target, createARM64MCRegisterInfo);
150 // Register the MC subtarget info.
151 TargetRegistry::RegisterMCSubtargetInfo(TheARM64Target,
152 createARM64MCSubtargetInfo);
154 // Register the asm backend.
155 TargetRegistry::RegisterMCAsmBackend(TheARM64Target, createARM64AsmBackend);
157 // Register the MC Code Emitter
158 TargetRegistry::RegisterMCCodeEmitter(TheARM64Target,
159 createARM64MCCodeEmitter);
161 // Register the object streamer.
162 TargetRegistry::RegisterMCObjectStreamer(TheARM64Target, createMCStreamer);
164 // Register the MCInstPrinter.
165 TargetRegistry::RegisterMCInstPrinter(TheARM64Target,
166 createARM64MCInstPrinter);