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 "ARMMachineFunctionInfo.h"
19 #include "ARMTargetMachine.h"
20 #include "ARMTargetObjectFile.h"
21 #include "InstPrinter/ARMInstPrinter.h"
22 #include "MCTargetDesc/ARMAddressingModes.h"
23 #include "MCTargetDesc/ARMMCExpr.h"
24 #include "llvm/ADT/SetVector.h"
25 #include "llvm/ADT/SmallString.h"
26 #include "llvm/BinaryFormat/COFF.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/Mangler.h"
33 #include "llvm/IR/Module.h"
34 #include "llvm/IR/Type.h"
35 #include "llvm/MC/MCAsmInfo.h"
36 #include "llvm/MC/MCAssembler.h"
37 #include "llvm/MC/MCContext.h"
38 #include "llvm/MC/MCELFStreamer.h"
39 #include "llvm/MC/MCInst.h"
40 #include "llvm/MC/MCInstBuilder.h"
41 #include "llvm/MC/MCObjectStreamer.h"
42 #include "llvm/MC/MCStreamer.h"
43 #include "llvm/MC/MCSymbol.h"
44 #include "llvm/Support/ARMBuildAttributes.h"
45 #include "llvm/Support/Debug.h"
46 #include "llvm/Support/ErrorHandling.h"
47 #include "llvm/Support/TargetParser.h"
48 #include "llvm/Support/TargetRegistry.h"
49 #include "llvm/Support/raw_ostream.h"
50 #include "llvm/Target/TargetMachine.h"
53 #define DEBUG_TYPE "asm-printer"
55 ARMAsmPrinter::ARMAsmPrinter(TargetMachine &TM,
56 std::unique_ptr<MCStreamer> Streamer)
57 : AsmPrinter(TM, std::move(Streamer)), AFI(nullptr), MCP(nullptr),
58 InConstantPool(false), OptimizationGoals(-1) {}
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);
74 OutStreamer->EmitAssemblerFlag(MCAF_Code32);
76 OutStreamer->EmitLabel(CurrentFnSym);
79 void ARMAsmPrinter::EmitXXStructor(const DataLayout &DL, const Constant *CV) {
80 uint64_t Size = 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 void ARMAsmPrinter::EmitGlobalVariable(const GlobalVariable *GV) {
97 if (PromotedGlobals.count(GV))
98 // The global was promoted into a constant pool. It should not be emitted.
100 AsmPrinter::EmitGlobalVariable(GV);
103 /// runOnMachineFunction - This uses the EmitInstruction()
104 /// method to print assembly for each instruction.
106 bool ARMAsmPrinter::runOnMachineFunction(MachineFunction &MF) {
107 AFI = MF.getInfo<ARMFunctionInfo>();
108 MCP = MF.getConstantPool();
109 Subtarget = &MF.getSubtarget<ARMSubtarget>();
111 SetupMachineFunction(MF);
112 const Function &F = MF.getFunction();
113 const TargetMachine& TM = MF.getTarget();
115 // Collect all globals that had their storage promoted to a constant pool.
116 // Functions are emitted before variables, so this accumulates promoted
117 // globals from all functions in PromotedGlobals.
118 for (auto *GV : AFI->getGlobalsPromotedToConstantPool())
119 PromotedGlobals.insert(GV);
121 // Calculate this function's optimization goal.
122 unsigned OptimizationGoal;
123 if (F.hasFnAttribute(Attribute::OptimizeNone))
124 // For best debugging illusion, speed and small size sacrificed
125 OptimizationGoal = 6;
126 else if (F.optForMinSize())
127 // Aggressively for small size, speed and debug illusion sacrificed
128 OptimizationGoal = 4;
129 else if (F.optForSize())
130 // For small size, but speed and debugging illusion preserved
131 OptimizationGoal = 3;
132 else if (TM.getOptLevel() == CodeGenOpt::Aggressive)
133 // Aggressively for speed, small size and debug illusion sacrificed
134 OptimizationGoal = 2;
135 else if (TM.getOptLevel() > CodeGenOpt::None)
136 // For speed, but small size and good debug illusion preserved
137 OptimizationGoal = 1;
138 else // TM.getOptLevel() == CodeGenOpt::None
139 // For good debugging, but speed and small size preserved
140 OptimizationGoal = 5;
142 // Combine a new optimization goal with existing ones.
143 if (OptimizationGoals == -1) // uninitialized goals
144 OptimizationGoals = OptimizationGoal;
145 else if (OptimizationGoals != (int)OptimizationGoal) // conflicting goals
146 OptimizationGoals = 0;
148 if (Subtarget->isTargetCOFF()) {
149 bool Internal = F.hasInternalLinkage();
150 COFF::SymbolStorageClass Scl = Internal ? COFF::IMAGE_SYM_CLASS_STATIC
151 : COFF::IMAGE_SYM_CLASS_EXTERNAL;
152 int Type = COFF::IMAGE_SYM_DTYPE_FUNCTION << COFF::SCT_COMPLEX_TYPE_SHIFT;
154 OutStreamer->BeginCOFFSymbolDef(CurrentFnSym);
155 OutStreamer->EmitCOFFSymbolStorageClass(Scl);
156 OutStreamer->EmitCOFFSymbolType(Type);
157 OutStreamer->EndCOFFSymbolDef();
160 // Emit the rest of the function body.
163 // Emit the XRay table for this function.
166 // If we need V4T thumb mode Register Indirect Jump pads, emit them.
167 // These are created per function, rather than per TU, since it's
168 // relatively easy to exceed the thumb branch range within a TU.
169 if (! ThumbIndirectPads.empty()) {
170 OutStreamer->EmitAssemblerFlag(MCAF_Code16);
172 for (std::pair<unsigned, MCSymbol *> &TIP : ThumbIndirectPads) {
173 OutStreamer->EmitLabel(TIP.second);
174 EmitToStreamer(*OutStreamer, MCInstBuilder(ARM::tBX)
176 // Add predicate operands.
180 ThumbIndirectPads.clear();
183 // We didn't modify anything.
187 void ARMAsmPrinter::printOperand(const MachineInstr *MI, int OpNum,
189 const MachineOperand &MO = MI->getOperand(OpNum);
190 unsigned TF = MO.getTargetFlags();
192 switch (MO.getType()) {
193 default: llvm_unreachable("<unknown operand type>");
194 case MachineOperand::MO_Register: {
195 unsigned Reg = MO.getReg();
196 assert(TargetRegisterInfo::isPhysicalRegister(Reg));
197 assert(!MO.getSubReg() && "Subregs should be eliminated!");
198 if(ARM::GPRPairRegClass.contains(Reg)) {
199 const MachineFunction &MF = *MI->getParent()->getParent();
200 const TargetRegisterInfo *TRI = MF.getSubtarget().getRegisterInfo();
201 Reg = TRI->getSubReg(Reg, ARM::gsub_0);
203 O << ARMInstPrinter::getRegisterName(Reg);
206 case MachineOperand::MO_Immediate: {
207 int64_t Imm = MO.getImm();
209 if (TF == ARMII::MO_LO16)
211 else if (TF == ARMII::MO_HI16)
216 case MachineOperand::MO_MachineBasicBlock:
217 MO.getMBB()->getSymbol()->print(O, MAI);
219 case MachineOperand::MO_GlobalAddress: {
220 const GlobalValue *GV = MO.getGlobal();
221 if (TF & ARMII::MO_LO16)
223 else if (TF & ARMII::MO_HI16)
225 GetARMGVSymbol(GV, TF)->print(O, MAI);
227 printOffset(MO.getOffset(), O);
230 case MachineOperand::MO_ConstantPoolIndex:
231 if (Subtarget->genExecuteOnly())
232 llvm_unreachable("execute-only should not generate constant pools");
233 GetCPISymbol(MO.getIndex())->print(O, MAI);
238 MCSymbol *ARMAsmPrinter::GetCPISymbol(unsigned CPID) const {
239 // The AsmPrinter::GetCPISymbol superclass method tries to use CPID as
240 // indexes in MachineConstantPool, which isn't in sync with indexes used here.
241 const DataLayout &DL = getDataLayout();
242 return OutContext.getOrCreateSymbol(Twine(DL.getPrivateGlobalPrefix()) +
243 "CPI" + Twine(getFunctionNumber()) + "_" +
247 //===--------------------------------------------------------------------===//
249 MCSymbol *ARMAsmPrinter::
250 GetARMJTIPICJumpTableLabel(unsigned uid) const {
251 const DataLayout &DL = getDataLayout();
252 SmallString<60> Name;
253 raw_svector_ostream(Name) << DL.getPrivateGlobalPrefix() << "JTI"
254 << getFunctionNumber() << '_' << uid;
255 return OutContext.getOrCreateSymbol(Name);
258 bool ARMAsmPrinter::PrintAsmOperand(const MachineInstr *MI, unsigned OpNum,
259 unsigned AsmVariant, const char *ExtraCode,
261 // Does this asm operand have a single letter operand modifier?
262 if (ExtraCode && ExtraCode[0]) {
263 if (ExtraCode[1] != 0) return true; // Unknown modifier.
265 switch (ExtraCode[0]) {
267 // See if this is a generic print operand
268 return AsmPrinter::PrintAsmOperand(MI, OpNum, AsmVariant, ExtraCode, O);
269 case 'a': // Print as a memory address.
270 if (MI->getOperand(OpNum).isReg()) {
272 << ARMInstPrinter::getRegisterName(MI->getOperand(OpNum).getReg())
277 case 'c': // Don't print "#" before an immediate operand.
278 if (!MI->getOperand(OpNum).isImm())
280 O << MI->getOperand(OpNum).getImm();
282 case 'P': // Print a VFP double precision register.
283 case 'q': // Print a NEON quad precision register.
284 printOperand(MI, OpNum, O);
286 case 'y': // Print a VFP single precision register as indexed double.
287 if (MI->getOperand(OpNum).isReg()) {
288 unsigned Reg = MI->getOperand(OpNum).getReg();
289 const TargetRegisterInfo *TRI = MF->getSubtarget().getRegisterInfo();
290 // Find the 'd' register that has this 's' register as a sub-register,
291 // and determine the lane number.
292 for (MCSuperRegIterator SR(Reg, TRI); SR.isValid(); ++SR) {
293 if (!ARM::DPRRegClass.contains(*SR))
295 bool Lane0 = TRI->getSubReg(*SR, ARM::ssub_0) == Reg;
296 O << ARMInstPrinter::getRegisterName(*SR) << (Lane0 ? "[0]" : "[1]");
301 case 'B': // Bitwise inverse of integer or symbol without a preceding #.
302 if (!MI->getOperand(OpNum).isImm())
304 O << ~(MI->getOperand(OpNum).getImm());
306 case 'L': // The low 16 bits of an immediate constant.
307 if (!MI->getOperand(OpNum).isImm())
309 O << (MI->getOperand(OpNum).getImm() & 0xffff);
311 case 'M': { // A register range suitable for LDM/STM.
312 if (!MI->getOperand(OpNum).isReg())
314 const MachineOperand &MO = MI->getOperand(OpNum);
315 unsigned RegBegin = MO.getReg();
316 // This takes advantage of the 2 operand-ness of ldm/stm and that we've
317 // already got the operands in registers that are operands to the
318 // inline asm statement.
320 if (ARM::GPRPairRegClass.contains(RegBegin)) {
321 const TargetRegisterInfo *TRI = MF->getSubtarget().getRegisterInfo();
322 unsigned Reg0 = TRI->getSubReg(RegBegin, ARM::gsub_0);
323 O << ARMInstPrinter::getRegisterName(Reg0) << ", ";
324 RegBegin = TRI->getSubReg(RegBegin, ARM::gsub_1);
326 O << ARMInstPrinter::getRegisterName(RegBegin);
328 // FIXME: The register allocator not only may not have given us the
329 // registers in sequence, but may not be in ascending registers. This
330 // will require changes in the register allocator that'll need to be
331 // propagated down here if the operands change.
332 unsigned RegOps = OpNum + 1;
333 while (MI->getOperand(RegOps).isReg()) {
335 << ARMInstPrinter::getRegisterName(MI->getOperand(RegOps).getReg());
343 case 'R': // The most significant register of a pair.
344 case 'Q': { // The least significant register of a pair.
347 const MachineOperand &FlagsOP = MI->getOperand(OpNum - 1);
348 if (!FlagsOP.isImm())
350 unsigned Flags = FlagsOP.getImm();
352 // This operand may not be the one that actually provides the register. If
353 // it's tied to a previous one then we should refer instead to that one
354 // for registers and their classes.
356 if (InlineAsm::isUseOperandTiedToDef(Flags, TiedIdx)) {
357 for (OpNum = InlineAsm::MIOp_FirstOperand; TiedIdx; --TiedIdx) {
358 unsigned OpFlags = MI->getOperand(OpNum).getImm();
359 OpNum += InlineAsm::getNumOperandRegisters(OpFlags) + 1;
361 Flags = MI->getOperand(OpNum).getImm();
363 // Later code expects OpNum to be pointing at the register rather than
368 unsigned NumVals = InlineAsm::getNumOperandRegisters(Flags);
370 const TargetRegisterInfo *TRI = MF->getSubtarget().getRegisterInfo();
371 if (InlineAsm::hasRegClassConstraint(Flags, RC) &&
372 ARM::GPRPairRegClass.hasSubClassEq(TRI->getRegClass(RC))) {
375 const MachineOperand &MO = MI->getOperand(OpNum);
378 const TargetRegisterInfo *TRI = MF->getSubtarget().getRegisterInfo();
379 unsigned Reg = TRI->getSubReg(MO.getReg(), ExtraCode[0] == 'Q' ?
380 ARM::gsub_0 : ARM::gsub_1);
381 O << ARMInstPrinter::getRegisterName(Reg);
386 unsigned RegOp = ExtraCode[0] == 'Q' ? OpNum : OpNum + 1;
387 if (RegOp >= MI->getNumOperands())
389 const MachineOperand &MO = MI->getOperand(RegOp);
392 unsigned Reg = MO.getReg();
393 O << ARMInstPrinter::getRegisterName(Reg);
397 case 'e': // The low doubleword register of a NEON quad register.
398 case 'f': { // The high doubleword register of a NEON quad register.
399 if (!MI->getOperand(OpNum).isReg())
401 unsigned Reg = MI->getOperand(OpNum).getReg();
402 if (!ARM::QPRRegClass.contains(Reg))
404 const TargetRegisterInfo *TRI = MF->getSubtarget().getRegisterInfo();
405 unsigned SubReg = TRI->getSubReg(Reg, ExtraCode[0] == 'e' ?
406 ARM::dsub_0 : ARM::dsub_1);
407 O << ARMInstPrinter::getRegisterName(SubReg);
411 // This modifier is not yet supported.
412 case 'h': // A range of VFP/NEON registers suitable for VLD1/VST1.
414 case 'H': { // The highest-numbered register of a pair.
415 const MachineOperand &MO = MI->getOperand(OpNum);
418 const MachineFunction &MF = *MI->getParent()->getParent();
419 const TargetRegisterInfo *TRI = MF.getSubtarget().getRegisterInfo();
420 unsigned Reg = MO.getReg();
421 if(!ARM::GPRPairRegClass.contains(Reg))
423 Reg = TRI->getSubReg(Reg, ARM::gsub_1);
424 O << ARMInstPrinter::getRegisterName(Reg);
430 printOperand(MI, OpNum, O);
434 bool ARMAsmPrinter::PrintAsmMemoryOperand(const MachineInstr *MI,
435 unsigned OpNum, unsigned AsmVariant,
436 const char *ExtraCode,
438 // Does this asm operand have a single letter operand modifier?
439 if (ExtraCode && ExtraCode[0]) {
440 if (ExtraCode[1] != 0) return true; // Unknown modifier.
442 switch (ExtraCode[0]) {
443 case 'A': // A memory operand for a VLD1/VST1 instruction.
444 default: return true; // Unknown modifier.
445 case 'm': // The base register of a memory operand.
446 if (!MI->getOperand(OpNum).isReg())
448 O << ARMInstPrinter::getRegisterName(MI->getOperand(OpNum).getReg());
453 const MachineOperand &MO = MI->getOperand(OpNum);
454 assert(MO.isReg() && "unexpected inline asm memory operand");
455 O << "[" << ARMInstPrinter::getRegisterName(MO.getReg()) << "]";
459 static bool isThumb(const MCSubtargetInfo& STI) {
460 return STI.getFeatureBits()[ARM::ModeThumb];
463 void ARMAsmPrinter::emitInlineAsmEnd(const MCSubtargetInfo &StartInfo,
464 const MCSubtargetInfo *EndInfo) const {
465 // If either end mode is unknown (EndInfo == NULL) or different than
466 // the start mode, then restore the start mode.
467 const bool WasThumb = isThumb(StartInfo);
468 if (!EndInfo || WasThumb != isThumb(*EndInfo)) {
469 OutStreamer->EmitAssemblerFlag(WasThumb ? MCAF_Code16 : MCAF_Code32);
473 void ARMAsmPrinter::EmitStartOfAsmFile(Module &M) {
474 const Triple &TT = TM.getTargetTriple();
475 // Use unified assembler syntax.
476 OutStreamer->EmitAssemblerFlag(MCAF_SyntaxUnified);
478 // Emit ARM Build Attributes
479 if (TT.isOSBinFormatELF())
482 // Use the triple's architecture and subarchitecture to determine
483 // if we're thumb for the purposes of the top level code16 assembler
485 if (!M.getModuleInlineAsm().empty() && TT.isThumb())
486 OutStreamer->EmitAssemblerFlag(MCAF_Code16);
490 emitNonLazySymbolPointer(MCStreamer &OutStreamer, MCSymbol *StubLabel,
491 MachineModuleInfoImpl::StubValueTy &MCSym) {
493 OutStreamer.EmitLabel(StubLabel);
494 // .indirect_symbol _foo
495 OutStreamer.EmitSymbolAttribute(MCSym.getPointer(), MCSA_IndirectSymbol);
498 // External to current translation unit.
499 OutStreamer.EmitIntValue(0, 4/*size*/);
501 // Internal to current translation unit.
503 // When we place the LSDA into the TEXT section, the type info
504 // pointers need to be indirect and pc-rel. We accomplish this by
505 // using NLPs; however, sometimes the types are local to the file.
506 // We need to fill in the value for the NLP in those cases.
507 OutStreamer.EmitValue(
508 MCSymbolRefExpr::create(MCSym.getPointer(), OutStreamer.getContext()),
513 void ARMAsmPrinter::EmitEndOfAsmFile(Module &M) {
514 const Triple &TT = TM.getTargetTriple();
515 if (TT.isOSBinFormatMachO()) {
516 // All darwin targets use mach-o.
517 const TargetLoweringObjectFileMachO &TLOFMacho =
518 static_cast<const TargetLoweringObjectFileMachO &>(getObjFileLowering());
519 MachineModuleInfoMachO &MMIMacho =
520 MMI->getObjFileInfo<MachineModuleInfoMachO>();
522 // Output non-lazy-pointers for external and common global variables.
523 MachineModuleInfoMachO::SymbolListTy Stubs = MMIMacho.GetGVStubList();
525 if (!Stubs.empty()) {
526 // Switch with ".non_lazy_symbol_pointer" directive.
527 OutStreamer->SwitchSection(TLOFMacho.getNonLazySymbolPointerSection());
530 for (auto &Stub : Stubs)
531 emitNonLazySymbolPointer(*OutStreamer, Stub.first, Stub.second);
534 OutStreamer->AddBlankLine();
537 Stubs = MMIMacho.GetThreadLocalGVStubList();
538 if (!Stubs.empty()) {
539 // Switch with ".non_lazy_symbol_pointer" directive.
540 OutStreamer->SwitchSection(TLOFMacho.getThreadLocalPointerSection());
543 for (auto &Stub : Stubs)
544 emitNonLazySymbolPointer(*OutStreamer, Stub.first, Stub.second);
547 OutStreamer->AddBlankLine();
550 // Funny Darwin hack: This flag tells the linker that no global symbols
551 // contain code that falls through to other global symbols (e.g. the obvious
552 // implementation of multiple entry points). If this doesn't occur, the
553 // linker can safely perform dead code stripping. Since LLVM never
554 // generates code that does this, it is always safe to set.
555 OutStreamer->EmitAssemblerFlag(MCAF_SubsectionsViaSymbols);
558 // The last attribute to be emitted is ABI_optimization_goals
559 MCTargetStreamer &TS = *OutStreamer->getTargetStreamer();
560 ARMTargetStreamer &ATS = static_cast<ARMTargetStreamer &>(TS);
562 if (OptimizationGoals > 0 &&
563 (Subtarget->isTargetAEABI() || Subtarget->isTargetGNUAEABI() ||
564 Subtarget->isTargetMuslAEABI()))
565 ATS.emitAttribute(ARMBuildAttrs::ABI_optimization_goals, OptimizationGoals);
566 OptimizationGoals = -1;
568 ATS.finishAttributeSection();
571 //===----------------------------------------------------------------------===//
572 // Helper routines for EmitStartOfAsmFile() and EmitEndOfAsmFile()
574 // The following seem like one-off assembler flags, but they actually need
575 // to appear in the .ARM.attributes section in ELF.
576 // Instead of subclassing the MCELFStreamer, we do the work here.
578 // Returns true if all functions have the same function attribute value.
579 // It also returns true when the module has no functions.
580 static bool checkFunctionsAttributeConsistency(const Module &M, StringRef Attr,
582 return !any_of(M, [&](const Function &F) {
583 return F.getFnAttribute(Attr).getValueAsString() != Value;
587 void ARMAsmPrinter::emitAttributes() {
588 MCTargetStreamer &TS = *OutStreamer->getTargetStreamer();
589 ARMTargetStreamer &ATS = static_cast<ARMTargetStreamer &>(TS);
591 ATS.emitTextAttribute(ARMBuildAttrs::conformance, "2.09");
593 ATS.switchVendor("aeabi");
595 // Compute ARM ELF Attributes based on the default subtarget that
596 // we'd have constructed. The existing ARM behavior isn't LTO clean
598 // FIXME: For ifunc related functions we could iterate over and look
599 // for a feature string that doesn't match the default one.
600 const Triple &TT = TM.getTargetTriple();
601 StringRef CPU = TM.getTargetCPU();
602 StringRef FS = TM.getTargetFeatureString();
603 std::string ArchFS = ARM_MC::ParseARMTriple(TT, CPU);
606 ArchFS = (Twine(ArchFS) + "," + FS).str();
610 const ARMBaseTargetMachine &ATM =
611 static_cast<const ARMBaseTargetMachine &>(TM);
612 const ARMSubtarget STI(TT, CPU, ArchFS, ATM, ATM.isLittleEndian());
614 // Emit build attributes for the available hardware.
615 ATS.emitTargetAttributes(STI);
617 // RW data addressing.
618 if (isPositionIndependent()) {
619 ATS.emitAttribute(ARMBuildAttrs::ABI_PCS_RW_data,
620 ARMBuildAttrs::AddressRWPCRel);
621 } else if (STI.isRWPI()) {
622 // RWPI specific attributes.
623 ATS.emitAttribute(ARMBuildAttrs::ABI_PCS_RW_data,
624 ARMBuildAttrs::AddressRWSBRel);
627 // RO data addressing.
628 if (isPositionIndependent() || STI.isROPI()) {
629 ATS.emitAttribute(ARMBuildAttrs::ABI_PCS_RO_data,
630 ARMBuildAttrs::AddressROPCRel);
634 if (isPositionIndependent()) {
635 ATS.emitAttribute(ARMBuildAttrs::ABI_PCS_GOT_use,
636 ARMBuildAttrs::AddressGOT);
638 ATS.emitAttribute(ARMBuildAttrs::ABI_PCS_GOT_use,
639 ARMBuildAttrs::AddressDirect);
643 if (checkFunctionsAttributeConsistency(*MMI->getModule(),
646 TM.Options.FPDenormalMode == FPDenormal::PreserveSign)
647 ATS.emitAttribute(ARMBuildAttrs::ABI_FP_denormal,
648 ARMBuildAttrs::PreserveFPSign);
649 else if (checkFunctionsAttributeConsistency(*MMI->getModule(),
652 TM.Options.FPDenormalMode == FPDenormal::PositiveZero)
653 ATS.emitAttribute(ARMBuildAttrs::ABI_FP_denormal,
654 ARMBuildAttrs::PositiveZero);
655 else if (!TM.Options.UnsafeFPMath)
656 ATS.emitAttribute(ARMBuildAttrs::ABI_FP_denormal,
657 ARMBuildAttrs::IEEEDenormals);
659 if (!STI.hasVFP2()) {
660 // When the target doesn't have an FPU (by design or
661 // intention), the assumptions made on the software support
662 // mirror that of the equivalent hardware support *if it
663 // existed*. For v7 and better we indicate that denormals are
664 // flushed preserving sign, and for V6 we indicate that
665 // denormals are flushed to positive zero.
667 ATS.emitAttribute(ARMBuildAttrs::ABI_FP_denormal,
668 ARMBuildAttrs::PreserveFPSign);
669 } else if (STI.hasVFP3()) {
670 // In VFPv4, VFPv4U, VFPv3, or VFPv3U, it is preserved. That is,
671 // the sign bit of the zero matches the sign bit of the input or
672 // result that is being flushed to zero.
673 ATS.emitAttribute(ARMBuildAttrs::ABI_FP_denormal,
674 ARMBuildAttrs::PreserveFPSign);
676 // For VFPv2 implementations it is implementation defined as
677 // to whether denormals are flushed to positive zero or to
678 // whatever the sign of zero is (ARM v7AR ARM 2.7.5). Historically
679 // LLVM has chosen to flush this to positive zero (most likely for
680 // GCC compatibility), so that's the chosen value here (the
681 // absence of its emission implies zero).
684 // Set FP exceptions and rounding
685 if (checkFunctionsAttributeConsistency(*MMI->getModule(),
686 "no-trapping-math", "true") ||
687 TM.Options.NoTrappingFPMath)
688 ATS.emitAttribute(ARMBuildAttrs::ABI_FP_exceptions,
689 ARMBuildAttrs::Not_Allowed);
690 else if (!TM.Options.UnsafeFPMath) {
691 ATS.emitAttribute(ARMBuildAttrs::ABI_FP_exceptions, ARMBuildAttrs::Allowed);
693 // If the user has permitted this code to choose the IEEE 754
694 // rounding at run-time, emit the rounding attribute.
695 if (TM.Options.HonorSignDependentRoundingFPMathOption)
696 ATS.emitAttribute(ARMBuildAttrs::ABI_FP_rounding, ARMBuildAttrs::Allowed);
699 // TM.Options.NoInfsFPMath && TM.Options.NoNaNsFPMath is the
700 // equivalent of GCC's -ffinite-math-only flag.
701 if (TM.Options.NoInfsFPMath && TM.Options.NoNaNsFPMath)
702 ATS.emitAttribute(ARMBuildAttrs::ABI_FP_number_model,
703 ARMBuildAttrs::Allowed);
705 ATS.emitAttribute(ARMBuildAttrs::ABI_FP_number_model,
706 ARMBuildAttrs::AllowIEEE754);
708 // FIXME: add more flags to ARMBuildAttributes.h
709 // 8-bytes alignment stuff.
710 ATS.emitAttribute(ARMBuildAttrs::ABI_align_needed, 1);
711 ATS.emitAttribute(ARMBuildAttrs::ABI_align_preserved, 1);
713 // Hard float. Use both S and D registers and conform to AAPCS-VFP.
714 if (STI.isAAPCS_ABI() && TM.Options.FloatABIType == FloatABI::Hard)
715 ATS.emitAttribute(ARMBuildAttrs::ABI_VFP_args, ARMBuildAttrs::HardFPAAPCS);
717 // FIXME: To support emitting this build attribute as GCC does, the
718 // -mfp16-format option and associated plumbing must be
719 // supported. For now the __fp16 type is exposed by default, so this
720 // attribute should be emitted with value 1.
721 ATS.emitAttribute(ARMBuildAttrs::ABI_FP_16bit_format,
722 ARMBuildAttrs::FP16FormatIEEE);
725 if (const Module *SourceModule = MMI->getModule()) {
726 // ABI_PCS_wchar_t to indicate wchar_t width
727 // FIXME: There is no way to emit value 0 (wchar_t prohibited).
728 if (auto WCharWidthValue = mdconst::extract_or_null<ConstantInt>(
729 SourceModule->getModuleFlag("wchar_size"))) {
730 int WCharWidth = WCharWidthValue->getZExtValue();
731 assert((WCharWidth == 2 || WCharWidth == 4) &&
732 "wchar_t width must be 2 or 4 bytes");
733 ATS.emitAttribute(ARMBuildAttrs::ABI_PCS_wchar_t, WCharWidth);
736 // ABI_enum_size to indicate enum width
737 // FIXME: There is no way to emit value 0 (enums prohibited) or value 3
738 // (all enums contain a value needing 32 bits to encode).
739 if (auto EnumWidthValue = mdconst::extract_or_null<ConstantInt>(
740 SourceModule->getModuleFlag("min_enum_size"))) {
741 int EnumWidth = EnumWidthValue->getZExtValue();
742 assert((EnumWidth == 1 || EnumWidth == 4) &&
743 "Minimum enum width must be 1 or 4 bytes");
744 int EnumBuildAttr = EnumWidth == 1 ? 1 : 2;
745 ATS.emitAttribute(ARMBuildAttrs::ABI_enum_size, EnumBuildAttr);
750 // We currently do not support using R9 as the TLS pointer.
752 ATS.emitAttribute(ARMBuildAttrs::ABI_PCS_R9_use,
753 ARMBuildAttrs::R9IsSB);
754 else if (STI.isR9Reserved())
755 ATS.emitAttribute(ARMBuildAttrs::ABI_PCS_R9_use,
756 ARMBuildAttrs::R9Reserved);
758 ATS.emitAttribute(ARMBuildAttrs::ABI_PCS_R9_use,
759 ARMBuildAttrs::R9IsGPR);
762 //===----------------------------------------------------------------------===//
764 static MCSymbol *getPICLabel(StringRef Prefix, unsigned FunctionNumber,
765 unsigned LabelId, MCContext &Ctx) {
767 MCSymbol *Label = Ctx.getOrCreateSymbol(Twine(Prefix)
768 + "PC" + Twine(FunctionNumber) + "_" + Twine(LabelId));
772 static MCSymbolRefExpr::VariantKind
773 getModifierVariantKind(ARMCP::ARMCPModifier Modifier) {
775 case ARMCP::no_modifier:
776 return MCSymbolRefExpr::VK_None;
778 return MCSymbolRefExpr::VK_TLSGD;
780 return MCSymbolRefExpr::VK_TPOFF;
781 case ARMCP::GOTTPOFF:
782 return MCSymbolRefExpr::VK_GOTTPOFF;
784 return MCSymbolRefExpr::VK_ARM_SBREL;
785 case ARMCP::GOT_PREL:
786 return MCSymbolRefExpr::VK_ARM_GOT_PREL;
788 return MCSymbolRefExpr::VK_SECREL;
790 llvm_unreachable("Invalid ARMCPModifier!");
793 MCSymbol *ARMAsmPrinter::GetARMGVSymbol(const GlobalValue *GV,
794 unsigned char TargetFlags) {
795 if (Subtarget->isTargetMachO()) {
797 (TargetFlags & ARMII::MO_NONLAZY) && Subtarget->isGVIndirectSymbol(GV);
800 return getSymbol(GV);
802 // FIXME: Remove this when Darwin transition to @GOT like syntax.
803 MCSymbol *MCSym = getSymbolWithGlobalValueBase(GV, "$non_lazy_ptr");
804 MachineModuleInfoMachO &MMIMachO =
805 MMI->getObjFileInfo<MachineModuleInfoMachO>();
806 MachineModuleInfoImpl::StubValueTy &StubSym =
807 GV->isThreadLocal() ? MMIMachO.getThreadLocalGVStubEntry(MCSym)
808 : MMIMachO.getGVStubEntry(MCSym);
810 if (!StubSym.getPointer())
811 StubSym = MachineModuleInfoImpl::StubValueTy(getSymbol(GV),
812 !GV->hasInternalLinkage());
814 } else if (Subtarget->isTargetCOFF()) {
815 assert(Subtarget->isTargetWindows() &&
816 "Windows is the only supported COFF target");
818 bool IsIndirect = (TargetFlags & ARMII::MO_DLLIMPORT);
820 return getSymbol(GV);
822 SmallString<128> Name;
824 getNameWithPrefix(Name, GV);
826 return OutContext.getOrCreateSymbol(Name);
827 } else if (Subtarget->isTargetELF()) {
828 return getSymbol(GV);
830 llvm_unreachable("unexpected target");
834 EmitMachineConstantPoolValue(MachineConstantPoolValue *MCPV) {
835 const DataLayout &DL = getDataLayout();
836 int Size = DL.getTypeAllocSize(MCPV->getType());
838 ARMConstantPoolValue *ACPV = static_cast<ARMConstantPoolValue*>(MCPV);
840 if (ACPV->isPromotedGlobal()) {
841 // This constant pool entry is actually a global whose storage has been
842 // promoted into the constant pool. This global may be referenced still
843 // by debug information, and due to the way AsmPrinter is set up, the debug
844 // info is immutable by the time we decide to promote globals to constant
845 // pools. Because of this, we need to ensure we emit a symbol for the global
846 // with private linkage (the default) so debug info can refer to it.
848 // However, if this global is promoted into several functions we must ensure
849 // we don't try and emit duplicate symbols!
850 auto *ACPC = cast<ARMConstantPoolConstant>(ACPV);
851 for (const auto *GV : ACPC->promotedGlobals()) {
852 if (!EmittedPromotedGlobalLabels.count(GV)) {
853 MCSymbol *GVSym = getSymbol(GV);
854 OutStreamer->EmitLabel(GVSym);
855 EmittedPromotedGlobalLabels.insert(GV);
858 return EmitGlobalConstant(DL, ACPC->getPromotedGlobalInit());
862 if (ACPV->isLSDA()) {
863 MCSym = getCurExceptionSym();
864 } else if (ACPV->isBlockAddress()) {
865 const BlockAddress *BA =
866 cast<ARMConstantPoolConstant>(ACPV)->getBlockAddress();
867 MCSym = GetBlockAddressSymbol(BA);
868 } else if (ACPV->isGlobalValue()) {
869 const GlobalValue *GV = cast<ARMConstantPoolConstant>(ACPV)->getGV();
871 // On Darwin, const-pool entries may get the "FOO$non_lazy_ptr" mangling, so
872 // flag the global as MO_NONLAZY.
873 unsigned char TF = Subtarget->isTargetMachO() ? ARMII::MO_NONLAZY : 0;
874 MCSym = GetARMGVSymbol(GV, TF);
875 } else if (ACPV->isMachineBasicBlock()) {
876 const MachineBasicBlock *MBB = cast<ARMConstantPoolMBB>(ACPV)->getMBB();
877 MCSym = MBB->getSymbol();
879 assert(ACPV->isExtSymbol() && "unrecognized constant pool value");
880 auto Sym = cast<ARMConstantPoolSymbol>(ACPV)->getSymbol();
881 MCSym = GetExternalSymbolSymbol(Sym);
884 // Create an MCSymbol for the reference.
886 MCSymbolRefExpr::create(MCSym, getModifierVariantKind(ACPV->getModifier()),
889 if (ACPV->getPCAdjustment()) {
891 getPICLabel(DL.getPrivateGlobalPrefix(), getFunctionNumber(),
892 ACPV->getLabelId(), OutContext);
893 const MCExpr *PCRelExpr = MCSymbolRefExpr::create(PCLabel, OutContext);
895 MCBinaryExpr::createAdd(PCRelExpr,
896 MCConstantExpr::create(ACPV->getPCAdjustment(),
899 if (ACPV->mustAddCurrentAddress()) {
900 // We want "(<expr> - .)", but MC doesn't have a concept of the '.'
901 // label, so just emit a local label end reference that instead.
902 MCSymbol *DotSym = OutContext.createTempSymbol();
903 OutStreamer->EmitLabel(DotSym);
904 const MCExpr *DotExpr = MCSymbolRefExpr::create(DotSym, OutContext);
905 PCRelExpr = MCBinaryExpr::createSub(PCRelExpr, DotExpr, OutContext);
907 Expr = MCBinaryExpr::createSub(Expr, PCRelExpr, OutContext);
909 OutStreamer->EmitValue(Expr, Size);
912 void ARMAsmPrinter::EmitJumpTableAddrs(const MachineInstr *MI) {
913 const MachineOperand &MO1 = MI->getOperand(1);
914 unsigned JTI = MO1.getIndex();
916 // Make sure the Thumb jump table is 4-byte aligned. This will be a nop for
920 // Emit a label for the jump table.
921 MCSymbol *JTISymbol = GetARMJTIPICJumpTableLabel(JTI);
922 OutStreamer->EmitLabel(JTISymbol);
924 // Mark the jump table as data-in-code.
925 OutStreamer->EmitDataRegion(MCDR_DataRegionJT32);
927 // Emit each entry of the table.
928 const MachineJumpTableInfo *MJTI = MF->getJumpTableInfo();
929 const std::vector<MachineJumpTableEntry> &JT = MJTI->getJumpTables();
930 const std::vector<MachineBasicBlock*> &JTBBs = JT[JTI].MBBs;
932 for (MachineBasicBlock *MBB : JTBBs) {
933 // Construct an MCExpr for the entry. We want a value of the form:
934 // (BasicBlockAddr - TableBeginAddr)
936 // For example, a table with entries jumping to basic blocks BB0 and BB1
939 // .word (LBB0 - LJTI_0_0)
940 // .word (LBB1 - LJTI_0_0)
941 const MCExpr *Expr = MCSymbolRefExpr::create(MBB->getSymbol(), OutContext);
943 if (isPositionIndependent() || Subtarget->isROPI())
944 Expr = MCBinaryExpr::createSub(Expr, MCSymbolRefExpr::create(JTISymbol,
947 // If we're generating a table of Thumb addresses in static relocation
948 // model, we need to add one to keep interworking correctly.
949 else if (AFI->isThumbFunction())
950 Expr = MCBinaryExpr::createAdd(Expr, MCConstantExpr::create(1,OutContext),
952 OutStreamer->EmitValue(Expr, 4);
954 // Mark the end of jump table data-in-code region.
955 OutStreamer->EmitDataRegion(MCDR_DataRegionEnd);
958 void ARMAsmPrinter::EmitJumpTableInsts(const MachineInstr *MI) {
959 const MachineOperand &MO1 = MI->getOperand(1);
960 unsigned JTI = MO1.getIndex();
962 // Make sure the Thumb jump table is 4-byte aligned. This will be a nop for
966 // Emit a label for the jump table.
967 MCSymbol *JTISymbol = GetARMJTIPICJumpTableLabel(JTI);
968 OutStreamer->EmitLabel(JTISymbol);
970 // Emit each entry of the table.
971 const MachineJumpTableInfo *MJTI = MF->getJumpTableInfo();
972 const std::vector<MachineJumpTableEntry> &JT = MJTI->getJumpTables();
973 const std::vector<MachineBasicBlock*> &JTBBs = JT[JTI].MBBs;
975 for (MachineBasicBlock *MBB : JTBBs) {
976 const MCExpr *MBBSymbolExpr = MCSymbolRefExpr::create(MBB->getSymbol(),
978 // If this isn't a TBB or TBH, the entries are direct branch instructions.
979 EmitToStreamer(*OutStreamer, MCInstBuilder(ARM::t2B)
980 .addExpr(MBBSymbolExpr)
986 void ARMAsmPrinter::EmitJumpTableTBInst(const MachineInstr *MI,
987 unsigned OffsetWidth) {
988 assert((OffsetWidth == 1 || OffsetWidth == 2) && "invalid tbb/tbh width");
989 const MachineOperand &MO1 = MI->getOperand(1);
990 unsigned JTI = MO1.getIndex();
992 if (Subtarget->isThumb1Only())
995 MCSymbol *JTISymbol = GetARMJTIPICJumpTableLabel(JTI);
996 OutStreamer->EmitLabel(JTISymbol);
998 // Emit each entry of the table.
999 const MachineJumpTableInfo *MJTI = MF->getJumpTableInfo();
1000 const std::vector<MachineJumpTableEntry> &JT = MJTI->getJumpTables();
1001 const std::vector<MachineBasicBlock*> &JTBBs = JT[JTI].MBBs;
1003 // Mark the jump table as data-in-code.
1004 OutStreamer->EmitDataRegion(OffsetWidth == 1 ? MCDR_DataRegionJT8
1005 : MCDR_DataRegionJT16);
1007 for (auto MBB : JTBBs) {
1008 const MCExpr *MBBSymbolExpr = MCSymbolRefExpr::create(MBB->getSymbol(),
1010 // Otherwise it's an offset from the dispatch instruction. Construct an
1011 // MCExpr for the entry. We want a value of the form:
1012 // (BasicBlockAddr - TBBInstAddr + 4) / 2
1014 // For example, a TBB table with entries jumping to basic blocks BB0 and BB1
1017 // .byte (LBB0 - (LCPI0_0 + 4)) / 2
1018 // .byte (LBB1 - (LCPI0_0 + 4)) / 2
1019 // where LCPI0_0 is a label defined just before the TBB instruction using
1021 MCSymbol *TBInstPC = GetCPISymbol(MI->getOperand(0).getImm());
1022 const MCExpr *Expr = MCBinaryExpr::createAdd(
1023 MCSymbolRefExpr::create(TBInstPC, OutContext),
1024 MCConstantExpr::create(4, OutContext), OutContext);
1025 Expr = MCBinaryExpr::createSub(MBBSymbolExpr, Expr, OutContext);
1026 Expr = MCBinaryExpr::createDiv(Expr, MCConstantExpr::create(2, OutContext),
1028 OutStreamer->EmitValue(Expr, OffsetWidth);
1030 // Mark the end of jump table data-in-code region. 32-bit offsets use
1031 // actual branch instructions here, so we don't mark those as a data-region
1033 OutStreamer->EmitDataRegion(MCDR_DataRegionEnd);
1035 // Make sure the next instruction is 2-byte aligned.
1039 void ARMAsmPrinter::EmitUnwindingInstruction(const MachineInstr *MI) {
1040 assert(MI->getFlag(MachineInstr::FrameSetup) &&
1041 "Only instruction which are involved into frame setup code are allowed");
1043 MCTargetStreamer &TS = *OutStreamer->getTargetStreamer();
1044 ARMTargetStreamer &ATS = static_cast<ARMTargetStreamer &>(TS);
1045 const MachineFunction &MF = *MI->getParent()->getParent();
1046 const TargetRegisterInfo *RegInfo = MF.getSubtarget().getRegisterInfo();
1047 const ARMFunctionInfo &AFI = *MF.getInfo<ARMFunctionInfo>();
1049 unsigned FramePtr = RegInfo->getFrameRegister(MF);
1050 unsigned Opc = MI->getOpcode();
1051 unsigned SrcReg, DstReg;
1053 if (Opc == ARM::tPUSH || Opc == ARM::tLDRpci) {
1054 // Two special cases:
1055 // 1) tPUSH does not have src/dst regs.
1056 // 2) for Thumb1 code we sometimes materialize the constant via constpool
1057 // load. Yes, this is pretty fragile, but for now I don't see better
1059 SrcReg = DstReg = ARM::SP;
1061 SrcReg = MI->getOperand(1).getReg();
1062 DstReg = MI->getOperand(0).getReg();
1065 // Try to figure out the unwinding opcode out of src / dst regs.
1066 if (MI->mayStore()) {
1068 assert(DstReg == ARM::SP &&
1069 "Only stack pointer as a destination reg is supported");
1071 SmallVector<unsigned, 4> RegList;
1072 // Skip src & dst reg, and pred ops.
1073 unsigned StartOp = 2 + 2;
1074 // Use all the operands.
1075 unsigned NumOffset = 0;
1076 // Amount of SP adjustment folded into a push.
1082 llvm_unreachable("Unsupported opcode for unwinding information");
1084 // Special case here: no src & dst reg, but two extra imp ops.
1085 StartOp = 2; NumOffset = 2;
1087 case ARM::STMDB_UPD:
1088 case ARM::t2STMDB_UPD:
1089 case ARM::VSTMDDB_UPD:
1090 assert(SrcReg == ARM::SP &&
1091 "Only stack pointer as a source reg is supported");
1092 for (unsigned i = StartOp, NumOps = MI->getNumOperands() - NumOffset;
1094 const MachineOperand &MO = MI->getOperand(i);
1095 // Actually, there should never be any impdef stuff here. Skip it
1096 // temporary to workaround PR11902.
1097 if (MO.isImplicit())
1099 // Registers, pushed as a part of folding an SP update into the
1100 // push instruction are marked as undef and should not be
1101 // restored when unwinding, because the function can modify the
1102 // corresponding stack slots.
1104 assert(RegList.empty() &&
1105 "Pad registers must come before restored ones");
1109 RegList.push_back(MO.getReg());
1112 case ARM::STR_PRE_IMM:
1113 case ARM::STR_PRE_REG:
1114 case ARM::t2STR_PRE:
1115 assert(MI->getOperand(2).getReg() == ARM::SP &&
1116 "Only stack pointer as a source reg is supported");
1117 RegList.push_back(SrcReg);
1120 if (MAI->getExceptionHandlingType() == ExceptionHandling::ARM) {
1121 ATS.emitRegSave(RegList, Opc == ARM::VSTMDDB_UPD);
1122 // Account for the SP adjustment, folded into the push.
1127 // Changes of stack / frame pointer.
1128 if (SrcReg == ARM::SP) {
1133 llvm_unreachable("Unsupported opcode for unwinding information");
1140 Offset = -MI->getOperand(2).getImm();
1144 Offset = MI->getOperand(2).getImm();
1147 Offset = MI->getOperand(2).getImm()*4;
1151 Offset = -MI->getOperand(2).getImm()*4;
1153 case ARM::tLDRpci: {
1154 // Grab the constpool index and check, whether it corresponds to
1155 // original or cloned constpool entry.
1156 unsigned CPI = MI->getOperand(1).getIndex();
1157 const MachineConstantPool *MCP = MF.getConstantPool();
1158 if (CPI >= MCP->getConstants().size())
1159 CPI = AFI.getOriginalCPIdx(CPI);
1160 assert(CPI != -1U && "Invalid constpool index");
1162 // Derive the actual offset.
1163 const MachineConstantPoolEntry &CPE = MCP->getConstants()[CPI];
1164 assert(!CPE.isMachineConstantPoolEntry() && "Invalid constpool entry");
1165 // FIXME: Check for user, it should be "add" instruction!
1166 Offset = -cast<ConstantInt>(CPE.Val.ConstVal)->getSExtValue();
1171 if (MAI->getExceptionHandlingType() == ExceptionHandling::ARM) {
1172 if (DstReg == FramePtr && FramePtr != ARM::SP)
1173 // Set-up of the frame pointer. Positive values correspond to "add"
1175 ATS.emitSetFP(FramePtr, ARM::SP, -Offset);
1176 else if (DstReg == ARM::SP) {
1177 // Change of SP by an offset. Positive values correspond to "sub"
1179 ATS.emitPad(Offset);
1181 // Move of SP to a register. Positive values correspond to an "add"
1183 ATS.emitMovSP(DstReg, -Offset);
1186 } else if (DstReg == ARM::SP) {
1188 llvm_unreachable("Unsupported opcode for unwinding information");
1192 llvm_unreachable("Unsupported opcode for unwinding information");
1197 // Simple pseudo-instructions have their lowering (with expansion to real
1198 // instructions) auto-generated.
1199 #include "ARMGenMCPseudoLowering.inc"
1201 void ARMAsmPrinter::EmitInstruction(const MachineInstr *MI) {
1202 const DataLayout &DL = getDataLayout();
1203 MCTargetStreamer &TS = *OutStreamer->getTargetStreamer();
1204 ARMTargetStreamer &ATS = static_cast<ARMTargetStreamer &>(TS);
1206 const MachineFunction &MF = *MI->getParent()->getParent();
1207 const ARMSubtarget &STI = MF.getSubtarget<ARMSubtarget>();
1208 unsigned FramePtr = STI.useR7AsFramePointer() ? ARM::R7 : ARM::R11;
1210 // If we just ended a constant pool, mark it as such.
1211 if (InConstantPool && MI->getOpcode() != ARM::CONSTPOOL_ENTRY) {
1212 OutStreamer->EmitDataRegion(MCDR_DataRegionEnd);
1213 InConstantPool = false;
1216 // Emit unwinding stuff for frame-related instructions
1217 if (Subtarget->isTargetEHABICompatible() &&
1218 MI->getFlag(MachineInstr::FrameSetup))
1219 EmitUnwindingInstruction(MI);
1221 // Do any auto-generated pseudo lowerings.
1222 if (emitPseudoExpansionLowering(*OutStreamer, MI))
1225 assert(!convertAddSubFlagsOpcode(MI->getOpcode()) &&
1226 "Pseudo flag setting opcode should be expanded early");
1228 // Check for manual lowerings.
1229 unsigned Opc = MI->getOpcode();
1231 case ARM::t2MOVi32imm: llvm_unreachable("Should be lowered by thumb2it pass");
1232 case ARM::DBG_VALUE: llvm_unreachable("Should be handled by generic printing");
1234 case ARM::tLEApcrel:
1235 case ARM::t2LEApcrel: {
1236 // FIXME: Need to also handle globals and externals
1237 MCSymbol *CPISymbol = GetCPISymbol(MI->getOperand(1).getIndex());
1238 EmitToStreamer(*OutStreamer, MCInstBuilder(MI->getOpcode() ==
1239 ARM::t2LEApcrel ? ARM::t2ADR
1240 : (MI->getOpcode() == ARM::tLEApcrel ? ARM::tADR
1242 .addReg(MI->getOperand(0).getReg())
1243 .addExpr(MCSymbolRefExpr::create(CPISymbol, OutContext))
1244 // Add predicate operands.
1245 .addImm(MI->getOperand(2).getImm())
1246 .addReg(MI->getOperand(3).getReg()));
1249 case ARM::LEApcrelJT:
1250 case ARM::tLEApcrelJT:
1251 case ARM::t2LEApcrelJT: {
1252 MCSymbol *JTIPICSymbol =
1253 GetARMJTIPICJumpTableLabel(MI->getOperand(1).getIndex());
1254 EmitToStreamer(*OutStreamer, MCInstBuilder(MI->getOpcode() ==
1255 ARM::t2LEApcrelJT ? ARM::t2ADR
1256 : (MI->getOpcode() == ARM::tLEApcrelJT ? ARM::tADR
1258 .addReg(MI->getOperand(0).getReg())
1259 .addExpr(MCSymbolRefExpr::create(JTIPICSymbol, OutContext))
1260 // Add predicate operands.
1261 .addImm(MI->getOperand(2).getImm())
1262 .addReg(MI->getOperand(3).getReg()));
1265 // Darwin call instructions are just normal call instructions with different
1266 // clobber semantics (they clobber R9).
1267 case ARM::BX_CALL: {
1268 EmitToStreamer(*OutStreamer, MCInstBuilder(ARM::MOVr)
1271 // Add predicate operands.
1274 // Add 's' bit operand (always reg0 for this)
1277 assert(Subtarget->hasV4TOps());
1278 EmitToStreamer(*OutStreamer, MCInstBuilder(ARM::BX)
1279 .addReg(MI->getOperand(0).getReg()));
1282 case ARM::tBX_CALL: {
1283 if (Subtarget->hasV5TOps())
1284 llvm_unreachable("Expected BLX to be selected for v5t+");
1286 // On ARM v4t, when doing a call from thumb mode, we need to ensure
1287 // that the saved lr has its LSB set correctly (the arch doesn't
1289 // So here we generate a bl to a small jump pad that does bx rN.
1290 // The jump pads are emitted after the function body.
1292 unsigned TReg = MI->getOperand(0).getReg();
1293 MCSymbol *TRegSym = nullptr;
1294 for (std::pair<unsigned, MCSymbol *> &TIP : ThumbIndirectPads) {
1295 if (TIP.first == TReg) {
1296 TRegSym = TIP.second;
1302 TRegSym = OutContext.createTempSymbol();
1303 ThumbIndirectPads.push_back(std::make_pair(TReg, TRegSym));
1306 // Create a link-saving branch to the Reg Indirect Jump Pad.
1307 EmitToStreamer(*OutStreamer, MCInstBuilder(ARM::tBL)
1308 // Predicate comes first here.
1309 .addImm(ARMCC::AL).addReg(0)
1310 .addExpr(MCSymbolRefExpr::create(TRegSym, OutContext)));
1313 case ARM::BMOVPCRX_CALL: {
1314 EmitToStreamer(*OutStreamer, MCInstBuilder(ARM::MOVr)
1317 // Add predicate operands.
1320 // Add 's' bit operand (always reg0 for this)
1323 EmitToStreamer(*OutStreamer, MCInstBuilder(ARM::MOVr)
1325 .addReg(MI->getOperand(0).getReg())
1326 // Add predicate operands.
1329 // Add 's' bit operand (always reg0 for this)
1333 case ARM::BMOVPCB_CALL: {
1334 EmitToStreamer(*OutStreamer, MCInstBuilder(ARM::MOVr)
1337 // Add predicate operands.
1340 // Add 's' bit operand (always reg0 for this)
1343 const MachineOperand &Op = MI->getOperand(0);
1344 const GlobalValue *GV = Op.getGlobal();
1345 const unsigned TF = Op.getTargetFlags();
1346 MCSymbol *GVSym = GetARMGVSymbol(GV, TF);
1347 const MCExpr *GVSymExpr = MCSymbolRefExpr::create(GVSym, OutContext);
1348 EmitToStreamer(*OutStreamer, MCInstBuilder(ARM::Bcc)
1350 // Add predicate operands.
1355 case ARM::MOVi16_ga_pcrel:
1356 case ARM::t2MOVi16_ga_pcrel: {
1358 TmpInst.setOpcode(Opc == ARM::MOVi16_ga_pcrel? ARM::MOVi16 : ARM::t2MOVi16);
1359 TmpInst.addOperand(MCOperand::createReg(MI->getOperand(0).getReg()));
1361 unsigned TF = MI->getOperand(1).getTargetFlags();
1362 const GlobalValue *GV = MI->getOperand(1).getGlobal();
1363 MCSymbol *GVSym = GetARMGVSymbol(GV, TF);
1364 const MCExpr *GVSymExpr = MCSymbolRefExpr::create(GVSym, OutContext);
1366 MCSymbol *LabelSym =
1367 getPICLabel(DL.getPrivateGlobalPrefix(), getFunctionNumber(),
1368 MI->getOperand(2).getImm(), OutContext);
1369 const MCExpr *LabelSymExpr= MCSymbolRefExpr::create(LabelSym, OutContext);
1370 unsigned PCAdj = (Opc == ARM::MOVi16_ga_pcrel) ? 8 : 4;
1371 const MCExpr *PCRelExpr =
1372 ARMMCExpr::createLower16(MCBinaryExpr::createSub(GVSymExpr,
1373 MCBinaryExpr::createAdd(LabelSymExpr,
1374 MCConstantExpr::create(PCAdj, OutContext),
1375 OutContext), OutContext), OutContext);
1376 TmpInst.addOperand(MCOperand::createExpr(PCRelExpr));
1378 // Add predicate operands.
1379 TmpInst.addOperand(MCOperand::createImm(ARMCC::AL));
1380 TmpInst.addOperand(MCOperand::createReg(0));
1381 // Add 's' bit operand (always reg0 for this)
1382 TmpInst.addOperand(MCOperand::createReg(0));
1383 EmitToStreamer(*OutStreamer, TmpInst);
1386 case ARM::MOVTi16_ga_pcrel:
1387 case ARM::t2MOVTi16_ga_pcrel: {
1389 TmpInst.setOpcode(Opc == ARM::MOVTi16_ga_pcrel
1390 ? ARM::MOVTi16 : ARM::t2MOVTi16);
1391 TmpInst.addOperand(MCOperand::createReg(MI->getOperand(0).getReg()));
1392 TmpInst.addOperand(MCOperand::createReg(MI->getOperand(1).getReg()));
1394 unsigned TF = MI->getOperand(2).getTargetFlags();
1395 const GlobalValue *GV = MI->getOperand(2).getGlobal();
1396 MCSymbol *GVSym = GetARMGVSymbol(GV, TF);
1397 const MCExpr *GVSymExpr = MCSymbolRefExpr::create(GVSym, OutContext);
1399 MCSymbol *LabelSym =
1400 getPICLabel(DL.getPrivateGlobalPrefix(), getFunctionNumber(),
1401 MI->getOperand(3).getImm(), OutContext);
1402 const MCExpr *LabelSymExpr= MCSymbolRefExpr::create(LabelSym, OutContext);
1403 unsigned PCAdj = (Opc == ARM::MOVTi16_ga_pcrel) ? 8 : 4;
1404 const MCExpr *PCRelExpr =
1405 ARMMCExpr::createUpper16(MCBinaryExpr::createSub(GVSymExpr,
1406 MCBinaryExpr::createAdd(LabelSymExpr,
1407 MCConstantExpr::create(PCAdj, OutContext),
1408 OutContext), OutContext), OutContext);
1409 TmpInst.addOperand(MCOperand::createExpr(PCRelExpr));
1410 // Add predicate operands.
1411 TmpInst.addOperand(MCOperand::createImm(ARMCC::AL));
1412 TmpInst.addOperand(MCOperand::createReg(0));
1413 // Add 's' bit operand (always reg0 for this)
1414 TmpInst.addOperand(MCOperand::createReg(0));
1415 EmitToStreamer(*OutStreamer, TmpInst);
1418 case ARM::tPICADD: {
1419 // This is a pseudo op for a label + instruction sequence, which looks like:
1422 // This adds the address of LPC0 to r0.
1425 OutStreamer->EmitLabel(getPICLabel(DL.getPrivateGlobalPrefix(),
1426 getFunctionNumber(),
1427 MI->getOperand(2).getImm(), OutContext));
1429 // Form and emit the add.
1430 EmitToStreamer(*OutStreamer, MCInstBuilder(ARM::tADDhirr)
1431 .addReg(MI->getOperand(0).getReg())
1432 .addReg(MI->getOperand(0).getReg())
1434 // Add predicate operands.
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(),
1448 MI->getOperand(2).getImm(), OutContext));
1450 // Form and emit the add.
1451 EmitToStreamer(*OutStreamer, MCInstBuilder(ARM::ADDrr)
1452 .addReg(MI->getOperand(0).getReg())
1454 .addReg(MI->getOperand(1).getReg())
1455 // Add predicate operands.
1456 .addImm(MI->getOperand(3).getImm())
1457 .addReg(MI->getOperand(4).getReg())
1458 // Add 's' bit operand (always reg0 for this)
1469 case ARM::PICLDRSH: {
1470 // This is a pseudo op for a label + instruction sequence, which looks like:
1473 // The LCP0 label is referenced by a constant pool entry in order to get
1474 // a PC-relative address at the ldr instruction.
1477 OutStreamer->EmitLabel(getPICLabel(DL.getPrivateGlobalPrefix(),
1478 getFunctionNumber(),
1479 MI->getOperand(2).getImm(), OutContext));
1481 // Form and emit the load
1483 switch (MI->getOpcode()) {
1485 llvm_unreachable("Unexpected opcode!");
1486 case ARM::PICSTR: Opcode = ARM::STRrs; break;
1487 case ARM::PICSTRB: Opcode = ARM::STRBrs; break;
1488 case ARM::PICSTRH: Opcode = ARM::STRH; break;
1489 case ARM::PICLDR: Opcode = ARM::LDRrs; break;
1490 case ARM::PICLDRB: Opcode = ARM::LDRBrs; break;
1491 case ARM::PICLDRH: Opcode = ARM::LDRH; break;
1492 case ARM::PICLDRSB: Opcode = ARM::LDRSB; break;
1493 case ARM::PICLDRSH: Opcode = ARM::LDRSH; break;
1495 EmitToStreamer(*OutStreamer, MCInstBuilder(Opcode)
1496 .addReg(MI->getOperand(0).getReg())
1498 .addReg(MI->getOperand(1).getReg())
1500 // Add predicate operands.
1501 .addImm(MI->getOperand(3).getImm())
1502 .addReg(MI->getOperand(4).getReg()));
1506 case ARM::CONSTPOOL_ENTRY: {
1507 if (Subtarget->genExecuteOnly())
1508 llvm_unreachable("execute-only should not generate constant pools");
1510 /// CONSTPOOL_ENTRY - This instruction represents a floating constant pool
1511 /// in the function. The first operand is the ID# for this instruction, the
1512 /// second is the index into the MachineConstantPool that this is, the third
1513 /// is the size in bytes of this constant pool entry.
1514 /// The required alignment is specified on the basic block holding this MI.
1515 unsigned LabelId = (unsigned)MI->getOperand(0).getImm();
1516 unsigned CPIdx = (unsigned)MI->getOperand(1).getIndex();
1518 // If this is the first entry of the pool, mark it.
1519 if (!InConstantPool) {
1520 OutStreamer->EmitDataRegion(MCDR_DataRegion);
1521 InConstantPool = true;
1524 OutStreamer->EmitLabel(GetCPISymbol(LabelId));
1526 const MachineConstantPoolEntry &MCPE = MCP->getConstants()[CPIdx];
1527 if (MCPE.isMachineConstantPoolEntry())
1528 EmitMachineConstantPoolValue(MCPE.Val.MachineCPVal);
1530 EmitGlobalConstant(DL, MCPE.Val.ConstVal);
1533 case ARM::JUMPTABLE_ADDRS:
1534 EmitJumpTableAddrs(MI);
1536 case ARM::JUMPTABLE_INSTS:
1537 EmitJumpTableInsts(MI);
1539 case ARM::JUMPTABLE_TBB:
1540 case ARM::JUMPTABLE_TBH:
1541 EmitJumpTableTBInst(MI, MI->getOpcode() == ARM::JUMPTABLE_TBB ? 1 : 2);
1543 case ARM::t2BR_JT: {
1544 EmitToStreamer(*OutStreamer, MCInstBuilder(ARM::tMOVr)
1546 .addReg(MI->getOperand(0).getReg())
1547 // Add predicate operands.
1553 case ARM::t2TBH_JT: {
1554 unsigned Opc = MI->getOpcode() == ARM::t2TBB_JT ? ARM::t2TBB : ARM::t2TBH;
1555 // Lower and emit the PC label, then the instruction itself.
1556 OutStreamer->EmitLabel(GetCPISymbol(MI->getOperand(3).getImm()));
1557 EmitToStreamer(*OutStreamer, MCInstBuilder(Opc)
1558 .addReg(MI->getOperand(0).getReg())
1559 .addReg(MI->getOperand(1).getReg())
1560 // Add predicate operands.
1566 case ARM::tTBH_JT: {
1568 bool Is8Bit = MI->getOpcode() == ARM::tTBB_JT;
1569 unsigned Base = MI->getOperand(0).getReg();
1570 unsigned Idx = MI->getOperand(1).getReg();
1571 assert(MI->getOperand(1).isKill() && "We need the index register as scratch!");
1573 // Multiply up idx if necessary.
1575 EmitToStreamer(*OutStreamer, MCInstBuilder(ARM::tLSLri)
1580 // Add predicate operands.
1584 if (Base == ARM::PC) {
1585 // TBB [base, idx] =
1586 // ADDS idx, idx, base
1587 // LDRB idx, [idx, #4] ; or LDRH if TBH
1591 // When using PC as the base, it's important that there is no padding
1592 // between the last ADDS and the start of the jump table. The jump table
1593 // is 4-byte aligned, so we ensure we're 4 byte aligned here too.
1595 // FIXME: Ideally we could vary the LDRB index based on the padding
1596 // between the sequence and jump table, however that relies on MCExprs
1597 // for load indexes which are currently not supported.
1598 OutStreamer->EmitCodeAlignment(4);
1599 EmitToStreamer(*OutStreamer, MCInstBuilder(ARM::tADDhirr)
1603 // Add predicate operands.
1607 unsigned Opc = Is8Bit ? ARM::tLDRBi : ARM::tLDRHi;
1608 EmitToStreamer(*OutStreamer, MCInstBuilder(Opc)
1611 .addImm(Is8Bit ? 4 : 2)
1612 // Add predicate operands.
1616 // TBB [base, idx] =
1617 // LDRB idx, [base, idx] ; or LDRH if TBH
1621 unsigned Opc = Is8Bit ? ARM::tLDRBr : ARM::tLDRHr;
1622 EmitToStreamer(*OutStreamer, MCInstBuilder(Opc)
1626 // Add predicate operands.
1631 EmitToStreamer(*OutStreamer, MCInstBuilder(ARM::tLSLri)
1636 // Add predicate operands.
1640 OutStreamer->EmitLabel(GetCPISymbol(MI->getOperand(3).getImm()));
1641 EmitToStreamer(*OutStreamer, MCInstBuilder(ARM::tADDhirr)
1645 // Add predicate operands.
1654 unsigned Opc = MI->getOpcode() == ARM::BR_JTr ?
1655 ARM::MOVr : ARM::tMOVr;
1656 TmpInst.setOpcode(Opc);
1657 TmpInst.addOperand(MCOperand::createReg(ARM::PC));
1658 TmpInst.addOperand(MCOperand::createReg(MI->getOperand(0).getReg()));
1659 // Add predicate operands.
1660 TmpInst.addOperand(MCOperand::createImm(ARMCC::AL));
1661 TmpInst.addOperand(MCOperand::createReg(0));
1662 // Add 's' bit operand (always reg0 for this)
1663 if (Opc == ARM::MOVr)
1664 TmpInst.addOperand(MCOperand::createReg(0));
1665 EmitToStreamer(*OutStreamer, TmpInst);
1668 case ARM::BR_JTm_i12: {
1671 TmpInst.setOpcode(ARM::LDRi12);
1672 TmpInst.addOperand(MCOperand::createReg(ARM::PC));
1673 TmpInst.addOperand(MCOperand::createReg(MI->getOperand(0).getReg()));
1674 TmpInst.addOperand(MCOperand::createImm(MI->getOperand(2).getImm()));
1675 // Add predicate operands.
1676 TmpInst.addOperand(MCOperand::createImm(ARMCC::AL));
1677 TmpInst.addOperand(MCOperand::createReg(0));
1678 EmitToStreamer(*OutStreamer, TmpInst);
1681 case ARM::BR_JTm_rs: {
1684 TmpInst.setOpcode(ARM::LDRrs);
1685 TmpInst.addOperand(MCOperand::createReg(ARM::PC));
1686 TmpInst.addOperand(MCOperand::createReg(MI->getOperand(0).getReg()));
1687 TmpInst.addOperand(MCOperand::createReg(MI->getOperand(1).getReg()));
1688 TmpInst.addOperand(MCOperand::createImm(MI->getOperand(2).getImm()));
1689 // Add predicate operands.
1690 TmpInst.addOperand(MCOperand::createImm(ARMCC::AL));
1691 TmpInst.addOperand(MCOperand::createReg(0));
1692 EmitToStreamer(*OutStreamer, TmpInst);
1695 case ARM::BR_JTadd: {
1696 // add pc, target, idx
1697 EmitToStreamer(*OutStreamer, MCInstBuilder(ARM::ADDrr)
1699 .addReg(MI->getOperand(0).getReg())
1700 .addReg(MI->getOperand(1).getReg())
1701 // Add predicate operands.
1704 // Add 's' bit operand (always reg0 for this)
1709 OutStreamer->EmitZeros(MI->getOperand(1).getImm());
1712 // Non-Darwin binutils don't yet support the "trap" mnemonic.
1713 // FIXME: Remove this special case when they do.
1714 if (!Subtarget->isTargetMachO()) {
1715 uint32_t Val = 0xe7ffdefeUL;
1716 OutStreamer->AddComment("trap");
1722 case ARM::TRAPNaCl: {
1723 uint32_t Val = 0xe7fedef0UL;
1724 OutStreamer->AddComment("trap");
1729 // Non-Darwin binutils don't yet support the "trap" mnemonic.
1730 // FIXME: Remove this special case when they do.
1731 if (!Subtarget->isTargetMachO()) {
1732 uint16_t Val = 0xdefe;
1733 OutStreamer->AddComment("trap");
1734 ATS.emitInst(Val, 'n');
1739 case ARM::t2Int_eh_sjlj_setjmp:
1740 case ARM::t2Int_eh_sjlj_setjmp_nofp:
1741 case ARM::tInt_eh_sjlj_setjmp: {
1742 // Two incoming args: GPR:$src, GPR:$val
1745 // str $val, [$src, #4]
1750 unsigned SrcReg = MI->getOperand(0).getReg();
1751 unsigned ValReg = MI->getOperand(1).getReg();
1752 MCSymbol *Label = OutContext.createTempSymbol("SJLJEH", false, true);
1753 OutStreamer->AddComment("eh_setjmp begin");
1754 EmitToStreamer(*OutStreamer, MCInstBuilder(ARM::tMOVr)
1761 EmitToStreamer(*OutStreamer, MCInstBuilder(ARM::tADDi3)
1771 EmitToStreamer(*OutStreamer, MCInstBuilder(ARM::tSTRi)
1774 // The offset immediate is #4. The operand value is scaled by 4 for the
1775 // tSTR instruction.
1781 EmitToStreamer(*OutStreamer, MCInstBuilder(ARM::tMOVi8)
1789 const MCExpr *SymbolExpr = MCSymbolRefExpr::create(Label, OutContext);
1790 EmitToStreamer(*OutStreamer, MCInstBuilder(ARM::tB)
1791 .addExpr(SymbolExpr)
1795 OutStreamer->AddComment("eh_setjmp end");
1796 EmitToStreamer(*OutStreamer, MCInstBuilder(ARM::tMOVi8)
1804 OutStreamer->EmitLabel(Label);
1808 case ARM::Int_eh_sjlj_setjmp_nofp:
1809 case ARM::Int_eh_sjlj_setjmp: {
1810 // Two incoming args: GPR:$src, GPR:$val
1812 // str $val, [$src, #+4]
1816 unsigned SrcReg = MI->getOperand(0).getReg();
1817 unsigned ValReg = MI->getOperand(1).getReg();
1819 OutStreamer->AddComment("eh_setjmp begin");
1820 EmitToStreamer(*OutStreamer, MCInstBuilder(ARM::ADDri)
1827 // 's' bit operand (always reg0 for this).
1830 EmitToStreamer(*OutStreamer, MCInstBuilder(ARM::STRi12)
1838 EmitToStreamer(*OutStreamer, MCInstBuilder(ARM::MOVi)
1844 // 's' bit operand (always reg0 for this).
1847 EmitToStreamer(*OutStreamer, MCInstBuilder(ARM::ADDri)
1854 // 's' bit operand (always reg0 for this).
1857 OutStreamer->AddComment("eh_setjmp end");
1858 EmitToStreamer(*OutStreamer, MCInstBuilder(ARM::MOVi)
1864 // 's' bit operand (always reg0 for this).
1868 case ARM::Int_eh_sjlj_longjmp: {
1869 // ldr sp, [$src, #8]
1870 // ldr $scratch, [$src, #4]
1873 unsigned SrcReg = MI->getOperand(0).getReg();
1874 unsigned ScratchReg = MI->getOperand(1).getReg();
1875 EmitToStreamer(*OutStreamer, MCInstBuilder(ARM::LDRi12)
1883 EmitToStreamer(*OutStreamer, MCInstBuilder(ARM::LDRi12)
1891 if (STI.isTargetDarwin() || STI.isTargetWindows()) {
1892 // These platforms always use the same frame register
1893 EmitToStreamer(*OutStreamer, MCInstBuilder(ARM::LDRi12)
1901 // If the calling code might use either R7 or R11 as
1902 // frame pointer register, restore it into both.
1903 EmitToStreamer(*OutStreamer, MCInstBuilder(ARM::LDRi12)
1910 EmitToStreamer(*OutStreamer, MCInstBuilder(ARM::LDRi12)
1919 assert(Subtarget->hasV4TOps());
1920 EmitToStreamer(*OutStreamer, MCInstBuilder(ARM::BX)
1927 case ARM::tInt_eh_sjlj_longjmp: {
1928 // ldr $scratch, [$src, #8]
1930 // ldr $scratch, [$src, #4]
1933 unsigned SrcReg = MI->getOperand(0).getReg();
1934 unsigned ScratchReg = MI->getOperand(1).getReg();
1936 EmitToStreamer(*OutStreamer, MCInstBuilder(ARM::tLDRi)
1939 // The offset immediate is #8. The operand value is scaled by 4 for the
1940 // tLDR instruction.
1946 EmitToStreamer(*OutStreamer, MCInstBuilder(ARM::tMOVr)
1953 EmitToStreamer(*OutStreamer, MCInstBuilder(ARM::tLDRi)
1961 if (STI.isTargetDarwin() || STI.isTargetWindows()) {
1962 // These platforms always use the same frame register
1963 EmitToStreamer(*OutStreamer, MCInstBuilder(ARM::tLDRi)
1971 // If the calling code might use either R7 or R11 as
1972 // frame pointer register, restore it into both.
1973 EmitToStreamer(*OutStreamer, MCInstBuilder(ARM::tLDRi)
1980 EmitToStreamer(*OutStreamer, MCInstBuilder(ARM::tLDRi)
1989 EmitToStreamer(*OutStreamer, MCInstBuilder(ARM::tBX)
1996 case ARM::tInt_WIN_eh_sjlj_longjmp: {
1997 // ldr.w r11, [$src, #0]
1998 // ldr.w sp, [$src, #8]
1999 // ldr.w pc, [$src, #4]
2001 unsigned SrcReg = MI->getOperand(0).getReg();
2003 EmitToStreamer(*OutStreamer, MCInstBuilder(ARM::t2LDRi12)
2010 EmitToStreamer(*OutStreamer, MCInstBuilder(ARM::t2LDRi12)
2017 EmitToStreamer(*OutStreamer, MCInstBuilder(ARM::t2LDRi12)
2026 case ARM::PATCHABLE_FUNCTION_ENTER:
2027 LowerPATCHABLE_FUNCTION_ENTER(*MI);
2029 case ARM::PATCHABLE_FUNCTION_EXIT:
2030 LowerPATCHABLE_FUNCTION_EXIT(*MI);
2032 case ARM::PATCHABLE_TAIL_CALL:
2033 LowerPATCHABLE_TAIL_CALL(*MI);
2038 LowerARMMachineInstrToMCInst(MI, TmpInst, *this);
2040 EmitToStreamer(*OutStreamer, TmpInst);
2043 //===----------------------------------------------------------------------===//
2044 // Target Registry Stuff
2045 //===----------------------------------------------------------------------===//
2047 // Force static initialization.
2048 extern "C" void LLVMInitializeARMAsmPrinter() {
2049 RegisterAsmPrinter<ARMAsmPrinter> X(getTheARMLETarget());
2050 RegisterAsmPrinter<ARMAsmPrinter> Y(getTheARMBETarget());
2051 RegisterAsmPrinter<ARMAsmPrinter> A(getTheThumbLETarget());
2052 RegisterAsmPrinter<ARMAsmPrinter> B(getTheThumbBETarget());