1 //===-- ARMAsmPrinter.cpp - Print machine code to an ARM .s file ----------===//
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 contains a printer that converts from our internal representation
11 // of machine-dependent LLVM code to GAS-format ARM assembly language.
13 //===----------------------------------------------------------------------===//
15 #include "ARMAsmPrinter.h"
17 #include "ARMConstantPoolValue.h"
18 #include "ARMFPUName.h"
19 #include "ARMMachineFunctionInfo.h"
20 #include "ARMTargetMachine.h"
21 #include "ARMTargetObjectFile.h"
22 #include "InstPrinter/ARMInstPrinter.h"
23 #include "MCTargetDesc/ARMAddressingModes.h"
24 #include "MCTargetDesc/ARMMCExpr.h"
25 #include "llvm/ADT/SetVector.h"
26 #include "llvm/ADT/SmallString.h"
27 #include "llvm/CodeGen/MachineFunctionPass.h"
28 #include "llvm/CodeGen/MachineJumpTableInfo.h"
29 #include "llvm/CodeGen/MachineModuleInfoImpls.h"
30 #include "llvm/IR/Constants.h"
31 #include "llvm/IR/DataLayout.h"
32 #include "llvm/IR/DebugInfo.h"
33 #include "llvm/IR/Mangler.h"
34 #include "llvm/IR/Module.h"
35 #include "llvm/IR/Type.h"
36 #include "llvm/MC/MCAsmInfo.h"
37 #include "llvm/MC/MCAssembler.h"
38 #include "llvm/MC/MCContext.h"
39 #include "llvm/MC/MCELFStreamer.h"
40 #include "llvm/MC/MCInst.h"
41 #include "llvm/MC/MCInstBuilder.h"
42 #include "llvm/MC/MCObjectStreamer.h"
43 #include "llvm/MC/MCSectionMachO.h"
44 #include "llvm/MC/MCStreamer.h"
45 #include "llvm/MC/MCSymbol.h"
46 #include "llvm/Support/ARMBuildAttributes.h"
47 #include "llvm/Support/COFF.h"
48 #include "llvm/Support/CommandLine.h"
49 #include "llvm/Support/Debug.h"
50 #include "llvm/Support/ELF.h"
51 #include "llvm/Support/ErrorHandling.h"
52 #include "llvm/Support/TargetRegistry.h"
53 #include "llvm/Support/raw_ostream.h"
54 #include "llvm/Target/TargetMachine.h"
58 #define DEBUG_TYPE "asm-printer"
60 void ARMAsmPrinter::EmitFunctionBodyEnd() {
61 // Make sure to terminate any constant pools that were at the end
65 InConstantPool = false;
66 OutStreamer.EmitDataRegion(MCDR_DataRegionEnd);
69 void ARMAsmPrinter::EmitFunctionEntryLabel() {
70 if (AFI->isThumbFunction()) {
71 OutStreamer.EmitAssemblerFlag(MCAF_Code16);
72 OutStreamer.EmitThumbFunc(CurrentFnSym);
75 OutStreamer.EmitLabel(CurrentFnSym);
78 void ARMAsmPrinter::EmitXXStructor(const Constant *CV) {
80 TM.getSubtargetImpl()->getDataLayout()->getTypeAllocSize(CV->getType());
81 assert(Size && "C++ constructor pointer had zero size!");
83 const GlobalValue *GV = dyn_cast<GlobalValue>(CV->stripPointerCasts());
84 assert(GV && "C++ constructor pointer was not a GlobalValue!");
86 const MCExpr *E = MCSymbolRefExpr::Create(GetARMGVSymbol(GV,
88 (Subtarget->isTargetELF()
89 ? MCSymbolRefExpr::VK_ARM_TARGET1
90 : MCSymbolRefExpr::VK_None),
93 OutStreamer.EmitValue(E, Size);
96 /// runOnMachineFunction - This uses the EmitInstruction()
97 /// method to print assembly for each instruction.
99 bool ARMAsmPrinter::runOnMachineFunction(MachineFunction &MF) {
100 AFI = MF.getInfo<ARMFunctionInfo>();
101 MCP = MF.getConstantPool();
103 SetupMachineFunction(MF);
105 if (Subtarget->isTargetCOFF()) {
106 bool Internal = MF.getFunction()->hasInternalLinkage();
107 COFF::SymbolStorageClass Scl = Internal ? COFF::IMAGE_SYM_CLASS_STATIC
108 : COFF::IMAGE_SYM_CLASS_EXTERNAL;
109 int Type = COFF::IMAGE_SYM_DTYPE_FUNCTION << COFF::SCT_COMPLEX_TYPE_SHIFT;
111 OutStreamer.BeginCOFFSymbolDef(CurrentFnSym);
112 OutStreamer.EmitCOFFSymbolStorageClass(Scl);
113 OutStreamer.EmitCOFFSymbolType(Type);
114 OutStreamer.EndCOFFSymbolDef();
117 // Have common code print out the function header with linkage info etc.
118 EmitFunctionHeader();
120 // Emit the rest of the function body.
123 // If we need V4T thumb mode Register Indirect Jump pads, emit them.
124 // These are created per function, rather than per TU, since it's
125 // relatively easy to exceed the thumb branch range within a TU.
126 if (! ThumbIndirectPads.empty()) {
127 OutStreamer.EmitAssemblerFlag(MCAF_Code16);
129 for (unsigned i = 0, e = ThumbIndirectPads.size(); i < e; i++) {
130 OutStreamer.EmitLabel(ThumbIndirectPads[i].second);
131 EmitToStreamer(OutStreamer, MCInstBuilder(ARM::tBX)
132 .addReg(ThumbIndirectPads[i].first)
133 // Add predicate operands.
137 ThumbIndirectPads.clear();
140 // We didn't modify anything.
144 void ARMAsmPrinter::printOperand(const MachineInstr *MI, int OpNum,
145 raw_ostream &O, const char *Modifier) {
146 const MachineOperand &MO = MI->getOperand(OpNum);
147 unsigned TF = MO.getTargetFlags();
149 switch (MO.getType()) {
150 default: llvm_unreachable("<unknown operand type>");
151 case MachineOperand::MO_Register: {
152 unsigned Reg = MO.getReg();
153 assert(TargetRegisterInfo::isPhysicalRegister(Reg));
154 assert(!MO.getSubReg() && "Subregs should be eliminated!");
155 if(ARM::GPRPairRegClass.contains(Reg)) {
156 const MachineFunction &MF = *MI->getParent()->getParent();
157 const TargetRegisterInfo *TRI = MF.getSubtarget().getRegisterInfo();
158 Reg = TRI->getSubReg(Reg, ARM::gsub_0);
160 O << ARMInstPrinter::getRegisterName(Reg);
163 case MachineOperand::MO_Immediate: {
164 int64_t Imm = MO.getImm();
166 if ((Modifier && strcmp(Modifier, "lo16") == 0) ||
167 (TF == ARMII::MO_LO16))
169 else if ((Modifier && strcmp(Modifier, "hi16") == 0) ||
170 (TF == ARMII::MO_HI16))
175 case MachineOperand::MO_MachineBasicBlock:
176 O << *MO.getMBB()->getSymbol();
178 case MachineOperand::MO_GlobalAddress: {
179 const GlobalValue *GV = MO.getGlobal();
180 if ((Modifier && strcmp(Modifier, "lo16") == 0) ||
181 (TF & ARMII::MO_LO16))
183 else if ((Modifier && strcmp(Modifier, "hi16") == 0) ||
184 (TF & ARMII::MO_HI16))
186 O << *GetARMGVSymbol(GV, TF);
188 printOffset(MO.getOffset(), O);
189 if (TF == ARMII::MO_PLT)
193 case MachineOperand::MO_ConstantPoolIndex:
194 O << *GetCPISymbol(MO.getIndex());
199 //===--------------------------------------------------------------------===//
201 MCSymbol *ARMAsmPrinter::
202 GetARMJTIPICJumpTableLabel2(unsigned uid, unsigned uid2) const {
203 const DataLayout *DL = TM.getSubtargetImpl()->getDataLayout();
204 SmallString<60> Name;
205 raw_svector_ostream(Name) << DL->getPrivateGlobalPrefix() << "JTI"
206 << getFunctionNumber() << '_' << uid << '_' << uid2;
207 return OutContext.GetOrCreateSymbol(Name.str());
211 MCSymbol *ARMAsmPrinter::GetARMSJLJEHLabel() const {
212 const DataLayout *DL = TM.getSubtargetImpl()->getDataLayout();
213 SmallString<60> Name;
214 raw_svector_ostream(Name) << DL->getPrivateGlobalPrefix() << "SJLJEH"
215 << getFunctionNumber();
216 return OutContext.GetOrCreateSymbol(Name.str());
219 bool ARMAsmPrinter::PrintAsmOperand(const MachineInstr *MI, unsigned OpNum,
220 unsigned AsmVariant, const char *ExtraCode,
222 // Does this asm operand have a single letter operand modifier?
223 if (ExtraCode && ExtraCode[0]) {
224 if (ExtraCode[1] != 0) return true; // Unknown modifier.
226 switch (ExtraCode[0]) {
228 // See if this is a generic print operand
229 return AsmPrinter::PrintAsmOperand(MI, OpNum, AsmVariant, ExtraCode, O);
230 case 'a': // Print as a memory address.
231 if (MI->getOperand(OpNum).isReg()) {
233 << ARMInstPrinter::getRegisterName(MI->getOperand(OpNum).getReg())
238 case 'c': // Don't print "#" before an immediate operand.
239 if (!MI->getOperand(OpNum).isImm())
241 O << MI->getOperand(OpNum).getImm();
243 case 'P': // Print a VFP double precision register.
244 case 'q': // Print a NEON quad precision register.
245 printOperand(MI, OpNum, O);
247 case 'y': // Print a VFP single precision register as indexed double.
248 if (MI->getOperand(OpNum).isReg()) {
249 unsigned Reg = MI->getOperand(OpNum).getReg();
250 const TargetRegisterInfo *TRI = MF->getSubtarget().getRegisterInfo();
251 // Find the 'd' register that has this 's' register as a sub-register,
252 // and determine the lane number.
253 for (MCSuperRegIterator SR(Reg, TRI); SR.isValid(); ++SR) {
254 if (!ARM::DPRRegClass.contains(*SR))
256 bool Lane0 = TRI->getSubReg(*SR, ARM::ssub_0) == Reg;
257 O << ARMInstPrinter::getRegisterName(*SR) << (Lane0 ? "[0]" : "[1]");
262 case 'B': // Bitwise inverse of integer or symbol without a preceding #.
263 if (!MI->getOperand(OpNum).isImm())
265 O << ~(MI->getOperand(OpNum).getImm());
267 case 'L': // The low 16 bits of an immediate constant.
268 if (!MI->getOperand(OpNum).isImm())
270 O << (MI->getOperand(OpNum).getImm() & 0xffff);
272 case 'M': { // A register range suitable for LDM/STM.
273 if (!MI->getOperand(OpNum).isReg())
275 const MachineOperand &MO = MI->getOperand(OpNum);
276 unsigned RegBegin = MO.getReg();
277 // This takes advantage of the 2 operand-ness of ldm/stm and that we've
278 // already got the operands in registers that are operands to the
279 // inline asm statement.
281 if (ARM::GPRPairRegClass.contains(RegBegin)) {
282 const TargetRegisterInfo *TRI = MF->getSubtarget().getRegisterInfo();
283 unsigned Reg0 = TRI->getSubReg(RegBegin, ARM::gsub_0);
284 O << ARMInstPrinter::getRegisterName(Reg0) << ", ";
285 RegBegin = TRI->getSubReg(RegBegin, ARM::gsub_1);
287 O << ARMInstPrinter::getRegisterName(RegBegin);
289 // FIXME: The register allocator not only may not have given us the
290 // registers in sequence, but may not be in ascending registers. This
291 // will require changes in the register allocator that'll need to be
292 // propagated down here if the operands change.
293 unsigned RegOps = OpNum + 1;
294 while (MI->getOperand(RegOps).isReg()) {
296 << ARMInstPrinter::getRegisterName(MI->getOperand(RegOps).getReg());
304 case 'R': // The most significant register of a pair.
305 case 'Q': { // The least significant register of a pair.
308 const MachineOperand &FlagsOP = MI->getOperand(OpNum - 1);
309 if (!FlagsOP.isImm())
311 unsigned Flags = FlagsOP.getImm();
313 // This operand may not be the one that actually provides the register. If
314 // it's tied to a previous one then we should refer instead to that one
315 // for registers and their classes.
317 if (InlineAsm::isUseOperandTiedToDef(Flags, TiedIdx)) {
318 for (OpNum = InlineAsm::MIOp_FirstOperand; TiedIdx; --TiedIdx) {
319 unsigned OpFlags = MI->getOperand(OpNum).getImm();
320 OpNum += InlineAsm::getNumOperandRegisters(OpFlags) + 1;
322 Flags = MI->getOperand(OpNum).getImm();
324 // Later code expects OpNum to be pointing at the register rather than
329 unsigned NumVals = InlineAsm::getNumOperandRegisters(Flags);
331 InlineAsm::hasRegClassConstraint(Flags, RC);
332 if (RC == ARM::GPRPairRegClassID) {
335 const MachineOperand &MO = MI->getOperand(OpNum);
338 const TargetRegisterInfo *TRI = MF->getSubtarget().getRegisterInfo();
339 unsigned Reg = TRI->getSubReg(MO.getReg(), ExtraCode[0] == 'Q' ?
340 ARM::gsub_0 : ARM::gsub_1);
341 O << ARMInstPrinter::getRegisterName(Reg);
346 unsigned RegOp = ExtraCode[0] == 'Q' ? OpNum : OpNum + 1;
347 if (RegOp >= MI->getNumOperands())
349 const MachineOperand &MO = MI->getOperand(RegOp);
352 unsigned Reg = MO.getReg();
353 O << ARMInstPrinter::getRegisterName(Reg);
357 case 'e': // The low doubleword register of a NEON quad register.
358 case 'f': { // The high doubleword register of a NEON quad register.
359 if (!MI->getOperand(OpNum).isReg())
361 unsigned Reg = MI->getOperand(OpNum).getReg();
362 if (!ARM::QPRRegClass.contains(Reg))
364 const TargetRegisterInfo *TRI = MF->getSubtarget().getRegisterInfo();
365 unsigned SubReg = TRI->getSubReg(Reg, ExtraCode[0] == 'e' ?
366 ARM::dsub_0 : ARM::dsub_1);
367 O << ARMInstPrinter::getRegisterName(SubReg);
371 // This modifier is not yet supported.
372 case 'h': // A range of VFP/NEON registers suitable for VLD1/VST1.
374 case 'H': { // The highest-numbered register of a pair.
375 const MachineOperand &MO = MI->getOperand(OpNum);
378 const MachineFunction &MF = *MI->getParent()->getParent();
379 const TargetRegisterInfo *TRI = MF.getSubtarget().getRegisterInfo();
380 unsigned Reg = MO.getReg();
381 if(!ARM::GPRPairRegClass.contains(Reg))
383 Reg = TRI->getSubReg(Reg, ARM::gsub_1);
384 O << ARMInstPrinter::getRegisterName(Reg);
390 printOperand(MI, OpNum, O);
394 bool ARMAsmPrinter::PrintAsmMemoryOperand(const MachineInstr *MI,
395 unsigned OpNum, unsigned AsmVariant,
396 const char *ExtraCode,
398 // Does this asm operand have a single letter operand modifier?
399 if (ExtraCode && ExtraCode[0]) {
400 if (ExtraCode[1] != 0) return true; // Unknown modifier.
402 switch (ExtraCode[0]) {
403 case 'A': // A memory operand for a VLD1/VST1 instruction.
404 default: return true; // Unknown modifier.
405 case 'm': // The base register of a memory operand.
406 if (!MI->getOperand(OpNum).isReg())
408 O << ARMInstPrinter::getRegisterName(MI->getOperand(OpNum).getReg());
413 const MachineOperand &MO = MI->getOperand(OpNum);
414 assert(MO.isReg() && "unexpected inline asm memory operand");
415 O << "[" << ARMInstPrinter::getRegisterName(MO.getReg()) << "]";
419 static bool isThumb(const MCSubtargetInfo& STI) {
420 return (STI.getFeatureBits() & ARM::ModeThumb) != 0;
423 void ARMAsmPrinter::emitInlineAsmEnd(const MCSubtargetInfo &StartInfo,
424 const MCSubtargetInfo *EndInfo) const {
425 // If either end mode is unknown (EndInfo == NULL) or different than
426 // the start mode, then restore the start mode.
427 const bool WasThumb = isThumb(StartInfo);
428 if (!EndInfo || WasThumb != isThumb(*EndInfo)) {
429 OutStreamer.EmitAssemblerFlag(WasThumb ? MCAF_Code16 : MCAF_Code32);
433 void ARMAsmPrinter::EmitStartOfAsmFile(Module &M) {
434 if (Subtarget->isTargetMachO()) {
435 Reloc::Model RelocM = TM.getRelocationModel();
436 if (RelocM == Reloc::PIC_ || RelocM == Reloc::DynamicNoPIC) {
437 // Declare all the text sections up front (before the DWARF sections
438 // emitted by AsmPrinter::doInitialization) so the assembler will keep
439 // them together at the beginning of the object file. This helps
440 // avoid out-of-range branches that are due a fundamental limitation of
441 // the way symbol offsets are encoded with the current Darwin ARM
443 const TargetLoweringObjectFileMachO &TLOFMacho =
444 static_cast<const TargetLoweringObjectFileMachO &>(
445 getObjFileLowering());
447 // Collect the set of sections our functions will go into.
448 SetVector<const MCSection *, SmallVector<const MCSection *, 8>,
449 SmallPtrSet<const MCSection *, 8> > TextSections;
450 // Default text section comes first.
451 TextSections.insert(TLOFMacho.getTextSection());
452 // Now any user defined text sections from function attributes.
453 for (Module::iterator F = M.begin(), e = M.end(); F != e; ++F)
454 if (!F->isDeclaration() && !F->hasAvailableExternallyLinkage())
455 TextSections.insert(TLOFMacho.SectionForGlobal(F, *Mang, TM));
456 // Now the coalescable sections.
457 TextSections.insert(TLOFMacho.getTextCoalSection());
458 TextSections.insert(TLOFMacho.getConstTextCoalSection());
460 // Emit the sections in the .s file header to fix the order.
461 for (unsigned i = 0, e = TextSections.size(); i != e; ++i)
462 OutStreamer.SwitchSection(TextSections[i]);
464 if (RelocM == Reloc::DynamicNoPIC) {
465 const MCSection *sect =
466 OutContext.getMachOSection("__TEXT", "__symbol_stub4",
467 MachO::S_SYMBOL_STUBS,
468 12, SectionKind::getText());
469 OutStreamer.SwitchSection(sect);
471 const MCSection *sect =
472 OutContext.getMachOSection("__TEXT", "__picsymbolstub4",
473 MachO::S_SYMBOL_STUBS,
474 16, SectionKind::getText());
475 OutStreamer.SwitchSection(sect);
477 const MCSection *StaticInitSect =
478 OutContext.getMachOSection("__TEXT", "__StaticInit",
480 MachO::S_ATTR_PURE_INSTRUCTIONS,
481 SectionKind::getText());
482 OutStreamer.SwitchSection(StaticInitSect);
485 // Compiling with debug info should not affect the code
486 // generation. Ensure the cstring section comes before the
487 // optional __DWARF secion. Otherwise, PC-relative loads would
488 // have to use different instruction sequences at "-g" in order to
489 // reach global data in the same object file.
490 OutStreamer.SwitchSection(getObjFileLowering().getCStringSection());
493 // Use unified assembler syntax.
494 OutStreamer.EmitAssemblerFlag(MCAF_SyntaxUnified);
496 // Emit ARM Build Attributes
497 if (Subtarget->isTargetELF())
500 if (!M.getModuleInlineAsm().empty() && Subtarget->isThumb())
501 OutStreamer.EmitAssemblerFlag(MCAF_Code16);
505 emitNonLazySymbolPointer(MCStreamer &OutStreamer, MCSymbol *StubLabel,
506 MachineModuleInfoImpl::StubValueTy &MCSym) {
508 OutStreamer.EmitLabel(StubLabel);
509 // .indirect_symbol _foo
510 OutStreamer.EmitSymbolAttribute(MCSym.getPointer(), MCSA_IndirectSymbol);
513 // External to current translation unit.
514 OutStreamer.EmitIntValue(0, 4/*size*/);
516 // Internal to current translation unit.
518 // When we place the LSDA into the TEXT section, the type info
519 // pointers need to be indirect and pc-rel. We accomplish this by
520 // using NLPs; however, sometimes the types are local to the file.
521 // We need to fill in the value for the NLP in those cases.
522 OutStreamer.EmitValue(
523 MCSymbolRefExpr::Create(MCSym.getPointer(), OutStreamer.getContext()),
528 void ARMAsmPrinter::EmitEndOfAsmFile(Module &M) {
529 if (Subtarget->isTargetMachO()) {
530 // All darwin targets use mach-o.
531 const TargetLoweringObjectFileMachO &TLOFMacho =
532 static_cast<const TargetLoweringObjectFileMachO &>(getObjFileLowering());
533 MachineModuleInfoMachO &MMIMacho =
534 MMI->getObjFileInfo<MachineModuleInfoMachO>();
536 // Output non-lazy-pointers for external and common global variables.
537 MachineModuleInfoMachO::SymbolListTy Stubs = MMIMacho.GetGVStubList();
539 if (!Stubs.empty()) {
540 // Switch with ".non_lazy_symbol_pointer" directive.
541 OutStreamer.SwitchSection(TLOFMacho.getNonLazySymbolPointerSection());
544 for (auto &Stub : Stubs)
545 emitNonLazySymbolPointer(OutStreamer, Stub.first, Stub.second);
548 OutStreamer.AddBlankLine();
551 Stubs = MMIMacho.GetHiddenGVStubList();
552 if (!Stubs.empty()) {
553 OutStreamer.SwitchSection(TLOFMacho.getNonLazySymbolPointerSection());
556 for (auto &Stub : Stubs)
557 emitNonLazySymbolPointer(OutStreamer, Stub.first, Stub.second);
560 OutStreamer.AddBlankLine();
563 // Funny Darwin hack: This flag tells the linker that no global symbols
564 // contain code that falls through to other global symbols (e.g. the obvious
565 // implementation of multiple entry points). If this doesn't occur, the
566 // linker can safely perform dead code stripping. Since LLVM never
567 // generates code that does this, it is always safe to set.
568 OutStreamer.EmitAssemblerFlag(MCAF_SubsectionsViaSymbols);
571 // Emit a .data.rel section containing any stubs that were created.
572 if (Subtarget->isTargetELF()) {
573 const TargetLoweringObjectFileELF &TLOFELF =
574 static_cast<const TargetLoweringObjectFileELF &>(getObjFileLowering());
576 MachineModuleInfoELF &MMIELF = MMI->getObjFileInfo<MachineModuleInfoELF>();
578 // Output stubs for external and common global variables.
579 MachineModuleInfoELF::SymbolListTy Stubs = MMIELF.GetGVStubList();
580 if (!Stubs.empty()) {
581 OutStreamer.SwitchSection(TLOFELF.getDataRelSection());
582 const DataLayout *TD = TM.getSubtargetImpl()->getDataLayout();
584 for (auto &stub: Stubs) {
585 OutStreamer.EmitLabel(stub.first);
586 OutStreamer.EmitSymbolValue(stub.second.getPointer(),
587 TD->getPointerSize(0));
594 //===----------------------------------------------------------------------===//
595 // Helper routines for EmitStartOfAsmFile() and EmitEndOfAsmFile()
597 // The following seem like one-off assembler flags, but they actually need
598 // to appear in the .ARM.attributes section in ELF.
599 // Instead of subclassing the MCELFStreamer, we do the work here.
601 static ARMBuildAttrs::CPUArch getArchForCPU(StringRef CPU,
602 const ARMSubtarget *Subtarget) {
604 return ARMBuildAttrs::v5TEJ;
606 if (Subtarget->hasV8Ops())
607 return ARMBuildAttrs::v8;
608 else if (Subtarget->hasV7Ops()) {
609 if (Subtarget->isMClass() && Subtarget->hasThumb2DSP())
610 return ARMBuildAttrs::v7E_M;
611 return ARMBuildAttrs::v7;
612 } else if (Subtarget->hasV6T2Ops())
613 return ARMBuildAttrs::v6T2;
614 else if (Subtarget->hasV6MOps())
615 return ARMBuildAttrs::v6S_M;
616 else if (Subtarget->hasV6Ops())
617 return ARMBuildAttrs::v6;
618 else if (Subtarget->hasV5TEOps())
619 return ARMBuildAttrs::v5TE;
620 else if (Subtarget->hasV5TOps())
621 return ARMBuildAttrs::v5T;
622 else if (Subtarget->hasV4TOps())
623 return ARMBuildAttrs::v4T;
625 return ARMBuildAttrs::v4;
628 void ARMAsmPrinter::emitAttributes() {
629 MCTargetStreamer &TS = *OutStreamer.getTargetStreamer();
630 ARMTargetStreamer &ATS = static_cast<ARMTargetStreamer &>(TS);
632 ATS.switchVendor("aeabi");
634 std::string CPUString = Subtarget->getCPUString();
636 // FIXME: remove krait check when GNU tools support krait cpu
637 if (CPUString != "generic" && CPUString != "krait")
638 ATS.emitTextAttribute(ARMBuildAttrs::CPU_name, CPUString);
640 ATS.emitAttribute(ARMBuildAttrs::CPU_arch,
641 getArchForCPU(CPUString, Subtarget));
643 // Tag_CPU_arch_profile must have the default value of 0 when "Architecture
644 // profile is not applicable (e.g. pre v7, or cross-profile code)".
645 if (Subtarget->hasV7Ops()) {
646 if (Subtarget->isAClass()) {
647 ATS.emitAttribute(ARMBuildAttrs::CPU_arch_profile,
648 ARMBuildAttrs::ApplicationProfile);
649 } else if (Subtarget->isRClass()) {
650 ATS.emitAttribute(ARMBuildAttrs::CPU_arch_profile,
651 ARMBuildAttrs::RealTimeProfile);
652 } else if (Subtarget->isMClass()) {
653 ATS.emitAttribute(ARMBuildAttrs::CPU_arch_profile,
654 ARMBuildAttrs::MicroControllerProfile);
658 ATS.emitAttribute(ARMBuildAttrs::ARM_ISA_use, Subtarget->hasARMOps() ?
659 ARMBuildAttrs::Allowed : ARMBuildAttrs::Not_Allowed);
660 if (Subtarget->isThumb1Only()) {
661 ATS.emitAttribute(ARMBuildAttrs::THUMB_ISA_use,
662 ARMBuildAttrs::Allowed);
663 } else if (Subtarget->hasThumb2()) {
664 ATS.emitAttribute(ARMBuildAttrs::THUMB_ISA_use,
665 ARMBuildAttrs::AllowThumb32);
668 if (Subtarget->hasNEON()) {
669 /* NEON is not exactly a VFP architecture, but GAS emit one of
670 * neon/neon-fp-armv8/neon-vfpv4/vfpv3/vfpv2 for .fpu parameters */
671 if (Subtarget->hasFPARMv8()) {
672 if (Subtarget->hasCrypto())
673 ATS.emitFPU(ARM::CRYPTO_NEON_FP_ARMV8);
675 ATS.emitFPU(ARM::NEON_FP_ARMV8);
677 else if (Subtarget->hasVFP4())
678 ATS.emitFPU(ARM::NEON_VFPV4);
680 ATS.emitFPU(ARM::NEON);
681 // Emit Tag_Advanced_SIMD_arch for ARMv8 architecture
682 if (Subtarget->hasV8Ops())
683 ATS.emitAttribute(ARMBuildAttrs::Advanced_SIMD_arch,
684 ARMBuildAttrs::AllowNeonARMv8);
686 if (Subtarget->hasFPARMv8())
687 // FPv5 and FP-ARMv8 have the same instructions, so are modeled as one
688 // FPU, but there are two different names for it depending on the CPU.
689 ATS.emitFPU(Subtarget->hasD16() ? ARM::FPV5_D16 : ARM::FP_ARMV8);
690 else if (Subtarget->hasVFP4())
691 ATS.emitFPU(Subtarget->hasD16() ? ARM::VFPV4_D16 : ARM::VFPV4);
692 else if (Subtarget->hasVFP3())
693 ATS.emitFPU(Subtarget->hasD16() ? ARM::VFPV3_D16 : ARM::VFPV3);
694 else if (Subtarget->hasVFP2())
695 ATS.emitFPU(ARM::VFPV2);
698 if (TM.getRelocationModel() == Reloc::PIC_) {
699 // PIC specific attributes.
700 ATS.emitAttribute(ARMBuildAttrs::ABI_PCS_RW_data,
701 ARMBuildAttrs::AddressRWPCRel);
702 ATS.emitAttribute(ARMBuildAttrs::ABI_PCS_RO_data,
703 ARMBuildAttrs::AddressROPCRel);
704 ATS.emitAttribute(ARMBuildAttrs::ABI_PCS_GOT_use,
705 ARMBuildAttrs::AddressGOT);
707 // Allow direct addressing of imported data for all other relocation models.
708 ATS.emitAttribute(ARMBuildAttrs::ABI_PCS_GOT_use,
709 ARMBuildAttrs::AddressDirect);
712 // Signal various FP modes.
713 if (!TM.Options.UnsafeFPMath) {
714 ATS.emitAttribute(ARMBuildAttrs::ABI_FP_denormal,
715 ARMBuildAttrs::IEEEDenormals);
716 ATS.emitAttribute(ARMBuildAttrs::ABI_FP_exceptions,
717 ARMBuildAttrs::Allowed);
719 // If the user has permitted this code to choose the IEEE 754
720 // rounding at run-time, emit the rounding attribute.
721 if (TM.Options.HonorSignDependentRoundingFPMathOption)
722 ATS.emitAttribute(ARMBuildAttrs::ABI_FP_rounding,
723 ARMBuildAttrs::Allowed);
725 if (!Subtarget->hasVFP2()) {
726 // When the target doesn't have an FPU (by design or
727 // intention), the assumptions made on the software support
728 // mirror that of the equivalent hardware support *if it
729 // existed*. For v7 and better we indicate that denormals are
730 // flushed preserving sign, and for V6 we indicate that
731 // denormals are flushed to positive zero.
732 if (Subtarget->hasV7Ops())
733 ATS.emitAttribute(ARMBuildAttrs::ABI_FP_denormal,
734 ARMBuildAttrs::PreserveFPSign);
735 } else if (Subtarget->hasVFP3()) {
736 // In VFPv4, VFPv4U, VFPv3, or VFPv3U, it is preserved. That is,
737 // the sign bit of the zero matches the sign bit of the input or
738 // result that is being flushed to zero.
739 ATS.emitAttribute(ARMBuildAttrs::ABI_FP_denormal,
740 ARMBuildAttrs::PreserveFPSign);
742 // For VFPv2 implementations it is implementation defined as
743 // to whether denormals are flushed to positive zero or to
744 // whatever the sign of zero is (ARM v7AR ARM 2.7.5). Historically
745 // LLVM has chosen to flush this to positive zero (most likely for
746 // GCC compatibility), so that's the chosen value here (the
747 // absence of its emission implies zero).
750 // TM.Options.NoInfsFPMath && TM.Options.NoNaNsFPMath is the
751 // equivalent of GCC's -ffinite-math-only flag.
752 if (TM.Options.NoInfsFPMath && TM.Options.NoNaNsFPMath)
753 ATS.emitAttribute(ARMBuildAttrs::ABI_FP_number_model,
754 ARMBuildAttrs::Allowed);
756 ATS.emitAttribute(ARMBuildAttrs::ABI_FP_number_model,
757 ARMBuildAttrs::AllowIEE754);
759 if (Subtarget->allowsUnalignedMem())
760 ATS.emitAttribute(ARMBuildAttrs::CPU_unaligned_access,
761 ARMBuildAttrs::Allowed);
763 ATS.emitAttribute(ARMBuildAttrs::CPU_unaligned_access,
764 ARMBuildAttrs::Not_Allowed);
766 // FIXME: add more flags to ARMBuildAttributes.h
767 // 8-bytes alignment stuff.
768 ATS.emitAttribute(ARMBuildAttrs::ABI_align_needed, 1);
769 ATS.emitAttribute(ARMBuildAttrs::ABI_align_preserved, 1);
771 // ABI_HardFP_use attribute to indicate single precision FP.
772 if (Subtarget->isFPOnlySP())
773 ATS.emitAttribute(ARMBuildAttrs::ABI_HardFP_use,
774 ARMBuildAttrs::HardFPSinglePrecision);
776 // Hard float. Use both S and D registers and conform to AAPCS-VFP.
777 if (Subtarget->isAAPCS_ABI() && TM.Options.FloatABIType == FloatABI::Hard)
778 ATS.emitAttribute(ARMBuildAttrs::ABI_VFP_args, ARMBuildAttrs::HardFPAAPCS);
780 // FIXME: Should we signal R9 usage?
782 if (Subtarget->hasFP16())
783 ATS.emitAttribute(ARMBuildAttrs::FP_HP_extension, ARMBuildAttrs::AllowHPFP);
785 if (Subtarget->hasMPExtension())
786 ATS.emitAttribute(ARMBuildAttrs::MPextension_use, ARMBuildAttrs::AllowMP);
788 // Hardware divide in ARM mode is part of base arch, starting from ARMv8.
789 // If only Thumb hwdiv is present, it must also be in base arch (ARMv7-R/M).
790 // It is not possible to produce DisallowDIV: if hwdiv is present in the base
791 // arch, supplying -hwdiv downgrades the effective arch, via ClearImpliedBits.
792 // AllowDIVExt is only emitted if hwdiv isn't available in the base arch;
793 // otherwise, the default value (AllowDIVIfExists) applies.
794 if (Subtarget->hasDivideInARMMode() && !Subtarget->hasV8Ops())
795 ATS.emitAttribute(ARMBuildAttrs::DIV_use, ARMBuildAttrs::AllowDIVExt);
798 if (const Module *SourceModule = MMI->getModule()) {
799 // ABI_PCS_wchar_t to indicate wchar_t width
800 // FIXME: There is no way to emit value 0 (wchar_t prohibited).
801 if (auto WCharWidthValue = mdconst::extract_or_null<ConstantInt>(
802 SourceModule->getModuleFlag("wchar_size"))) {
803 int WCharWidth = WCharWidthValue->getZExtValue();
804 assert((WCharWidth == 2 || WCharWidth == 4) &&
805 "wchar_t width must be 2 or 4 bytes");
806 ATS.emitAttribute(ARMBuildAttrs::ABI_PCS_wchar_t, WCharWidth);
809 // ABI_enum_size to indicate enum width
810 // FIXME: There is no way to emit value 0 (enums prohibited) or value 3
811 // (all enums contain a value needing 32 bits to encode).
812 if (auto EnumWidthValue = mdconst::extract_or_null<ConstantInt>(
813 SourceModule->getModuleFlag("min_enum_size"))) {
814 int EnumWidth = EnumWidthValue->getZExtValue();
815 assert((EnumWidth == 1 || EnumWidth == 4) &&
816 "Minimum enum width must be 1 or 4 bytes");
817 int EnumBuildAttr = EnumWidth == 1 ? 1 : 2;
818 ATS.emitAttribute(ARMBuildAttrs::ABI_enum_size, EnumBuildAttr);
823 // TODO: We currently only support either reserving the register, or treating
824 // it as another callee-saved register, but not as SB or a TLS pointer; It
825 // would instead be nicer to push this from the frontend as metadata, as we do
826 // for the wchar and enum size tags
827 if (Subtarget->isR9Reserved())
828 ATS.emitAttribute(ARMBuildAttrs::ABI_PCS_R9_use,
829 ARMBuildAttrs::R9Reserved);
831 ATS.emitAttribute(ARMBuildAttrs::ABI_PCS_R9_use,
832 ARMBuildAttrs::R9IsGPR);
834 if (Subtarget->hasTrustZone() && Subtarget->hasVirtualization())
835 ATS.emitAttribute(ARMBuildAttrs::Virtualization_use,
836 ARMBuildAttrs::AllowTZVirtualization);
837 else if (Subtarget->hasTrustZone())
838 ATS.emitAttribute(ARMBuildAttrs::Virtualization_use,
839 ARMBuildAttrs::AllowTZ);
840 else if (Subtarget->hasVirtualization())
841 ATS.emitAttribute(ARMBuildAttrs::Virtualization_use,
842 ARMBuildAttrs::AllowVirtualization);
844 ATS.finishAttributeSection();
847 //===----------------------------------------------------------------------===//
849 static MCSymbol *getPICLabel(const char *Prefix, unsigned FunctionNumber,
850 unsigned LabelId, MCContext &Ctx) {
852 MCSymbol *Label = Ctx.GetOrCreateSymbol(Twine(Prefix)
853 + "PC" + Twine(FunctionNumber) + "_" + Twine(LabelId));
857 static MCSymbolRefExpr::VariantKind
858 getModifierVariantKind(ARMCP::ARMCPModifier Modifier) {
860 case ARMCP::no_modifier: return MCSymbolRefExpr::VK_None;
861 case ARMCP::TLSGD: return MCSymbolRefExpr::VK_TLSGD;
862 case ARMCP::TPOFF: return MCSymbolRefExpr::VK_TPOFF;
863 case ARMCP::GOTTPOFF: return MCSymbolRefExpr::VK_GOTTPOFF;
864 case ARMCP::GOT: return MCSymbolRefExpr::VK_GOT;
865 case ARMCP::GOTOFF: return MCSymbolRefExpr::VK_GOTOFF;
867 llvm_unreachable("Invalid ARMCPModifier!");
870 MCSymbol *ARMAsmPrinter::GetARMGVSymbol(const GlobalValue *GV,
871 unsigned char TargetFlags) {
872 if (Subtarget->isTargetMachO()) {
873 bool IsIndirect = (TargetFlags & ARMII::MO_NONLAZY) &&
874 Subtarget->GVIsIndirectSymbol(GV, TM.getRelocationModel());
877 return getSymbol(GV);
879 // FIXME: Remove this when Darwin transition to @GOT like syntax.
880 MCSymbol *MCSym = getSymbolWithGlobalValueBase(GV, "$non_lazy_ptr");
881 MachineModuleInfoMachO &MMIMachO =
882 MMI->getObjFileInfo<MachineModuleInfoMachO>();
883 MachineModuleInfoImpl::StubValueTy &StubSym =
884 GV->hasHiddenVisibility() ? MMIMachO.getHiddenGVStubEntry(MCSym)
885 : MMIMachO.getGVStubEntry(MCSym);
886 if (!StubSym.getPointer())
887 StubSym = MachineModuleInfoImpl::StubValueTy(getSymbol(GV),
888 !GV->hasInternalLinkage());
890 } else if (Subtarget->isTargetCOFF()) {
891 assert(Subtarget->isTargetWindows() &&
892 "Windows is the only supported COFF target");
894 bool IsIndirect = (TargetFlags & ARMII::MO_DLLIMPORT);
896 return getSymbol(GV);
898 SmallString<128> Name;
900 getNameWithPrefix(Name, GV);
902 return OutContext.GetOrCreateSymbol(Name);
903 } else if (Subtarget->isTargetELF()) {
904 return getSymbol(GV);
906 llvm_unreachable("unexpected target");
910 EmitMachineConstantPoolValue(MachineConstantPoolValue *MCPV) {
911 const DataLayout *DL = TM.getSubtargetImpl()->getDataLayout();
913 TM.getSubtargetImpl()->getDataLayout()->getTypeAllocSize(MCPV->getType());
915 ARMConstantPoolValue *ACPV = static_cast<ARMConstantPoolValue*>(MCPV);
918 if (ACPV->isLSDA()) {
919 SmallString<128> Str;
920 raw_svector_ostream OS(Str);
921 OS << DL->getPrivateGlobalPrefix() << "_LSDA_" << getFunctionNumber();
922 MCSym = OutContext.GetOrCreateSymbol(OS.str());
923 } else if (ACPV->isBlockAddress()) {
924 const BlockAddress *BA =
925 cast<ARMConstantPoolConstant>(ACPV)->getBlockAddress();
926 MCSym = GetBlockAddressSymbol(BA);
927 } else if (ACPV->isGlobalValue()) {
928 const GlobalValue *GV = cast<ARMConstantPoolConstant>(ACPV)->getGV();
930 // On Darwin, const-pool entries may get the "FOO$non_lazy_ptr" mangling, so
931 // flag the global as MO_NONLAZY.
932 unsigned char TF = Subtarget->isTargetMachO() ? ARMII::MO_NONLAZY : 0;
933 MCSym = GetARMGVSymbol(GV, TF);
934 } else if (ACPV->isMachineBasicBlock()) {
935 const MachineBasicBlock *MBB = cast<ARMConstantPoolMBB>(ACPV)->getMBB();
936 MCSym = MBB->getSymbol();
938 assert(ACPV->isExtSymbol() && "unrecognized constant pool value");
939 const char *Sym = cast<ARMConstantPoolSymbol>(ACPV)->getSymbol();
940 MCSym = GetExternalSymbolSymbol(Sym);
943 // Create an MCSymbol for the reference.
945 MCSymbolRefExpr::Create(MCSym, getModifierVariantKind(ACPV->getModifier()),
948 if (ACPV->getPCAdjustment()) {
949 MCSymbol *PCLabel = getPICLabel(DL->getPrivateGlobalPrefix(),
953 const MCExpr *PCRelExpr = MCSymbolRefExpr::Create(PCLabel, OutContext);
955 MCBinaryExpr::CreateAdd(PCRelExpr,
956 MCConstantExpr::Create(ACPV->getPCAdjustment(),
959 if (ACPV->mustAddCurrentAddress()) {
960 // We want "(<expr> - .)", but MC doesn't have a concept of the '.'
961 // label, so just emit a local label end reference that instead.
962 MCSymbol *DotSym = OutContext.CreateTempSymbol();
963 OutStreamer.EmitLabel(DotSym);
964 const MCExpr *DotExpr = MCSymbolRefExpr::Create(DotSym, OutContext);
965 PCRelExpr = MCBinaryExpr::CreateSub(PCRelExpr, DotExpr, OutContext);
967 Expr = MCBinaryExpr::CreateSub(Expr, PCRelExpr, OutContext);
969 OutStreamer.EmitValue(Expr, Size);
972 void ARMAsmPrinter::EmitJumpTable(const MachineInstr *MI) {
973 unsigned Opcode = MI->getOpcode();
975 if (Opcode == ARM::BR_JTadd)
977 else if (Opcode == ARM::BR_JTm)
980 const MachineOperand &MO1 = MI->getOperand(OpNum);
981 const MachineOperand &MO2 = MI->getOperand(OpNum+1); // Unique Id
982 unsigned JTI = MO1.getIndex();
984 // Emit a label for the jump table.
985 MCSymbol *JTISymbol = GetARMJTIPICJumpTableLabel2(JTI, MO2.getImm());
986 OutStreamer.EmitLabel(JTISymbol);
988 // Mark the jump table as data-in-code.
989 OutStreamer.EmitDataRegion(MCDR_DataRegionJT32);
991 // Emit each entry of the table.
992 const MachineJumpTableInfo *MJTI = MF->getJumpTableInfo();
993 const std::vector<MachineJumpTableEntry> &JT = MJTI->getJumpTables();
994 const std::vector<MachineBasicBlock*> &JTBBs = JT[JTI].MBBs;
996 for (unsigned i = 0, e = JTBBs.size(); i != e; ++i) {
997 MachineBasicBlock *MBB = JTBBs[i];
998 // Construct an MCExpr for the entry. We want a value of the form:
999 // (BasicBlockAddr - TableBeginAddr)
1001 // For example, a table with entries jumping to basic blocks BB0 and BB1
1004 // .word (LBB0 - LJTI_0_0)
1005 // .word (LBB1 - LJTI_0_0)
1006 const MCExpr *Expr = MCSymbolRefExpr::Create(MBB->getSymbol(), OutContext);
1008 if (TM.getRelocationModel() == Reloc::PIC_)
1009 Expr = MCBinaryExpr::CreateSub(Expr, MCSymbolRefExpr::Create(JTISymbol,
1012 // If we're generating a table of Thumb addresses in static relocation
1013 // model, we need to add one to keep interworking correctly.
1014 else if (AFI->isThumbFunction())
1015 Expr = MCBinaryExpr::CreateAdd(Expr, MCConstantExpr::Create(1,OutContext),
1017 OutStreamer.EmitValue(Expr, 4);
1019 // Mark the end of jump table data-in-code region.
1020 OutStreamer.EmitDataRegion(MCDR_DataRegionEnd);
1023 void ARMAsmPrinter::EmitJump2Table(const MachineInstr *MI) {
1024 unsigned Opcode = MI->getOpcode();
1025 int OpNum = (Opcode == ARM::t2BR_JT) ? 2 : 1;
1026 const MachineOperand &MO1 = MI->getOperand(OpNum);
1027 const MachineOperand &MO2 = MI->getOperand(OpNum+1); // Unique Id
1028 unsigned JTI = MO1.getIndex();
1030 MCSymbol *JTISymbol = GetARMJTIPICJumpTableLabel2(JTI, MO2.getImm());
1031 OutStreamer.EmitLabel(JTISymbol);
1033 // Emit each entry of the table.
1034 const MachineJumpTableInfo *MJTI = MF->getJumpTableInfo();
1035 const std::vector<MachineJumpTableEntry> &JT = MJTI->getJumpTables();
1036 const std::vector<MachineBasicBlock*> &JTBBs = JT[JTI].MBBs;
1037 unsigned OffsetWidth = 4;
1038 if (MI->getOpcode() == ARM::t2TBB_JT) {
1040 // Mark the jump table as data-in-code.
1041 OutStreamer.EmitDataRegion(MCDR_DataRegionJT8);
1042 } else if (MI->getOpcode() == ARM::t2TBH_JT) {
1044 // Mark the jump table as data-in-code.
1045 OutStreamer.EmitDataRegion(MCDR_DataRegionJT16);
1048 for (unsigned i = 0, e = JTBBs.size(); i != e; ++i) {
1049 MachineBasicBlock *MBB = JTBBs[i];
1050 const MCExpr *MBBSymbolExpr = MCSymbolRefExpr::Create(MBB->getSymbol(),
1052 // If this isn't a TBB or TBH, the entries are direct branch instructions.
1053 if (OffsetWidth == 4) {
1054 EmitToStreamer(OutStreamer, MCInstBuilder(ARM::t2B)
1055 .addExpr(MBBSymbolExpr)
1060 // Otherwise it's an offset from the dispatch instruction. Construct an
1061 // MCExpr for the entry. We want a value of the form:
1062 // (BasicBlockAddr - TableBeginAddr) / 2
1064 // For example, a TBB table with entries jumping to basic blocks BB0 and BB1
1067 // .byte (LBB0 - LJTI_0_0) / 2
1068 // .byte (LBB1 - LJTI_0_0) / 2
1069 const MCExpr *Expr =
1070 MCBinaryExpr::CreateSub(MBBSymbolExpr,
1071 MCSymbolRefExpr::Create(JTISymbol, OutContext),
1073 Expr = MCBinaryExpr::CreateDiv(Expr, MCConstantExpr::Create(2, OutContext),
1075 OutStreamer.EmitValue(Expr, OffsetWidth);
1077 // Mark the end of jump table data-in-code region. 32-bit offsets use
1078 // actual branch instructions here, so we don't mark those as a data-region
1080 if (OffsetWidth != 4)
1081 OutStreamer.EmitDataRegion(MCDR_DataRegionEnd);
1084 void ARMAsmPrinter::EmitUnwindingInstruction(const MachineInstr *MI) {
1085 assert(MI->getFlag(MachineInstr::FrameSetup) &&
1086 "Only instruction which are involved into frame setup code are allowed");
1088 MCTargetStreamer &TS = *OutStreamer.getTargetStreamer();
1089 ARMTargetStreamer &ATS = static_cast<ARMTargetStreamer &>(TS);
1090 const MachineFunction &MF = *MI->getParent()->getParent();
1091 const TargetRegisterInfo *RegInfo = MF.getSubtarget().getRegisterInfo();
1092 const ARMFunctionInfo &AFI = *MF.getInfo<ARMFunctionInfo>();
1094 unsigned FramePtr = RegInfo->getFrameRegister(MF);
1095 unsigned Opc = MI->getOpcode();
1096 unsigned SrcReg, DstReg;
1098 if (Opc == ARM::tPUSH || Opc == ARM::tLDRpci) {
1099 // Two special cases:
1100 // 1) tPUSH does not have src/dst regs.
1101 // 2) for Thumb1 code we sometimes materialize the constant via constpool
1102 // load. Yes, this is pretty fragile, but for now I don't see better
1104 SrcReg = DstReg = ARM::SP;
1106 SrcReg = MI->getOperand(1).getReg();
1107 DstReg = MI->getOperand(0).getReg();
1110 // Try to figure out the unwinding opcode out of src / dst regs.
1111 if (MI->mayStore()) {
1113 assert(DstReg == ARM::SP &&
1114 "Only stack pointer as a destination reg is supported");
1116 SmallVector<unsigned, 4> RegList;
1117 // Skip src & dst reg, and pred ops.
1118 unsigned StartOp = 2 + 2;
1119 // Use all the operands.
1120 unsigned NumOffset = 0;
1125 llvm_unreachable("Unsupported opcode for unwinding information");
1127 // Special case here: no src & dst reg, but two extra imp ops.
1128 StartOp = 2; NumOffset = 2;
1129 case ARM::STMDB_UPD:
1130 case ARM::t2STMDB_UPD:
1131 case ARM::VSTMDDB_UPD:
1132 assert(SrcReg == ARM::SP &&
1133 "Only stack pointer as a source reg is supported");
1134 for (unsigned i = StartOp, NumOps = MI->getNumOperands() - NumOffset;
1136 const MachineOperand &MO = MI->getOperand(i);
1137 // Actually, there should never be any impdef stuff here. Skip it
1138 // temporary to workaround PR11902.
1139 if (MO.isImplicit())
1141 RegList.push_back(MO.getReg());
1144 case ARM::STR_PRE_IMM:
1145 case ARM::STR_PRE_REG:
1146 case ARM::t2STR_PRE:
1147 assert(MI->getOperand(2).getReg() == ARM::SP &&
1148 "Only stack pointer as a source reg is supported");
1149 RegList.push_back(SrcReg);
1152 if (MAI->getExceptionHandlingType() == ExceptionHandling::ARM)
1153 ATS.emitRegSave(RegList, Opc == ARM::VSTMDDB_UPD);
1155 // Changes of stack / frame pointer.
1156 if (SrcReg == ARM::SP) {
1161 llvm_unreachable("Unsupported opcode for unwinding information");
1167 Offset = -MI->getOperand(2).getImm();
1171 Offset = MI->getOperand(2).getImm();
1174 Offset = MI->getOperand(2).getImm()*4;
1178 Offset = -MI->getOperand(2).getImm()*4;
1180 case ARM::tLDRpci: {
1181 // Grab the constpool index and check, whether it corresponds to
1182 // original or cloned constpool entry.
1183 unsigned CPI = MI->getOperand(1).getIndex();
1184 const MachineConstantPool *MCP = MF.getConstantPool();
1185 if (CPI >= MCP->getConstants().size())
1186 CPI = AFI.getOriginalCPIdx(CPI);
1187 assert(CPI != -1U && "Invalid constpool index");
1189 // Derive the actual offset.
1190 const MachineConstantPoolEntry &CPE = MCP->getConstants()[CPI];
1191 assert(!CPE.isMachineConstantPoolEntry() && "Invalid constpool entry");
1192 // FIXME: Check for user, it should be "add" instruction!
1193 Offset = -cast<ConstantInt>(CPE.Val.ConstVal)->getSExtValue();
1198 if (MAI->getExceptionHandlingType() == ExceptionHandling::ARM) {
1199 if (DstReg == FramePtr && FramePtr != ARM::SP)
1200 // Set-up of the frame pointer. Positive values correspond to "add"
1202 ATS.emitSetFP(FramePtr, ARM::SP, -Offset);
1203 else if (DstReg == ARM::SP) {
1204 // Change of SP by an offset. Positive values correspond to "sub"
1206 ATS.emitPad(Offset);
1208 // Move of SP to a register. Positive values correspond to an "add"
1210 ATS.emitMovSP(DstReg, -Offset);
1213 } else if (DstReg == ARM::SP) {
1215 llvm_unreachable("Unsupported opcode for unwinding information");
1219 llvm_unreachable("Unsupported opcode for unwinding information");
1224 // Simple pseudo-instructions have their lowering (with expansion to real
1225 // instructions) auto-generated.
1226 #include "ARMGenMCPseudoLowering.inc"
1228 void ARMAsmPrinter::EmitInstruction(const MachineInstr *MI) {
1229 const DataLayout *DL = TM.getSubtargetImpl()->getDataLayout();
1231 // If we just ended a constant pool, mark it as such.
1232 if (InConstantPool && MI->getOpcode() != ARM::CONSTPOOL_ENTRY) {
1233 OutStreamer.EmitDataRegion(MCDR_DataRegionEnd);
1234 InConstantPool = false;
1237 // Emit unwinding stuff for frame-related instructions
1238 if (Subtarget->isTargetEHABICompatible() &&
1239 MI->getFlag(MachineInstr::FrameSetup))
1240 EmitUnwindingInstruction(MI);
1242 // Do any auto-generated pseudo lowerings.
1243 if (emitPseudoExpansionLowering(OutStreamer, MI))
1246 assert(!convertAddSubFlagsOpcode(MI->getOpcode()) &&
1247 "Pseudo flag setting opcode should be expanded early");
1249 // Check for manual lowerings.
1250 unsigned Opc = MI->getOpcode();
1252 case ARM::t2MOVi32imm: llvm_unreachable("Should be lowered by thumb2it pass");
1253 case ARM::DBG_VALUE: llvm_unreachable("Should be handled by generic printing");
1255 case ARM::tLEApcrel:
1256 case ARM::t2LEApcrel: {
1257 // FIXME: Need to also handle globals and externals
1258 MCSymbol *CPISymbol = GetCPISymbol(MI->getOperand(1).getIndex());
1259 EmitToStreamer(OutStreamer, MCInstBuilder(MI->getOpcode() ==
1260 ARM::t2LEApcrel ? ARM::t2ADR
1261 : (MI->getOpcode() == ARM::tLEApcrel ? ARM::tADR
1263 .addReg(MI->getOperand(0).getReg())
1264 .addExpr(MCSymbolRefExpr::Create(CPISymbol, OutContext))
1265 // Add predicate operands.
1266 .addImm(MI->getOperand(2).getImm())
1267 .addReg(MI->getOperand(3).getReg()));
1270 case ARM::LEApcrelJT:
1271 case ARM::tLEApcrelJT:
1272 case ARM::t2LEApcrelJT: {
1273 MCSymbol *JTIPICSymbol =
1274 GetARMJTIPICJumpTableLabel2(MI->getOperand(1).getIndex(),
1275 MI->getOperand(2).getImm());
1276 EmitToStreamer(OutStreamer, MCInstBuilder(MI->getOpcode() ==
1277 ARM::t2LEApcrelJT ? ARM::t2ADR
1278 : (MI->getOpcode() == ARM::tLEApcrelJT ? ARM::tADR
1280 .addReg(MI->getOperand(0).getReg())
1281 .addExpr(MCSymbolRefExpr::Create(JTIPICSymbol, OutContext))
1282 // Add predicate operands.
1283 .addImm(MI->getOperand(3).getImm())
1284 .addReg(MI->getOperand(4).getReg()));
1287 // Darwin call instructions are just normal call instructions with different
1288 // clobber semantics (they clobber R9).
1289 case ARM::BX_CALL: {
1290 EmitToStreamer(OutStreamer, MCInstBuilder(ARM::MOVr)
1293 // Add predicate operands.
1296 // Add 's' bit operand (always reg0 for this)
1299 EmitToStreamer(OutStreamer, MCInstBuilder(ARM::BX)
1300 .addReg(MI->getOperand(0).getReg()));
1303 case ARM::tBX_CALL: {
1304 if (Subtarget->hasV5TOps())
1305 llvm_unreachable("Expected BLX to be selected for v5t+");
1307 // On ARM v4t, when doing a call from thumb mode, we need to ensure
1308 // that the saved lr has its LSB set correctly (the arch doesn't
1310 // So here we generate a bl to a small jump pad that does bx rN.
1311 // The jump pads are emitted after the function body.
1313 unsigned TReg = MI->getOperand(0).getReg();
1314 MCSymbol *TRegSym = nullptr;
1315 for (unsigned i = 0, e = ThumbIndirectPads.size(); i < e; i++) {
1316 if (ThumbIndirectPads[i].first == TReg) {
1317 TRegSym = ThumbIndirectPads[i].second;
1323 TRegSym = OutContext.CreateTempSymbol();
1324 ThumbIndirectPads.push_back(std::make_pair(TReg, TRegSym));
1327 // Create a link-saving branch to the Reg Indirect Jump Pad.
1328 EmitToStreamer(OutStreamer, MCInstBuilder(ARM::tBL)
1329 // Predicate comes first here.
1330 .addImm(ARMCC::AL).addReg(0)
1331 .addExpr(MCSymbolRefExpr::Create(TRegSym, OutContext)));
1334 case ARM::BMOVPCRX_CALL: {
1335 EmitToStreamer(OutStreamer, MCInstBuilder(ARM::MOVr)
1338 // Add predicate operands.
1341 // Add 's' bit operand (always reg0 for this)
1344 EmitToStreamer(OutStreamer, MCInstBuilder(ARM::MOVr)
1346 .addReg(MI->getOperand(0).getReg())
1347 // Add predicate operands.
1350 // Add 's' bit operand (always reg0 for this)
1354 case ARM::BMOVPCB_CALL: {
1355 EmitToStreamer(OutStreamer, MCInstBuilder(ARM::MOVr)
1358 // Add predicate operands.
1361 // Add 's' bit operand (always reg0 for this)
1364 const MachineOperand &Op = MI->getOperand(0);
1365 const GlobalValue *GV = Op.getGlobal();
1366 const unsigned TF = Op.getTargetFlags();
1367 MCSymbol *GVSym = GetARMGVSymbol(GV, TF);
1368 const MCExpr *GVSymExpr = MCSymbolRefExpr::Create(GVSym, OutContext);
1369 EmitToStreamer(OutStreamer, MCInstBuilder(ARM::Bcc)
1371 // Add predicate operands.
1376 case ARM::MOVi16_ga_pcrel:
1377 case ARM::t2MOVi16_ga_pcrel: {
1379 TmpInst.setOpcode(Opc == ARM::MOVi16_ga_pcrel? ARM::MOVi16 : ARM::t2MOVi16);
1380 TmpInst.addOperand(MCOperand::CreateReg(MI->getOperand(0).getReg()));
1382 unsigned TF = MI->getOperand(1).getTargetFlags();
1383 const GlobalValue *GV = MI->getOperand(1).getGlobal();
1384 MCSymbol *GVSym = GetARMGVSymbol(GV, TF);
1385 const MCExpr *GVSymExpr = MCSymbolRefExpr::Create(GVSym, OutContext);
1387 MCSymbol *LabelSym = getPICLabel(DL->getPrivateGlobalPrefix(),
1388 getFunctionNumber(),
1389 MI->getOperand(2).getImm(), OutContext);
1390 const MCExpr *LabelSymExpr= MCSymbolRefExpr::Create(LabelSym, OutContext);
1391 unsigned PCAdj = (Opc == ARM::MOVi16_ga_pcrel) ? 8 : 4;
1392 const MCExpr *PCRelExpr =
1393 ARMMCExpr::CreateLower16(MCBinaryExpr::CreateSub(GVSymExpr,
1394 MCBinaryExpr::CreateAdd(LabelSymExpr,
1395 MCConstantExpr::Create(PCAdj, OutContext),
1396 OutContext), OutContext), OutContext);
1397 TmpInst.addOperand(MCOperand::CreateExpr(PCRelExpr));
1399 // Add predicate operands.
1400 TmpInst.addOperand(MCOperand::CreateImm(ARMCC::AL));
1401 TmpInst.addOperand(MCOperand::CreateReg(0));
1402 // Add 's' bit operand (always reg0 for this)
1403 TmpInst.addOperand(MCOperand::CreateReg(0));
1404 EmitToStreamer(OutStreamer, TmpInst);
1407 case ARM::MOVTi16_ga_pcrel:
1408 case ARM::t2MOVTi16_ga_pcrel: {
1410 TmpInst.setOpcode(Opc == ARM::MOVTi16_ga_pcrel
1411 ? ARM::MOVTi16 : ARM::t2MOVTi16);
1412 TmpInst.addOperand(MCOperand::CreateReg(MI->getOperand(0).getReg()));
1413 TmpInst.addOperand(MCOperand::CreateReg(MI->getOperand(1).getReg()));
1415 unsigned TF = MI->getOperand(2).getTargetFlags();
1416 const GlobalValue *GV = MI->getOperand(2).getGlobal();
1417 MCSymbol *GVSym = GetARMGVSymbol(GV, TF);
1418 const MCExpr *GVSymExpr = MCSymbolRefExpr::Create(GVSym, OutContext);
1420 MCSymbol *LabelSym = getPICLabel(DL->getPrivateGlobalPrefix(),
1421 getFunctionNumber(),
1422 MI->getOperand(3).getImm(), OutContext);
1423 const MCExpr *LabelSymExpr= MCSymbolRefExpr::Create(LabelSym, OutContext);
1424 unsigned PCAdj = (Opc == ARM::MOVTi16_ga_pcrel) ? 8 : 4;
1425 const MCExpr *PCRelExpr =
1426 ARMMCExpr::CreateUpper16(MCBinaryExpr::CreateSub(GVSymExpr,
1427 MCBinaryExpr::CreateAdd(LabelSymExpr,
1428 MCConstantExpr::Create(PCAdj, OutContext),
1429 OutContext), OutContext), OutContext);
1430 TmpInst.addOperand(MCOperand::CreateExpr(PCRelExpr));
1431 // Add predicate operands.
1432 TmpInst.addOperand(MCOperand::CreateImm(ARMCC::AL));
1433 TmpInst.addOperand(MCOperand::CreateReg(0));
1434 // Add 's' bit operand (always reg0 for this)
1435 TmpInst.addOperand(MCOperand::CreateReg(0));
1436 EmitToStreamer(OutStreamer, TmpInst);
1439 case ARM::tPICADD: {
1440 // This is a pseudo op for a label + instruction sequence, which looks like:
1443 // This adds the address of LPC0 to r0.
1446 OutStreamer.EmitLabel(getPICLabel(DL->getPrivateGlobalPrefix(),
1447 getFunctionNumber(), MI->getOperand(2).getImm(),
1450 // Form and emit the add.
1451 EmitToStreamer(OutStreamer, MCInstBuilder(ARM::tADDhirr)
1452 .addReg(MI->getOperand(0).getReg())
1453 .addReg(MI->getOperand(0).getReg())
1455 // Add predicate operands.
1461 // This is a pseudo op for a label + instruction sequence, which looks like:
1464 // This adds the address of LPC0 to r0.
1467 OutStreamer.EmitLabel(getPICLabel(DL->getPrivateGlobalPrefix(),
1468 getFunctionNumber(), MI->getOperand(2).getImm(),
1471 // Form and emit the add.
1472 EmitToStreamer(OutStreamer, MCInstBuilder(ARM::ADDrr)
1473 .addReg(MI->getOperand(0).getReg())
1475 .addReg(MI->getOperand(1).getReg())
1476 // Add predicate operands.
1477 .addImm(MI->getOperand(3).getImm())
1478 .addReg(MI->getOperand(4).getReg())
1479 // Add 's' bit operand (always reg0 for this)
1490 case ARM::PICLDRSH: {
1491 // This is a pseudo op for a label + instruction sequence, which looks like:
1494 // The LCP0 label is referenced by a constant pool entry in order to get
1495 // a PC-relative address at the ldr instruction.
1498 OutStreamer.EmitLabel(getPICLabel(DL->getPrivateGlobalPrefix(),
1499 getFunctionNumber(), MI->getOperand(2).getImm(),
1502 // Form and emit the load
1504 switch (MI->getOpcode()) {
1506 llvm_unreachable("Unexpected opcode!");
1507 case ARM::PICSTR: Opcode = ARM::STRrs; break;
1508 case ARM::PICSTRB: Opcode = ARM::STRBrs; break;
1509 case ARM::PICSTRH: Opcode = ARM::STRH; break;
1510 case ARM::PICLDR: Opcode = ARM::LDRrs; break;
1511 case ARM::PICLDRB: Opcode = ARM::LDRBrs; break;
1512 case ARM::PICLDRH: Opcode = ARM::LDRH; break;
1513 case ARM::PICLDRSB: Opcode = ARM::LDRSB; break;
1514 case ARM::PICLDRSH: Opcode = ARM::LDRSH; break;
1516 EmitToStreamer(OutStreamer, MCInstBuilder(Opcode)
1517 .addReg(MI->getOperand(0).getReg())
1519 .addReg(MI->getOperand(1).getReg())
1521 // Add predicate operands.
1522 .addImm(MI->getOperand(3).getImm())
1523 .addReg(MI->getOperand(4).getReg()));
1527 case ARM::CONSTPOOL_ENTRY: {
1528 /// CONSTPOOL_ENTRY - This instruction represents a floating constant pool
1529 /// in the function. The first operand is the ID# for this instruction, the
1530 /// second is the index into the MachineConstantPool that this is, the third
1531 /// is the size in bytes of this constant pool entry.
1532 /// The required alignment is specified on the basic block holding this MI.
1533 unsigned LabelId = (unsigned)MI->getOperand(0).getImm();
1534 unsigned CPIdx = (unsigned)MI->getOperand(1).getIndex();
1536 // If this is the first entry of the pool, mark it.
1537 if (!InConstantPool) {
1538 OutStreamer.EmitDataRegion(MCDR_DataRegion);
1539 InConstantPool = true;
1542 OutStreamer.EmitLabel(GetCPISymbol(LabelId));
1544 const MachineConstantPoolEntry &MCPE = MCP->getConstants()[CPIdx];
1545 if (MCPE.isMachineConstantPoolEntry())
1546 EmitMachineConstantPoolValue(MCPE.Val.MachineCPVal);
1548 EmitGlobalConstant(MCPE.Val.ConstVal);
1551 case ARM::t2BR_JT: {
1552 // Lower and emit the instruction itself, then the jump table following it.
1553 EmitToStreamer(OutStreamer, MCInstBuilder(ARM::tMOVr)
1555 .addReg(MI->getOperand(0).getReg())
1556 // Add predicate operands.
1560 // Output the data for the jump table itself
1564 case ARM::t2TBB_JT: {
1565 // Lower and emit the instruction itself, then the jump table following it.
1566 EmitToStreamer(OutStreamer, MCInstBuilder(ARM::t2TBB)
1568 .addReg(MI->getOperand(0).getReg())
1569 // Add predicate operands.
1573 // Output the data for the jump table itself
1575 // Make sure the next instruction is 2-byte aligned.
1579 case ARM::t2TBH_JT: {
1580 // Lower and emit the instruction itself, then the jump table following it.
1581 EmitToStreamer(OutStreamer, MCInstBuilder(ARM::t2TBH)
1583 .addReg(MI->getOperand(0).getReg())
1584 // Add predicate operands.
1588 // Output the data for the jump table itself
1594 // Lower and emit the instruction itself, then the jump table following it.
1597 unsigned Opc = MI->getOpcode() == ARM::BR_JTr ?
1598 ARM::MOVr : ARM::tMOVr;
1599 TmpInst.setOpcode(Opc);
1600 TmpInst.addOperand(MCOperand::CreateReg(ARM::PC));
1601 TmpInst.addOperand(MCOperand::CreateReg(MI->getOperand(0).getReg()));
1602 // Add predicate operands.
1603 TmpInst.addOperand(MCOperand::CreateImm(ARMCC::AL));
1604 TmpInst.addOperand(MCOperand::CreateReg(0));
1605 // Add 's' bit operand (always reg0 for this)
1606 if (Opc == ARM::MOVr)
1607 TmpInst.addOperand(MCOperand::CreateReg(0));
1608 EmitToStreamer(OutStreamer, TmpInst);
1610 // Make sure the Thumb jump table is 4-byte aligned.
1611 if (Opc == ARM::tMOVr)
1614 // Output the data for the jump table itself
1619 // Lower and emit the instruction itself, then the jump table following it.
1622 if (MI->getOperand(1).getReg() == 0) {
1624 TmpInst.setOpcode(ARM::LDRi12);
1625 TmpInst.addOperand(MCOperand::CreateReg(ARM::PC));
1626 TmpInst.addOperand(MCOperand::CreateReg(MI->getOperand(0).getReg()));
1627 TmpInst.addOperand(MCOperand::CreateImm(MI->getOperand(2).getImm()));
1629 TmpInst.setOpcode(ARM::LDRrs);
1630 TmpInst.addOperand(MCOperand::CreateReg(ARM::PC));
1631 TmpInst.addOperand(MCOperand::CreateReg(MI->getOperand(0).getReg()));
1632 TmpInst.addOperand(MCOperand::CreateReg(MI->getOperand(1).getReg()));
1633 TmpInst.addOperand(MCOperand::CreateImm(0));
1635 // Add predicate operands.
1636 TmpInst.addOperand(MCOperand::CreateImm(ARMCC::AL));
1637 TmpInst.addOperand(MCOperand::CreateReg(0));
1638 EmitToStreamer(OutStreamer, TmpInst);
1640 // Output the data for the jump table itself
1644 case ARM::BR_JTadd: {
1645 // Lower and emit the instruction itself, then the jump table following it.
1646 // add pc, target, idx
1647 EmitToStreamer(OutStreamer, MCInstBuilder(ARM::ADDrr)
1649 .addReg(MI->getOperand(0).getReg())
1650 .addReg(MI->getOperand(1).getReg())
1651 // Add predicate operands.
1654 // Add 's' bit operand (always reg0 for this)
1657 // Output the data for the jump table itself
1662 OutStreamer.EmitZeros(MI->getOperand(1).getImm());
1665 // Non-Darwin binutils don't yet support the "trap" mnemonic.
1666 // FIXME: Remove this special case when they do.
1667 if (!Subtarget->isTargetMachO()) {
1668 //.long 0xe7ffdefe @ trap
1669 uint32_t Val = 0xe7ffdefeUL;
1670 OutStreamer.AddComment("trap");
1671 OutStreamer.EmitIntValue(Val, 4);
1676 case ARM::TRAPNaCl: {
1677 //.long 0xe7fedef0 @ trap
1678 uint32_t Val = 0xe7fedef0UL;
1679 OutStreamer.AddComment("trap");
1680 OutStreamer.EmitIntValue(Val, 4);
1684 // Non-Darwin binutils don't yet support the "trap" mnemonic.
1685 // FIXME: Remove this special case when they do.
1686 if (!Subtarget->isTargetMachO()) {
1687 //.short 57086 @ trap
1688 uint16_t Val = 0xdefe;
1689 OutStreamer.AddComment("trap");
1690 OutStreamer.EmitIntValue(Val, 2);
1695 case ARM::t2Int_eh_sjlj_setjmp:
1696 case ARM::t2Int_eh_sjlj_setjmp_nofp:
1697 case ARM::tInt_eh_sjlj_setjmp: {
1698 // Two incoming args: GPR:$src, GPR:$val
1701 // str $val, [$src, #4]
1706 unsigned SrcReg = MI->getOperand(0).getReg();
1707 unsigned ValReg = MI->getOperand(1).getReg();
1708 MCSymbol *Label = GetARMSJLJEHLabel();
1709 OutStreamer.AddComment("eh_setjmp begin");
1710 EmitToStreamer(OutStreamer, MCInstBuilder(ARM::tMOVr)
1717 EmitToStreamer(OutStreamer, MCInstBuilder(ARM::tADDi3)
1727 EmitToStreamer(OutStreamer, MCInstBuilder(ARM::tSTRi)
1730 // The offset immediate is #4. The operand value is scaled by 4 for the
1731 // tSTR instruction.
1737 EmitToStreamer(OutStreamer, MCInstBuilder(ARM::tMOVi8)
1745 const MCExpr *SymbolExpr = MCSymbolRefExpr::Create(Label, OutContext);
1746 EmitToStreamer(OutStreamer, MCInstBuilder(ARM::tB)
1747 .addExpr(SymbolExpr)
1751 OutStreamer.AddComment("eh_setjmp end");
1752 EmitToStreamer(OutStreamer, MCInstBuilder(ARM::tMOVi8)
1760 OutStreamer.EmitLabel(Label);
1764 case ARM::Int_eh_sjlj_setjmp_nofp:
1765 case ARM::Int_eh_sjlj_setjmp: {
1766 // Two incoming args: GPR:$src, GPR:$val
1768 // str $val, [$src, #+4]
1772 unsigned SrcReg = MI->getOperand(0).getReg();
1773 unsigned ValReg = MI->getOperand(1).getReg();
1775 OutStreamer.AddComment("eh_setjmp begin");
1776 EmitToStreamer(OutStreamer, MCInstBuilder(ARM::ADDri)
1783 // 's' bit operand (always reg0 for this).
1786 EmitToStreamer(OutStreamer, MCInstBuilder(ARM::STRi12)
1794 EmitToStreamer(OutStreamer, MCInstBuilder(ARM::MOVi)
1800 // 's' bit operand (always reg0 for this).
1803 EmitToStreamer(OutStreamer, MCInstBuilder(ARM::ADDri)
1810 // 's' bit operand (always reg0 for this).
1813 OutStreamer.AddComment("eh_setjmp end");
1814 EmitToStreamer(OutStreamer, MCInstBuilder(ARM::MOVi)
1820 // 's' bit operand (always reg0 for this).
1824 case ARM::Int_eh_sjlj_longjmp: {
1825 // ldr sp, [$src, #8]
1826 // ldr $scratch, [$src, #4]
1829 unsigned SrcReg = MI->getOperand(0).getReg();
1830 unsigned ScratchReg = MI->getOperand(1).getReg();
1831 EmitToStreamer(OutStreamer, MCInstBuilder(ARM::LDRi12)
1839 EmitToStreamer(OutStreamer, MCInstBuilder(ARM::LDRi12)
1847 EmitToStreamer(OutStreamer, MCInstBuilder(ARM::LDRi12)
1855 EmitToStreamer(OutStreamer, MCInstBuilder(ARM::BX)
1862 case ARM::tInt_eh_sjlj_longjmp: {
1863 // ldr $scratch, [$src, #8]
1865 // ldr $scratch, [$src, #4]
1868 unsigned SrcReg = MI->getOperand(0).getReg();
1869 unsigned ScratchReg = MI->getOperand(1).getReg();
1870 EmitToStreamer(OutStreamer, MCInstBuilder(ARM::tLDRi)
1873 // The offset immediate is #8. The operand value is scaled by 4 for the
1874 // tLDR instruction.
1880 EmitToStreamer(OutStreamer, MCInstBuilder(ARM::tMOVr)
1887 EmitToStreamer(OutStreamer, MCInstBuilder(ARM::tLDRi)
1895 EmitToStreamer(OutStreamer, MCInstBuilder(ARM::tLDRi)
1903 EmitToStreamer(OutStreamer, MCInstBuilder(ARM::tBX)
1913 LowerARMMachineInstrToMCInst(MI, TmpInst, *this);
1915 EmitToStreamer(OutStreamer, TmpInst);
1918 //===----------------------------------------------------------------------===//
1919 // Target Registry Stuff
1920 //===----------------------------------------------------------------------===//
1922 // Force static initialization.
1923 extern "C" void LLVMInitializeARMAsmPrinter() {
1924 RegisterAsmPrinter<ARMAsmPrinter> X(TheARMLETarget);
1925 RegisterAsmPrinter<ARMAsmPrinter> Y(TheARMBETarget);
1926 RegisterAsmPrinter<ARMAsmPrinter> A(TheThumbLETarget);
1927 RegisterAsmPrinter<ARMAsmPrinter> B(TheThumbBETarget);