blob: 21c9fc1e58b296c21ec16b03773e5058af80824a [file] [log] [blame]
Jia Liub22310f2012-02-18 12:03:15 +00001//===-- ARMMCTargetDesc.cpp - ARM Target Descriptions ---------------------===//
Evan Cheng928ce722011-07-06 22:02:34 +00002//
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 ARM specific target descriptions.
11//
12//===----------------------------------------------------------------------===//
13
Chandler Carruthbe810232013-01-02 10:22:59 +000014#include "ARMBaseInfo.h"
Tim Northover5cc3dc82012-12-07 16:50:23 +000015#include "ARMMCAsmInfo.h"
Eli Bendersky2e2ce492013-01-30 16:30:19 +000016#include "ARMMCTargetDesc.h"
Evan Cheng61faa552011-07-25 21:20:24 +000017#include "InstPrinter/ARMInstPrinter.h"
Eli Bendersky2e2ce492013-01-30 16:30:19 +000018#include "llvm/ADT/Triple.h"
Evan Cheng4d6c9d72011-08-23 20:15:21 +000019#include "llvm/MC/MCCodeGenInfo.h"
Rafael Espindolaac4ad252013-10-05 16:42:21 +000020#include "llvm/MC/MCELFStreamer.h"
Evan Cheng4d6c9d72011-08-23 20:15:21 +000021#include "llvm/MC/MCInstrAnalysis.h"
Evan Cheng928ce722011-07-06 22:02:34 +000022#include "llvm/MC/MCInstrInfo.h"
23#include "llvm/MC/MCRegisterInfo.h"
Saleem Abdulrasool84b952b2014-04-27 03:48:22 +000024#include "llvm/MC/MCStreamer.h"
Evan Cheng928ce722011-07-06 22:02:34 +000025#include "llvm/MC/MCSubtargetInfo.h"
Evan Chengad5f4852011-07-23 00:00:19 +000026#include "llvm/Support/ErrorHandling.h"
Evan Cheng2bb40352011-08-24 18:08:43 +000027#include "llvm/Support/TargetRegistry.h"
Evan Cheng928ce722011-07-06 22:02:34 +000028
Joey Gouly0e76fa72013-09-12 10:28:05 +000029using namespace llvm;
30
Evan Cheng928ce722011-07-06 22:02:34 +000031#define GET_REGINFO_MC_DESC
32#include "ARMGenRegisterInfo.inc"
33
Duncan P. N. Exon Smithad987452015-07-08 17:30:55 +000034static bool getMCRDeprecationInfo(MCInst &MI, const MCSubtargetInfo &STI,
Joey Gouly0e76fa72013-09-12 10:28:05 +000035 std::string &Info) {
Michael Kupersteindb0712f2015-05-26 10:47:10 +000036 if (STI.getFeatureBits()[llvm::ARM::HasV7Ops] &&
Joey Gouly830c27a2013-09-17 09:54:57 +000037 (MI.getOperand(0).isImm() && MI.getOperand(0).getImm() == 15) &&
Joey Gouly0e76fa72013-09-12 10:28:05 +000038 (MI.getOperand(1).isImm() && MI.getOperand(1).getImm() == 0) &&
Joey Gouly830c27a2013-09-17 09:54:57 +000039 // Checks for the deprecated CP15ISB encoding:
40 // mcr p15, #0, rX, c7, c5, #4
41 (MI.getOperand(3).isImm() && MI.getOperand(3).getImm() == 7)) {
42 if ((MI.getOperand(5).isImm() && MI.getOperand(5).getImm() == 4)) {
43 if (MI.getOperand(4).isImm() && MI.getOperand(4).getImm() == 5) {
44 Info = "deprecated since v7, use 'isb'";
45 return true;
46 }
47
48 // Checks for the deprecated CP15DSB encoding:
49 // mcr p15, #0, rX, c7, c10, #4
50 if (MI.getOperand(4).isImm() && MI.getOperand(4).getImm() == 10) {
51 Info = "deprecated since v7, use 'dsb'";
52 return true;
53 }
54 }
55 // Checks for the deprecated CP15DMB encoding:
56 // mcr p15, #0, rX, c7, c10, #5
57 if (MI.getOperand(4).isImm() && MI.getOperand(4).getImm() == 10 &&
58 (MI.getOperand(5).isImm() && MI.getOperand(5).getImm() == 5)) {
59 Info = "deprecated since v7, use 'dmb'";
60 return true;
61 }
Joey Gouly0e76fa72013-09-12 10:28:05 +000062 }
63 return false;
64}
65
Duncan P. N. Exon Smithad987452015-07-08 17:30:55 +000066static bool getITDeprecationInfo(MCInst &MI, const MCSubtargetInfo &STI,
Saleem Abdulrasool08408ea2014-12-16 04:10:10 +000067 std::string &Info) {
Michael Kupersteindb0712f2015-05-26 10:47:10 +000068 if (STI.getFeatureBits()[llvm::ARM::HasV8Ops] && MI.getOperand(1).isImm() &&
Saleem Abdulrasool08408ea2014-12-16 04:10:10 +000069 MI.getOperand(1).getImm() != 8) {
70 Info = "applying IT instruction to more than one subsequent instruction is "
71 "deprecated";
Amara Emerson52cfb6a2013-10-03 09:31:51 +000072 return true;
73 }
74
75 return false;
76}
77
Duncan P. N. Exon Smithad987452015-07-08 17:30:55 +000078static bool getARMStoreDeprecationInfo(MCInst &MI, const MCSubtargetInfo &STI,
Saleem Abdulrasool417fc6b2014-12-16 05:53:25 +000079 std::string &Info) {
Michael Kupersteindb0712f2015-05-26 10:47:10 +000080 assert(!STI.getFeatureBits()[llvm::ARM::ModeThumb] &&
Saleem Abdulrasool747ec2d2014-12-24 18:40:42 +000081 "cannot predicate thumb instructions");
Saleem Abdulrasool1ce7d312014-12-17 16:17:44 +000082
83 assert(MI.getNumOperands() >= 4 && "expected >= 4 arguments");
Saleem Abdulrasool417fc6b2014-12-16 05:53:25 +000084 for (unsigned OI = 4, OE = MI.getNumOperands(); OI < OE; ++OI) {
85 assert(MI.getOperand(OI).isReg() && "expected register");
86 if (MI.getOperand(OI).getReg() == ARM::SP ||
87 MI.getOperand(OI).getReg() == ARM::PC) {
88 Info = "use of SP or PC in the list is deprecated";
89 return true;
90 }
91 }
92 return false;
93}
94
Duncan P. N. Exon Smithad987452015-07-08 17:30:55 +000095static bool getARMLoadDeprecationInfo(MCInst &MI, const MCSubtargetInfo &STI,
Saleem Abdulrasool0fa83202014-12-20 20:25:36 +000096 std::string &Info) {
Michael Kupersteindb0712f2015-05-26 10:47:10 +000097 assert(!STI.getFeatureBits()[llvm::ARM::ModeThumb] &&
Saleem Abdulrasool747ec2d2014-12-24 18:40:42 +000098 "cannot predicate thumb instructions");
Saleem Abdulrasool0fa83202014-12-20 20:25:36 +000099
100 assert(MI.getNumOperands() >= 4 && "expected >= 4 arguments");
101 bool ListContainsPC = false, ListContainsLR = false;
102 for (unsigned OI = 4, OE = MI.getNumOperands(); OI < OE; ++OI) {
103 assert(MI.getOperand(OI).isReg() && "expected register");
104 switch (MI.getOperand(OI).getReg()) {
105 default:
106 break;
107 case ARM::LR:
108 ListContainsLR = true;
109 break;
110 case ARM::PC:
111 ListContainsPC = true;
112 break;
113 case ARM::SP:
114 Info = "use of SP in the list is deprecated";
115 return true;
116 }
117 }
118
119 if (ListContainsPC && ListContainsLR) {
120 Info = "use of LR and PC simultaneously in the list is deprecated";
121 return true;
122 }
123
124 return false;
125}
126
Evan Cheng928ce722011-07-06 22:02:34 +0000127#define GET_INSTRINFO_MC_DESC
128#include "ARMGenInstrInfo.inc"
129
130#define GET_SUBTARGETINFO_MC_DESC
131#include "ARMGenSubtargetInfo.inc"
132
Daniel Sandersa73f1fd2015-06-10 12:11:26 +0000133std::string ARM_MC::ParseARMTriple(const Triple &TT, StringRef CPU) {
134 bool isThumb =
135 TT.getArch() == Triple::thumb || TT.getArch() == Triple::thumbeb;
Evan Cheng2bd65362011-07-07 00:08:19 +0000136
Evan Chengf52003d2012-04-27 01:27:19 +0000137 bool NoCPU = CPU == "generic" || CPU.empty();
Evan Cheng2bd65362011-07-07 00:08:19 +0000138 std::string ARMArchFeature;
Daniel Sandersa73f1fd2015-06-10 12:11:26 +0000139 switch (TT.getSubArch()) {
Tim Northoverc879d062014-09-05 07:56:46 +0000140 default:
141 llvm_unreachable("invalid sub-architecture for ARM");
Renato Golinc17a07b2014-07-18 12:00:48 +0000142 case Triple::ARMSubArch_v8:
143 if (NoCPU)
144 // v8a: FeatureDB, FeatureFPARMv8, FeatureNEON, FeatureDSPThumb2,
145 // FeatureMP, FeatureHWDiv, FeatureHWDivARM, FeatureTrustZone,
146 // FeatureT2XtPk, FeatureCrypto, FeatureCRC
147 ARMArchFeature = "+v8,+db,+fp-armv8,+neon,+t2dsp,+mp,+hwdiv,+hwdiv-arm,"
148 "+trustzone,+t2xtpk,+crypto,+crc";
149 else
150 // Use CPU to figure out the exact features
151 ARMArchFeature = "+v8";
152 break;
Vladimir Sukharevc632cda2015-03-26 17:05:54 +0000153 case Triple::ARMSubArch_v8_1a:
154 if (NoCPU)
155 // v8.1a: FeatureDB, FeatureFPARMv8, FeatureNEON, FeatureDSPThumb2,
156 // FeatureMP, FeatureHWDiv, FeatureHWDivARM, FeatureTrustZone,
157 // FeatureT2XtPk, FeatureCrypto, FeatureCRC, FeatureV8_1a
158 ARMArchFeature = "+v8.1a,+db,+fp-armv8,+neon,+t2dsp,+mp,+hwdiv,+hwdiv-arm,"
159 "+trustzone,+t2xtpk,+crypto,+crc";
160 else
161 // Use CPU to figure out the exact features
162 ARMArchFeature = "+v8.1a";
163 break;
Renato Golinc17a07b2014-07-18 12:00:48 +0000164 case Triple::ARMSubArch_v7m:
165 isThumb = true;
166 if (NoCPU)
167 // v7m: FeatureNoARM, FeatureDB, FeatureHWDiv, FeatureMClass
168 ARMArchFeature = "+v7,+noarm,+db,+hwdiv,+mclass";
169 else
170 // Use CPU to figure out the exact features.
171 ARMArchFeature = "+v7";
172 break;
173 case Triple::ARMSubArch_v7em:
174 if (NoCPU)
175 // v7em: FeatureNoARM, FeatureDB, FeatureHWDiv, FeatureDSPThumb2,
176 // FeatureT2XtPk, FeatureMClass
John Brawnc815a962015-05-22 14:16:22 +0000177 ARMArchFeature = "+v7,+noarm,+db,+hwdiv,+t2dsp,+t2xtpk,+mclass";
Renato Golinc17a07b2014-07-18 12:00:48 +0000178 else
179 // Use CPU to figure out the exact features.
180 ARMArchFeature = "+v7";
181 break;
182 case Triple::ARMSubArch_v7s:
183 if (NoCPU)
184 // v7s: FeatureNEON, FeatureDB, FeatureDSPThumb2, FeatureHasRAS
185 // Swift
186 ARMArchFeature = "+v7,+swift,+neon,+db,+t2dsp,+ras";
187 else
188 // Use CPU to figure out the exact features.
189 ARMArchFeature = "+v7";
190 break;
191 case Triple::ARMSubArch_v7:
192 // v7 CPUs have lots of different feature sets. If no CPU is specified,
193 // then assume v7a (e.g. cortex-a8) feature set. Otherwise, return
194 // the "minimum" feature set and use CPU string to figure out the exact
195 // features.
196 if (NoCPU)
197 // v7a: FeatureNEON, FeatureDB, FeatureDSPThumb2, FeatureT2XtPk
198 ARMArchFeature = "+v7,+neon,+db,+t2dsp,+t2xtpk";
199 else
200 // Use CPU to figure out the exact features.
201 ARMArchFeature = "+v7";
202 break;
203 case Triple::ARMSubArch_v6t2:
204 ARMArchFeature = "+v6t2";
205 break;
Renato Golin12350602015-03-17 11:55:28 +0000206 case Triple::ARMSubArch_v6k:
207 ARMArchFeature = "+v6k";
208 break;
Renato Golinc17a07b2014-07-18 12:00:48 +0000209 case Triple::ARMSubArch_v6m:
210 isThumb = true;
211 if (NoCPU)
212 // v6m: FeatureNoARM, FeatureMClass
213 ARMArchFeature = "+v6m,+noarm,+mclass";
214 else
215 ARMArchFeature = "+v6";
216 break;
217 case Triple::ARMSubArch_v6:
218 ARMArchFeature = "+v6";
219 break;
220 case Triple::ARMSubArch_v5te:
221 ARMArchFeature = "+v5te";
222 break;
223 case Triple::ARMSubArch_v5:
224 ARMArchFeature = "+v5t";
225 break;
226 case Triple::ARMSubArch_v4t:
227 ARMArchFeature = "+v4t";
228 break;
Renato Goline48d9dc2014-07-18 12:13:04 +0000229 case Triple::NoSubArch:
230 break;
Evan Cheng2bd65362011-07-07 00:08:19 +0000231 }
232
Evan Chengf2c26162011-07-07 08:26:46 +0000233 if (isThumb) {
234 if (ARMArchFeature.empty())
Evan Cheng1834f5d2011-07-07 19:05:12 +0000235 ARMArchFeature = "+thumb-mode";
Evan Chengf2c26162011-07-07 08:26:46 +0000236 else
Evan Cheng1834f5d2011-07-07 19:05:12 +0000237 ARMArchFeature += ",+thumb-mode";
Evan Chengf2c26162011-07-07 08:26:46 +0000238 }
239
Daniel Sandersa73f1fd2015-06-10 12:11:26 +0000240 if (TT.isOSNaCl()) {
Eli Bendersky2e2ce492013-01-30 16:30:19 +0000241 if (ARMArchFeature.empty())
242 ARMArchFeature = "+nacl-trap";
243 else
244 ARMArchFeature += ",+nacl-trap";
245 }
246
Evan Cheng2bd65362011-07-07 00:08:19 +0000247 return ARMArchFeature;
248}
Evan Cheng4d1ca962011-07-08 01:53:10 +0000249
Daniel Sandersa73f1fd2015-06-10 12:11:26 +0000250MCSubtargetInfo *ARM_MC::createARMMCSubtargetInfo(const Triple &TT,
251 StringRef CPU, StringRef FS) {
Evan Cheng9f7ad312012-04-26 01:13:36 +0000252 std::string ArchFS = ARM_MC::ParseARMTriple(TT, CPU);
Evan Cheng4d1ca962011-07-08 01:53:10 +0000253 if (!FS.empty()) {
254 if (!ArchFS.empty())
Yaron Keren075759a2015-03-30 15:42:36 +0000255 ArchFS = (Twine(ArchFS) + "," + FS).str();
Evan Cheng4d1ca962011-07-08 01:53:10 +0000256 else
257 ArchFS = FS;
258 }
259
Duncan P. N. Exon Smith754e21f2015-07-10 22:43:42 +0000260 return createARMMCSubtargetInfoImpl(TT, CPU, ArchFS);
Evan Cheng4d1ca962011-07-08 01:53:10 +0000261}
262
Evan Cheng1705ab02011-07-14 23:50:31 +0000263static MCInstrInfo *createARMMCInstrInfo() {
Evan Cheng4d1ca962011-07-08 01:53:10 +0000264 MCInstrInfo *X = new MCInstrInfo();
265 InitARMMCInstrInfo(X);
266 return X;
267}
268
Daniel Sandersf423f562015-07-06 16:56:07 +0000269static MCRegisterInfo *createARMMCRegisterInfo(const Triple &Triple) {
Evan Cheng1705ab02011-07-14 23:50:31 +0000270 MCRegisterInfo *X = new MCRegisterInfo();
Jim Grosbach6df94842012-12-19 23:38:53 +0000271 InitARMMCRegisterInfo(X, ARM::LR, 0, 0, ARM::PC);
Evan Cheng1705ab02011-07-14 23:50:31 +0000272 return X;
273}
274
Daniel Sanders7813ae82015-06-04 13:12:25 +0000275static MCAsmInfo *createARMMCAsmInfo(const MCRegisterInfo &MRI,
276 const Triple &TheTriple) {
Mark Seabornba86cf52014-01-27 22:38:14 +0000277 MCAsmInfo *MAI;
Bob Wilson1e1f1382014-10-19 00:39:30 +0000278 if (TheTriple.isOSDarwin() || TheTriple.isOSBinFormatMachO())
Daniel Sanders7813ae82015-06-04 13:12:25 +0000279 MAI = new ARMMCAsmInfoDarwin(TheTriple);
Reid Klecknerd9707022014-11-17 22:55:59 +0000280 else if (TheTriple.isWindowsMSVCEnvironment())
Bob Wilson1e1f1382014-10-19 00:39:30 +0000281 MAI = new ARMCOFFMCAsmInfoMicrosoft();
Yaron Kerend1ba2d92015-07-14 05:51:05 +0000282 else if (TheTriple.isOSWindows())
283 MAI = new ARMCOFFMCAsmInfoGNU();
Bob Wilson1e1f1382014-10-19 00:39:30 +0000284 else
Daniel Sanders7813ae82015-06-04 13:12:25 +0000285 MAI = new ARMELFMCAsmInfo(TheTriple);
Evan Cheng1705ab02011-07-14 23:50:31 +0000286
Mark Seabornba86cf52014-01-27 22:38:14 +0000287 unsigned Reg = MRI.getDwarfRegNum(ARM::SP, true);
Craig Topper062a2ba2014-04-25 05:30:21 +0000288 MAI->addInitialFrameState(MCCFIInstruction::createDefCfa(nullptr, Reg, 0));
Mark Seabornba86cf52014-01-27 22:38:14 +0000289
290 return MAI;
Evan Cheng1705ab02011-07-14 23:50:31 +0000291}
292
Daniel Sandersf423f562015-07-06 16:56:07 +0000293static MCCodeGenInfo *createARMMCCodeGenInfo(const Triple &TT, Reloc::Model RM,
Evan Chengecb29082011-11-16 08:38:26 +0000294 CodeModel::Model CM,
295 CodeGenOpt::Level OL) {
Evan Cheng2129f592011-07-19 06:37:02 +0000296 MCCodeGenInfo *X = new MCCodeGenInfo();
Jim Grosbach4e0dbee2011-09-30 17:41:35 +0000297 if (RM == Reloc::Default) {
Jim Grosbach4e0dbee2011-09-30 17:41:35 +0000298 // Default relocation model on Darwin is PIC, not DynamicNoPIC.
Daniel Sandersf423f562015-07-06 16:56:07 +0000299 RM = TT.isOSDarwin() ? Reloc::PIC_ : Reloc::DynamicNoPIC;
Jim Grosbach4e0dbee2011-09-30 17:41:35 +0000300 }
Jim Grosbach4c98cf72015-05-15 19:13:31 +0000301 X->initMCCodeGenInfo(RM, CM, OL);
Evan Cheng2129f592011-07-19 06:37:02 +0000302 return X;
303}
304
Rafael Espindolacd584a82015-03-19 01:50:16 +0000305static MCStreamer *createELFStreamer(const Triple &T, MCContext &Ctx,
Rafael Espindola5560a4c2015-04-14 22:14:34 +0000306 MCAsmBackend &MAB, raw_pwrite_stream &OS,
Rafael Espindolacd584a82015-03-19 01:50:16 +0000307 MCCodeEmitter *Emitter, bool RelaxAll) {
308 return createARMELFStreamer(Ctx, MAB, OS, Emitter, false,
309 T.getArch() == Triple::thumb);
310}
311
312static MCStreamer *createARMMachOStreamer(MCContext &Ctx, MCAsmBackend &MAB,
Rafael Espindola5560a4c2015-04-14 22:14:34 +0000313 raw_pwrite_stream &OS,
Rafael Espindola36a15cb2015-03-20 20:00:01 +0000314 MCCodeEmitter *Emitter, bool RelaxAll,
315 bool DWARFMustBeAtTheEnd) {
316 return createMachOStreamer(Ctx, MAB, OS, Emitter, false, DWARFMustBeAtTheEnd);
Evan Chengad5f4852011-07-23 00:00:19 +0000317}
318
Eric Christopherf8019402015-03-31 00:10:04 +0000319static MCInstPrinter *createARMMCInstPrinter(const Triple &T,
320 unsigned SyntaxVariant,
James Molloy4c493e82011-09-07 17:24:38 +0000321 const MCAsmInfo &MAI,
Craig Topper54bfde72012-04-02 06:09:36 +0000322 const MCInstrInfo &MII,
Eric Christopherf8019402015-03-31 00:10:04 +0000323 const MCRegisterInfo &MRI) {
Evan Cheng61faa552011-07-25 21:20:24 +0000324 if (SyntaxVariant == 0)
Eric Christopher7099d512015-03-30 21:52:28 +0000325 return new ARMInstPrinter(MAI, MII, MRI);
Craig Topper062a2ba2014-04-25 05:30:21 +0000326 return nullptr;
Evan Cheng61faa552011-07-25 21:20:24 +0000327}
328
Daniel Sanders9aa7e382015-06-10 10:54:40 +0000329static MCRelocationInfo *createARMMCRelocationInfo(const Triple &TT,
Quentin Colombetf4828052013-05-24 22:51:52 +0000330 MCContext &Ctx) {
Daniel Sanders9aa7e382015-06-10 10:54:40 +0000331 if (TT.isOSBinFormatMachO())
Ahmed Bougachaad1084d2013-05-24 00:39:57 +0000332 return createARMMachORelocationInfo(Ctx);
333 // Default to the stock relocation info.
Quentin Colombetf4828052013-05-24 22:51:52 +0000334 return llvm::createMCRelocationInfo(TT, Ctx);
Ahmed Bougachaad1084d2013-05-24 00:39:57 +0000335}
336
Benjamin Kramerc22d50e2011-08-08 18:56:44 +0000337namespace {
338
339class ARMMCInstrAnalysis : public MCInstrAnalysis {
340public:
341 ARMMCInstrAnalysis(const MCInstrInfo *Info) : MCInstrAnalysis(Info) {}
Benjamin Kramerc22d50e2011-08-08 18:56:44 +0000342
Craig Topperca7e3e52014-03-10 03:19:03 +0000343 bool isUnconditionalBranch(const MCInst &Inst) const override {
Benjamin Kramerc22d50e2011-08-08 18:56:44 +0000344 // BCCs with the "always" predicate are unconditional branches.
345 if (Inst.getOpcode() == ARM::Bcc && Inst.getOperand(1).getImm()==ARMCC::AL)
346 return true;
347 return MCInstrAnalysis::isUnconditionalBranch(Inst);
348 }
349
Craig Topperca7e3e52014-03-10 03:19:03 +0000350 bool isConditionalBranch(const MCInst &Inst) const override {
Benjamin Kramerc22d50e2011-08-08 18:56:44 +0000351 // BCCs with the "always" predicate are unconditional branches.
352 if (Inst.getOpcode() == ARM::Bcc && Inst.getOperand(1).getImm()==ARMCC::AL)
353 return false;
354 return MCInstrAnalysis::isConditionalBranch(Inst);
355 }
356
Ahmed Bougachaaa790682013-05-24 01:07:04 +0000357 bool evaluateBranch(const MCInst &Inst, uint64_t Addr,
Craig Topperca7e3e52014-03-10 03:19:03 +0000358 uint64_t Size, uint64_t &Target) const override {
Benjamin Kramerc22d50e2011-08-08 18:56:44 +0000359 // We only handle PCRel branches for now.
360 if (Info->get(Inst.getOpcode()).OpInfo[0].OperandType!=MCOI::OPERAND_PCREL)
Ahmed Bougachaaa790682013-05-24 01:07:04 +0000361 return false;
Benjamin Kramerc22d50e2011-08-08 18:56:44 +0000362
363 int64_t Imm = Inst.getOperand(0).getImm();
364 // FIXME: This is not right for thumb.
Ahmed Bougachaaa790682013-05-24 01:07:04 +0000365 Target = Addr+Imm+8; // In ARM mode the PC is always off by 8 bytes.
366 return true;
Benjamin Kramerc22d50e2011-08-08 18:56:44 +0000367 }
368};
369
Alexander Kornienkof00654e2015-06-23 09:49:53 +0000370}
Benjamin Kramerc22d50e2011-08-08 18:56:44 +0000371
372static MCInstrAnalysis *createARMMCInstrAnalysis(const MCInstrInfo *Info) {
373 return new ARMMCInstrAnalysis(Info);
374}
Evan Chengad5f4852011-07-23 00:00:19 +0000375
Evan Cheng8c886a42011-07-22 21:58:54 +0000376// Force static initialization.
377extern "C" void LLVMInitializeARMTargetMC() {
Rafael Espindola69244c32015-03-18 23:15:49 +0000378 for (Target *T : {&TheARMLETarget, &TheARMBETarget, &TheThumbLETarget,
379 &TheThumbBETarget}) {
380 // Register the MC asm info.
381 RegisterMCAsmInfoFn X(*T, createARMMCAsmInfo);
Evan Cheng8c886a42011-07-22 21:58:54 +0000382
Rafael Espindola69244c32015-03-18 23:15:49 +0000383 // Register the MC codegen info.
384 TargetRegistry::RegisterMCCodeGenInfo(*T, createARMMCCodeGenInfo);
Evan Cheng8c886a42011-07-22 21:58:54 +0000385
Rafael Espindola69244c32015-03-18 23:15:49 +0000386 // Register the MC instruction info.
387 TargetRegistry::RegisterMCInstrInfo(*T, createARMMCInstrInfo);
Evan Cheng8c886a42011-07-22 21:58:54 +0000388
Rafael Espindola69244c32015-03-18 23:15:49 +0000389 // Register the MC register info.
390 TargetRegistry::RegisterMCRegInfo(*T, createARMMCRegisterInfo);
Evan Cheng8c886a42011-07-22 21:58:54 +0000391
Rafael Espindola69244c32015-03-18 23:15:49 +0000392 // Register the MC subtarget info.
393 TargetRegistry::RegisterMCSubtargetInfo(*T,
394 ARM_MC::createARMMCSubtargetInfo);
Evan Chengad5f4852011-07-23 00:00:19 +0000395
Rafael Espindola69244c32015-03-18 23:15:49 +0000396 // Register the MC instruction analyzer.
397 TargetRegistry::RegisterMCInstrAnalysis(*T, createARMMCInstrAnalysis);
398
Rafael Espindolacd584a82015-03-19 01:50:16 +0000399 TargetRegistry::RegisterELFStreamer(*T, createELFStreamer);
400 TargetRegistry::RegisterCOFFStreamer(*T, createARMWinCOFFStreamer);
401 TargetRegistry::RegisterMachOStreamer(*T, createARMMachOStreamer);
402
403 // Register the obj target streamer.
404 TargetRegistry::RegisterObjectTargetStreamer(*T,
405 createARMObjectTargetStreamer);
Rafael Espindola69244c32015-03-18 23:15:49 +0000406
407 // Register the asm streamer.
408 TargetRegistry::RegisterAsmTargetStreamer(*T, createARMTargetAsmStreamer);
409
410 // Register the null TargetStreamer.
411 TargetRegistry::RegisterNullTargetStreamer(*T, createARMNullTargetStreamer);
412
413 // Register the MCInstPrinter.
414 TargetRegistry::RegisterMCInstPrinter(*T, createARMMCInstPrinter);
415
416 // Register the MC relocation info.
417 TargetRegistry::RegisterMCRelocationInfo(*T, createARMMCRelocationInfo);
418 }
Evan Cheng4d6c9d72011-08-23 20:15:21 +0000419
Evan Chengad5f4852011-07-23 00:00:19 +0000420 // Register the MC Code Emitter
Rafael Espindola69244c32015-03-18 23:15:49 +0000421 for (Target *T : {&TheARMLETarget, &TheThumbLETarget})
422 TargetRegistry::RegisterMCCodeEmitter(*T, createARMLEMCCodeEmitter);
423 for (Target *T : {&TheARMBETarget, &TheThumbBETarget})
424 TargetRegistry::RegisterMCCodeEmitter(*T, createARMBEMCCodeEmitter);
Evan Chengad5f4852011-07-23 00:00:19 +0000425
426 // Register the asm backend.
Christian Pirkerdc9ff752014-04-01 15:19:30 +0000427 TargetRegistry::RegisterMCAsmBackend(TheARMLETarget, createARMLEAsmBackend);
428 TargetRegistry::RegisterMCAsmBackend(TheARMBETarget, createARMBEAsmBackend);
429 TargetRegistry::RegisterMCAsmBackend(TheThumbLETarget,
430 createThumbLEAsmBackend);
431 TargetRegistry::RegisterMCAsmBackend(TheThumbBETarget,
432 createThumbBEAsmBackend);
Evan Cheng2129f592011-07-19 06:37:02 +0000433}