[ORC] Add std::tuple support to SimplePackedSerialization.
[llvm-project.git] / llvm / lib / Target / ARM / ARMAsmPrinter.cpp
blobba594b7f0935747cdc5b31af27b54d00a92c0468
1 //===-- ARMAsmPrinter.cpp - Print machine code to an ARM .s file ----------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file contains a printer that converts from our internal representation
10 // of machine-dependent LLVM code to GAS-format ARM assembly language.
12 //===----------------------------------------------------------------------===//
14 #include "ARMAsmPrinter.h"
15 #include "ARM.h"
16 #include "ARMConstantPoolValue.h"
17 #include "ARMMachineFunctionInfo.h"
18 #include "ARMTargetMachine.h"
19 #include "ARMTargetObjectFile.h"
20 #include "MCTargetDesc/ARMAddressingModes.h"
21 #include "MCTargetDesc/ARMInstPrinter.h"
22 #include "MCTargetDesc/ARMMCExpr.h"
23 #include "TargetInfo/ARMTargetInfo.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"
51 using namespace llvm;
53 #define DEBUG_TYPE "asm-printer"
55 ARMAsmPrinter::ARMAsmPrinter(TargetMachine &TM,
56 std::unique_ptr<MCStreamer> Streamer)
57 : AsmPrinter(TM, std::move(Streamer)), Subtarget(nullptr), AFI(nullptr),
58 MCP(nullptr), InConstantPool(false), OptimizationGoals(-1) {}
60 void ARMAsmPrinter::emitFunctionBodyEnd() {
61 // Make sure to terminate any constant pools that were at the end
62 // of the function.
63 if (!InConstantPool)
64 return;
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);
73 } else {
74 OutStreamer->emitAssemblerFlag(MCAF_Code32);
77 // Emit symbol for CMSE non-secure entry point
78 if (AFI->isCmseNSEntryFunction()) {
79 MCSymbol *S =
80 OutContext.getOrCreateSymbol("__acle_se_" + CurrentFnSym->getName());
81 emitLinkage(&MF->getFunction(), S);
82 OutStreamer->emitSymbolAttribute(S, MCSA_ELF_TypeFunction);
83 OutStreamer->emitLabel(S);
86 OutStreamer->emitLabel(CurrentFnSym);
89 void ARMAsmPrinter::emitXXStructor(const DataLayout &DL, const Constant *CV) {
90 uint64_t Size = getDataLayout().getTypeAllocSize(CV->getType());
91 assert(Size && "C++ constructor pointer had zero size!");
93 const GlobalValue *GV = dyn_cast<GlobalValue>(CV->stripPointerCasts());
94 assert(GV && "C++ constructor pointer was not a GlobalValue!");
96 const MCExpr *E = MCSymbolRefExpr::create(GetARMGVSymbol(GV,
97 ARMII::MO_NO_FLAG),
98 (Subtarget->isTargetELF()
99 ? MCSymbolRefExpr::VK_ARM_TARGET1
100 : MCSymbolRefExpr::VK_None),
101 OutContext);
103 OutStreamer->emitValue(E, Size);
106 void ARMAsmPrinter::emitGlobalVariable(const GlobalVariable *GV) {
107 if (PromotedGlobals.count(GV))
108 // The global was promoted into a constant pool. It should not be emitted.
109 return;
110 AsmPrinter::emitGlobalVariable(GV);
113 /// runOnMachineFunction - This uses the emitInstruction()
114 /// method to print assembly for each instruction.
116 bool ARMAsmPrinter::runOnMachineFunction(MachineFunction &MF) {
117 AFI = MF.getInfo<ARMFunctionInfo>();
118 MCP = MF.getConstantPool();
119 Subtarget = &MF.getSubtarget<ARMSubtarget>();
121 SetupMachineFunction(MF);
122 const Function &F = MF.getFunction();
123 const TargetMachine& TM = MF.getTarget();
125 // Collect all globals that had their storage promoted to a constant pool.
126 // Functions are emitted before variables, so this accumulates promoted
127 // globals from all functions in PromotedGlobals.
128 for (auto *GV : AFI->getGlobalsPromotedToConstantPool())
129 PromotedGlobals.insert(GV);
131 // Calculate this function's optimization goal.
132 unsigned OptimizationGoal;
133 if (F.hasOptNone())
134 // For best debugging illusion, speed and small size sacrificed
135 OptimizationGoal = 6;
136 else if (F.hasMinSize())
137 // Aggressively for small size, speed and debug illusion sacrificed
138 OptimizationGoal = 4;
139 else if (F.hasOptSize())
140 // For small size, but speed and debugging illusion preserved
141 OptimizationGoal = 3;
142 else if (TM.getOptLevel() == CodeGenOpt::Aggressive)
143 // Aggressively for speed, small size and debug illusion sacrificed
144 OptimizationGoal = 2;
145 else if (TM.getOptLevel() > CodeGenOpt::None)
146 // For speed, but small size and good debug illusion preserved
147 OptimizationGoal = 1;
148 else // TM.getOptLevel() == CodeGenOpt::None
149 // For good debugging, but speed and small size preserved
150 OptimizationGoal = 5;
152 // Combine a new optimization goal with existing ones.
153 if (OptimizationGoals == -1) // uninitialized goals
154 OptimizationGoals = OptimizationGoal;
155 else if (OptimizationGoals != (int)OptimizationGoal) // conflicting goals
156 OptimizationGoals = 0;
158 if (Subtarget->isTargetCOFF()) {
159 bool Internal = F.hasInternalLinkage();
160 COFF::SymbolStorageClass Scl = Internal ? COFF::IMAGE_SYM_CLASS_STATIC
161 : COFF::IMAGE_SYM_CLASS_EXTERNAL;
162 int Type = COFF::IMAGE_SYM_DTYPE_FUNCTION << COFF::SCT_COMPLEX_TYPE_SHIFT;
164 OutStreamer->BeginCOFFSymbolDef(CurrentFnSym);
165 OutStreamer->EmitCOFFSymbolStorageClass(Scl);
166 OutStreamer->EmitCOFFSymbolType(Type);
167 OutStreamer->EndCOFFSymbolDef();
170 // Emit the rest of the function body.
171 emitFunctionBody();
173 // Emit the XRay table for this function.
174 emitXRayTable();
176 // If we need V4T thumb mode Register Indirect Jump pads, emit them.
177 // These are created per function, rather than per TU, since it's
178 // relatively easy to exceed the thumb branch range within a TU.
179 if (! ThumbIndirectPads.empty()) {
180 OutStreamer->emitAssemblerFlag(MCAF_Code16);
181 emitAlignment(Align(2));
182 for (std::pair<unsigned, MCSymbol *> &TIP : ThumbIndirectPads) {
183 OutStreamer->emitLabel(TIP.second);
184 EmitToStreamer(*OutStreamer, MCInstBuilder(ARM::tBX)
185 .addReg(TIP.first)
186 // Add predicate operands.
187 .addImm(ARMCC::AL)
188 .addReg(0));
190 ThumbIndirectPads.clear();
193 // We didn't modify anything.
194 return false;
197 void ARMAsmPrinter::PrintSymbolOperand(const MachineOperand &MO,
198 raw_ostream &O) {
199 assert(MO.isGlobal() && "caller should check MO.isGlobal");
200 unsigned TF = MO.getTargetFlags();
201 if (TF & ARMII::MO_LO16)
202 O << ":lower16:";
203 else if (TF & ARMII::MO_HI16)
204 O << ":upper16:";
205 GetARMGVSymbol(MO.getGlobal(), TF)->print(O, MAI);
206 printOffset(MO.getOffset(), O);
209 void ARMAsmPrinter::printOperand(const MachineInstr *MI, int OpNum,
210 raw_ostream &O) {
211 const MachineOperand &MO = MI->getOperand(OpNum);
213 switch (MO.getType()) {
214 default: llvm_unreachable("<unknown operand type>");
215 case MachineOperand::MO_Register: {
216 Register Reg = MO.getReg();
217 assert(Register::isPhysicalRegister(Reg));
218 assert(!MO.getSubReg() && "Subregs should be eliminated!");
219 if(ARM::GPRPairRegClass.contains(Reg)) {
220 const MachineFunction &MF = *MI->getParent()->getParent();
221 const TargetRegisterInfo *TRI = MF.getSubtarget().getRegisterInfo();
222 Reg = TRI->getSubReg(Reg, ARM::gsub_0);
224 O << ARMInstPrinter::getRegisterName(Reg);
225 break;
227 case MachineOperand::MO_Immediate: {
228 O << '#';
229 unsigned TF = MO.getTargetFlags();
230 if (TF == ARMII::MO_LO16)
231 O << ":lower16:";
232 else if (TF == ARMII::MO_HI16)
233 O << ":upper16:";
234 O << MO.getImm();
235 break;
237 case MachineOperand::MO_MachineBasicBlock:
238 MO.getMBB()->getSymbol()->print(O, MAI);
239 return;
240 case MachineOperand::MO_GlobalAddress: {
241 PrintSymbolOperand(MO, O);
242 break;
244 case MachineOperand::MO_ConstantPoolIndex:
245 if (Subtarget->genExecuteOnly())
246 llvm_unreachable("execute-only should not generate constant pools");
247 GetCPISymbol(MO.getIndex())->print(O, MAI);
248 break;
252 MCSymbol *ARMAsmPrinter::GetCPISymbol(unsigned CPID) const {
253 // The AsmPrinter::GetCPISymbol superclass method tries to use CPID as
254 // indexes in MachineConstantPool, which isn't in sync with indexes used here.
255 const DataLayout &DL = getDataLayout();
256 return OutContext.getOrCreateSymbol(Twine(DL.getPrivateGlobalPrefix()) +
257 "CPI" + Twine(getFunctionNumber()) + "_" +
258 Twine(CPID));
261 //===--------------------------------------------------------------------===//
263 MCSymbol *ARMAsmPrinter::
264 GetARMJTIPICJumpTableLabel(unsigned uid) const {
265 const DataLayout &DL = getDataLayout();
266 SmallString<60> Name;
267 raw_svector_ostream(Name) << DL.getPrivateGlobalPrefix() << "JTI"
268 << getFunctionNumber() << '_' << uid;
269 return OutContext.getOrCreateSymbol(Name);
272 bool ARMAsmPrinter::PrintAsmOperand(const MachineInstr *MI, unsigned OpNum,
273 const char *ExtraCode, raw_ostream &O) {
274 // Does this asm operand have a single letter operand modifier?
275 if (ExtraCode && ExtraCode[0]) {
276 if (ExtraCode[1] != 0) return true; // Unknown modifier.
278 switch (ExtraCode[0]) {
279 default:
280 // See if this is a generic print operand
281 return AsmPrinter::PrintAsmOperand(MI, OpNum, ExtraCode, O);
282 case 'P': // Print a VFP double precision register.
283 case 'q': // Print a NEON quad precision register.
284 printOperand(MI, OpNum, O);
285 return false;
286 case 'y': // Print a VFP single precision register as indexed double.
287 if (MI->getOperand(OpNum).isReg()) {
288 MCRegister Reg = MI->getOperand(OpNum).getReg().asMCReg();
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))
294 continue;
295 bool Lane0 = TRI->getSubReg(*SR, ARM::ssub_0) == Reg;
296 O << ARMInstPrinter::getRegisterName(*SR) << (Lane0 ? "[0]" : "[1]");
297 return false;
300 return true;
301 case 'B': // Bitwise inverse of integer or symbol without a preceding #.
302 if (!MI->getOperand(OpNum).isImm())
303 return true;
304 O << ~(MI->getOperand(OpNum).getImm());
305 return false;
306 case 'L': // The low 16 bits of an immediate constant.
307 if (!MI->getOperand(OpNum).isImm())
308 return true;
309 O << (MI->getOperand(OpNum).getImm() & 0xffff);
310 return false;
311 case 'M': { // A register range suitable for LDM/STM.
312 if (!MI->getOperand(OpNum).isReg())
313 return true;
314 const MachineOperand &MO = MI->getOperand(OpNum);
315 Register 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.
319 O << "{";
320 if (ARM::GPRPairRegClass.contains(RegBegin)) {
321 const TargetRegisterInfo *TRI = MF->getSubtarget().getRegisterInfo();
322 Register 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()) {
334 O << ", "
335 << ARMInstPrinter::getRegisterName(MI->getOperand(RegOps).getReg());
336 RegOps++;
339 O << "}";
341 return false;
343 case 'R': // The most significant register of a pair.
344 case 'Q': { // The least significant register of a pair.
345 if (OpNum == 0)
346 return true;
347 const MachineOperand &FlagsOP = MI->getOperand(OpNum - 1);
348 if (!FlagsOP.isImm())
349 return true;
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.
355 unsigned TiedIdx;
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
364 // the flags.
365 OpNum += 1;
368 unsigned NumVals = InlineAsm::getNumOperandRegisters(Flags);
369 unsigned RC;
370 bool FirstHalf;
371 const ARMBaseTargetMachine &ATM =
372 static_cast<const ARMBaseTargetMachine &>(TM);
374 // 'Q' should correspond to the low order register and 'R' to the high
375 // order register. Whether this corresponds to the upper or lower half
376 // depends on the endianess mode.
377 if (ExtraCode[0] == 'Q')
378 FirstHalf = ATM.isLittleEndian();
379 else
380 // ExtraCode[0] == 'R'.
381 FirstHalf = !ATM.isLittleEndian();
382 const TargetRegisterInfo *TRI = MF->getSubtarget().getRegisterInfo();
383 if (InlineAsm::hasRegClassConstraint(Flags, RC) &&
384 ARM::GPRPairRegClass.hasSubClassEq(TRI->getRegClass(RC))) {
385 if (NumVals != 1)
386 return true;
387 const MachineOperand &MO = MI->getOperand(OpNum);
388 if (!MO.isReg())
389 return true;
390 const TargetRegisterInfo *TRI = MF->getSubtarget().getRegisterInfo();
391 Register Reg =
392 TRI->getSubReg(MO.getReg(), FirstHalf ? ARM::gsub_0 : ARM::gsub_1);
393 O << ARMInstPrinter::getRegisterName(Reg);
394 return false;
396 if (NumVals != 2)
397 return true;
398 unsigned RegOp = FirstHalf ? OpNum : OpNum + 1;
399 if (RegOp >= MI->getNumOperands())
400 return true;
401 const MachineOperand &MO = MI->getOperand(RegOp);
402 if (!MO.isReg())
403 return true;
404 Register Reg = MO.getReg();
405 O << ARMInstPrinter::getRegisterName(Reg);
406 return false;
409 case 'e': // The low doubleword register of a NEON quad register.
410 case 'f': { // The high doubleword register of a NEON quad register.
411 if (!MI->getOperand(OpNum).isReg())
412 return true;
413 Register Reg = MI->getOperand(OpNum).getReg();
414 if (!ARM::QPRRegClass.contains(Reg))
415 return true;
416 const TargetRegisterInfo *TRI = MF->getSubtarget().getRegisterInfo();
417 Register SubReg =
418 TRI->getSubReg(Reg, ExtraCode[0] == 'e' ? ARM::dsub_0 : ARM::dsub_1);
419 O << ARMInstPrinter::getRegisterName(SubReg);
420 return false;
423 // This modifier is not yet supported.
424 case 'h': // A range of VFP/NEON registers suitable for VLD1/VST1.
425 return true;
426 case 'H': { // The highest-numbered register of a pair.
427 const MachineOperand &MO = MI->getOperand(OpNum);
428 if (!MO.isReg())
429 return true;
430 const MachineFunction &MF = *MI->getParent()->getParent();
431 const TargetRegisterInfo *TRI = MF.getSubtarget().getRegisterInfo();
432 Register Reg = MO.getReg();
433 if(!ARM::GPRPairRegClass.contains(Reg))
434 return false;
435 Reg = TRI->getSubReg(Reg, ARM::gsub_1);
436 O << ARMInstPrinter::getRegisterName(Reg);
437 return false;
442 printOperand(MI, OpNum, O);
443 return false;
446 bool ARMAsmPrinter::PrintAsmMemoryOperand(const MachineInstr *MI,
447 unsigned OpNum, const char *ExtraCode,
448 raw_ostream &O) {
449 // Does this asm operand have a single letter operand modifier?
450 if (ExtraCode && ExtraCode[0]) {
451 if (ExtraCode[1] != 0) return true; // Unknown modifier.
453 switch (ExtraCode[0]) {
454 case 'A': // A memory operand for a VLD1/VST1 instruction.
455 default: return true; // Unknown modifier.
456 case 'm': // The base register of a memory operand.
457 if (!MI->getOperand(OpNum).isReg())
458 return true;
459 O << ARMInstPrinter::getRegisterName(MI->getOperand(OpNum).getReg());
460 return false;
464 const MachineOperand &MO = MI->getOperand(OpNum);
465 assert(MO.isReg() && "unexpected inline asm memory operand");
466 O << "[" << ARMInstPrinter::getRegisterName(MO.getReg()) << "]";
467 return false;
470 static bool isThumb(const MCSubtargetInfo& STI) {
471 return STI.getFeatureBits()[ARM::ModeThumb];
474 void ARMAsmPrinter::emitInlineAsmEnd(const MCSubtargetInfo &StartInfo,
475 const MCSubtargetInfo *EndInfo) const {
476 // If either end mode is unknown (EndInfo == NULL) or different than
477 // the start mode, then restore the start mode.
478 const bool WasThumb = isThumb(StartInfo);
479 if (!EndInfo || WasThumb != isThumb(*EndInfo)) {
480 OutStreamer->emitAssemblerFlag(WasThumb ? MCAF_Code16 : MCAF_Code32);
484 void ARMAsmPrinter::emitStartOfAsmFile(Module &M) {
485 const Triple &TT = TM.getTargetTriple();
486 // Use unified assembler syntax.
487 OutStreamer->emitAssemblerFlag(MCAF_SyntaxUnified);
489 // Emit ARM Build Attributes
490 if (TT.isOSBinFormatELF())
491 emitAttributes();
493 // Use the triple's architecture and subarchitecture to determine
494 // if we're thumb for the purposes of the top level code16 assembler
495 // flag.
496 if (!M.getModuleInlineAsm().empty() && TT.isThumb())
497 OutStreamer->emitAssemblerFlag(MCAF_Code16);
500 static void
501 emitNonLazySymbolPointer(MCStreamer &OutStreamer, MCSymbol *StubLabel,
502 MachineModuleInfoImpl::StubValueTy &MCSym) {
503 // L_foo$stub:
504 OutStreamer.emitLabel(StubLabel);
505 // .indirect_symbol _foo
506 OutStreamer.emitSymbolAttribute(MCSym.getPointer(), MCSA_IndirectSymbol);
508 if (MCSym.getInt())
509 // External to current translation unit.
510 OutStreamer.emitIntValue(0, 4/*size*/);
511 else
512 // Internal to current translation unit.
514 // When we place the LSDA into the TEXT section, the type info
515 // pointers need to be indirect and pc-rel. We accomplish this by
516 // using NLPs; however, sometimes the types are local to the file.
517 // We need to fill in the value for the NLP in those cases.
518 OutStreamer.emitValue(
519 MCSymbolRefExpr::create(MCSym.getPointer(), OutStreamer.getContext()),
520 4 /*size*/);
524 void ARMAsmPrinter::emitEndOfAsmFile(Module &M) {
525 const Triple &TT = TM.getTargetTriple();
526 if (TT.isOSBinFormatMachO()) {
527 // All darwin targets use mach-o.
528 const TargetLoweringObjectFileMachO &TLOFMacho =
529 static_cast<const TargetLoweringObjectFileMachO &>(getObjFileLowering());
530 MachineModuleInfoMachO &MMIMacho =
531 MMI->getObjFileInfo<MachineModuleInfoMachO>();
533 // Output non-lazy-pointers for external and common global variables.
534 MachineModuleInfoMachO::SymbolListTy Stubs = MMIMacho.GetGVStubList();
536 if (!Stubs.empty()) {
537 // Switch with ".non_lazy_symbol_pointer" directive.
538 OutStreamer->SwitchSection(TLOFMacho.getNonLazySymbolPointerSection());
539 emitAlignment(Align(4));
541 for (auto &Stub : Stubs)
542 emitNonLazySymbolPointer(*OutStreamer, Stub.first, Stub.second);
544 Stubs.clear();
545 OutStreamer->AddBlankLine();
548 Stubs = MMIMacho.GetThreadLocalGVStubList();
549 if (!Stubs.empty()) {
550 // Switch with ".non_lazy_symbol_pointer" directive.
551 OutStreamer->SwitchSection(TLOFMacho.getThreadLocalPointerSection());
552 emitAlignment(Align(4));
554 for (auto &Stub : Stubs)
555 emitNonLazySymbolPointer(*OutStreamer, Stub.first, Stub.second);
557 Stubs.clear();
558 OutStreamer->AddBlankLine();
561 // Funny Darwin hack: This flag tells the linker that no global symbols
562 // contain code that falls through to other global symbols (e.g. the obvious
563 // implementation of multiple entry points). If this doesn't occur, the
564 // linker can safely perform dead code stripping. Since LLVM never
565 // generates code that does this, it is always safe to set.
566 OutStreamer->emitAssemblerFlag(MCAF_SubsectionsViaSymbols);
569 // The last attribute to be emitted is ABI_optimization_goals
570 MCTargetStreamer &TS = *OutStreamer->getTargetStreamer();
571 ARMTargetStreamer &ATS = static_cast<ARMTargetStreamer &>(TS);
573 if (OptimizationGoals > 0 &&
574 (Subtarget->isTargetAEABI() || Subtarget->isTargetGNUAEABI() ||
575 Subtarget->isTargetMuslAEABI()))
576 ATS.emitAttribute(ARMBuildAttrs::ABI_optimization_goals, OptimizationGoals);
577 OptimizationGoals = -1;
579 ATS.finishAttributeSection();
582 //===----------------------------------------------------------------------===//
583 // Helper routines for emitStartOfAsmFile() and emitEndOfAsmFile()
584 // FIXME:
585 // The following seem like one-off assembler flags, but they actually need
586 // to appear in the .ARM.attributes section in ELF.
587 // Instead of subclassing the MCELFStreamer, we do the work here.
589 // Returns true if all functions have the same function attribute value.
590 // It also returns true when the module has no functions.
591 static bool checkFunctionsAttributeConsistency(const Module &M, StringRef Attr,
592 StringRef Value) {
593 return !any_of(M, [&](const Function &F) {
594 return F.getFnAttribute(Attr).getValueAsString() != Value;
597 // Returns true if all functions have the same denormal mode.
598 // It also returns true when the module has no functions.
599 static bool checkDenormalAttributeConsistency(const Module &M,
600 StringRef Attr,
601 DenormalMode Value) {
602 return !any_of(M, [&](const Function &F) {
603 StringRef AttrVal = F.getFnAttribute(Attr).getValueAsString();
604 return parseDenormalFPAttribute(AttrVal) != Value;
608 void ARMAsmPrinter::emitAttributes() {
609 MCTargetStreamer &TS = *OutStreamer->getTargetStreamer();
610 ARMTargetStreamer &ATS = static_cast<ARMTargetStreamer &>(TS);
612 ATS.emitTextAttribute(ARMBuildAttrs::conformance, "2.09");
614 ATS.switchVendor("aeabi");
616 // Compute ARM ELF Attributes based on the default subtarget that
617 // we'd have constructed. The existing ARM behavior isn't LTO clean
618 // anyhow.
619 // FIXME: For ifunc related functions we could iterate over and look
620 // for a feature string that doesn't match the default one.
621 const Triple &TT = TM.getTargetTriple();
622 StringRef CPU = TM.getTargetCPU();
623 StringRef FS = TM.getTargetFeatureString();
624 std::string ArchFS = ARM_MC::ParseARMTriple(TT, CPU);
625 if (!FS.empty()) {
626 if (!ArchFS.empty())
627 ArchFS = (Twine(ArchFS) + "," + FS).str();
628 else
629 ArchFS = std::string(FS);
631 const ARMBaseTargetMachine &ATM =
632 static_cast<const ARMBaseTargetMachine &>(TM);
633 const ARMSubtarget STI(TT, std::string(CPU), ArchFS, ATM,
634 ATM.isLittleEndian());
636 // Emit build attributes for the available hardware.
637 ATS.emitTargetAttributes(STI);
639 // RW data addressing.
640 if (isPositionIndependent()) {
641 ATS.emitAttribute(ARMBuildAttrs::ABI_PCS_RW_data,
642 ARMBuildAttrs::AddressRWPCRel);
643 } else if (STI.isRWPI()) {
644 // RWPI specific attributes.
645 ATS.emitAttribute(ARMBuildAttrs::ABI_PCS_RW_data,
646 ARMBuildAttrs::AddressRWSBRel);
649 // RO data addressing.
650 if (isPositionIndependent() || STI.isROPI()) {
651 ATS.emitAttribute(ARMBuildAttrs::ABI_PCS_RO_data,
652 ARMBuildAttrs::AddressROPCRel);
655 // GOT use.
656 if (isPositionIndependent()) {
657 ATS.emitAttribute(ARMBuildAttrs::ABI_PCS_GOT_use,
658 ARMBuildAttrs::AddressGOT);
659 } else {
660 ATS.emitAttribute(ARMBuildAttrs::ABI_PCS_GOT_use,
661 ARMBuildAttrs::AddressDirect);
664 // Set FP Denormals.
665 if (checkDenormalAttributeConsistency(*MMI->getModule(), "denormal-fp-math",
666 DenormalMode::getPreserveSign()))
667 ATS.emitAttribute(ARMBuildAttrs::ABI_FP_denormal,
668 ARMBuildAttrs::PreserveFPSign);
669 else if (checkDenormalAttributeConsistency(*MMI->getModule(),
670 "denormal-fp-math",
671 DenormalMode::getPositiveZero()))
672 ATS.emitAttribute(ARMBuildAttrs::ABI_FP_denormal,
673 ARMBuildAttrs::PositiveZero);
674 else if (!TM.Options.UnsafeFPMath)
675 ATS.emitAttribute(ARMBuildAttrs::ABI_FP_denormal,
676 ARMBuildAttrs::IEEEDenormals);
677 else {
678 if (!STI.hasVFP2Base()) {
679 // When the target doesn't have an FPU (by design or
680 // intention), the assumptions made on the software support
681 // mirror that of the equivalent hardware support *if it
682 // existed*. For v7 and better we indicate that denormals are
683 // flushed preserving sign, and for V6 we indicate that
684 // denormals are flushed to positive zero.
685 if (STI.hasV7Ops())
686 ATS.emitAttribute(ARMBuildAttrs::ABI_FP_denormal,
687 ARMBuildAttrs::PreserveFPSign);
688 } else if (STI.hasVFP3Base()) {
689 // In VFPv4, VFPv4U, VFPv3, or VFPv3U, it is preserved. That is,
690 // the sign bit of the zero matches the sign bit of the input or
691 // result that is being flushed to zero.
692 ATS.emitAttribute(ARMBuildAttrs::ABI_FP_denormal,
693 ARMBuildAttrs::PreserveFPSign);
695 // For VFPv2 implementations it is implementation defined as
696 // to whether denormals are flushed to positive zero or to
697 // whatever the sign of zero is (ARM v7AR ARM 2.7.5). Historically
698 // LLVM has chosen to flush this to positive zero (most likely for
699 // GCC compatibility), so that's the chosen value here (the
700 // absence of its emission implies zero).
703 // Set FP exceptions and rounding
704 if (checkFunctionsAttributeConsistency(*MMI->getModule(),
705 "no-trapping-math", "true") ||
706 TM.Options.NoTrappingFPMath)
707 ATS.emitAttribute(ARMBuildAttrs::ABI_FP_exceptions,
708 ARMBuildAttrs::Not_Allowed);
709 else if (!TM.Options.UnsafeFPMath) {
710 ATS.emitAttribute(ARMBuildAttrs::ABI_FP_exceptions, ARMBuildAttrs::Allowed);
712 // If the user has permitted this code to choose the IEEE 754
713 // rounding at run-time, emit the rounding attribute.
714 if (TM.Options.HonorSignDependentRoundingFPMathOption)
715 ATS.emitAttribute(ARMBuildAttrs::ABI_FP_rounding, ARMBuildAttrs::Allowed);
718 // TM.Options.NoInfsFPMath && TM.Options.NoNaNsFPMath is the
719 // equivalent of GCC's -ffinite-math-only flag.
720 if (TM.Options.NoInfsFPMath && TM.Options.NoNaNsFPMath)
721 ATS.emitAttribute(ARMBuildAttrs::ABI_FP_number_model,
722 ARMBuildAttrs::Allowed);
723 else
724 ATS.emitAttribute(ARMBuildAttrs::ABI_FP_number_model,
725 ARMBuildAttrs::AllowIEEE754);
727 // FIXME: add more flags to ARMBuildAttributes.h
728 // 8-bytes alignment stuff.
729 ATS.emitAttribute(ARMBuildAttrs::ABI_align_needed, 1);
730 ATS.emitAttribute(ARMBuildAttrs::ABI_align_preserved, 1);
732 // Hard float. Use both S and D registers and conform to AAPCS-VFP.
733 if (STI.isAAPCS_ABI() && TM.Options.FloatABIType == FloatABI::Hard)
734 ATS.emitAttribute(ARMBuildAttrs::ABI_VFP_args, ARMBuildAttrs::HardFPAAPCS);
736 // FIXME: To support emitting this build attribute as GCC does, the
737 // -mfp16-format option and associated plumbing must be
738 // supported. For now the __fp16 type is exposed by default, so this
739 // attribute should be emitted with value 1.
740 ATS.emitAttribute(ARMBuildAttrs::ABI_FP_16bit_format,
741 ARMBuildAttrs::FP16FormatIEEE);
743 if (MMI) {
744 if (const Module *SourceModule = MMI->getModule()) {
745 // ABI_PCS_wchar_t to indicate wchar_t width
746 // FIXME: There is no way to emit value 0 (wchar_t prohibited).
747 if (auto WCharWidthValue = mdconst::extract_or_null<ConstantInt>(
748 SourceModule->getModuleFlag("wchar_size"))) {
749 int WCharWidth = WCharWidthValue->getZExtValue();
750 assert((WCharWidth == 2 || WCharWidth == 4) &&
751 "wchar_t width must be 2 or 4 bytes");
752 ATS.emitAttribute(ARMBuildAttrs::ABI_PCS_wchar_t, WCharWidth);
755 // ABI_enum_size to indicate enum width
756 // FIXME: There is no way to emit value 0 (enums prohibited) or value 3
757 // (all enums contain a value needing 32 bits to encode).
758 if (auto EnumWidthValue = mdconst::extract_or_null<ConstantInt>(
759 SourceModule->getModuleFlag("min_enum_size"))) {
760 int EnumWidth = EnumWidthValue->getZExtValue();
761 assert((EnumWidth == 1 || EnumWidth == 4) &&
762 "Minimum enum width must be 1 or 4 bytes");
763 int EnumBuildAttr = EnumWidth == 1 ? 1 : 2;
764 ATS.emitAttribute(ARMBuildAttrs::ABI_enum_size, EnumBuildAttr);
769 // We currently do not support using R9 as the TLS pointer.
770 if (STI.isRWPI())
771 ATS.emitAttribute(ARMBuildAttrs::ABI_PCS_R9_use,
772 ARMBuildAttrs::R9IsSB);
773 else if (STI.isR9Reserved())
774 ATS.emitAttribute(ARMBuildAttrs::ABI_PCS_R9_use,
775 ARMBuildAttrs::R9Reserved);
776 else
777 ATS.emitAttribute(ARMBuildAttrs::ABI_PCS_R9_use,
778 ARMBuildAttrs::R9IsGPR);
781 //===----------------------------------------------------------------------===//
783 static MCSymbol *getBFLabel(StringRef Prefix, unsigned FunctionNumber,
784 unsigned LabelId, MCContext &Ctx) {
786 MCSymbol *Label = Ctx.getOrCreateSymbol(Twine(Prefix)
787 + "BF" + Twine(FunctionNumber) + "_" + Twine(LabelId));
788 return Label;
791 static MCSymbol *getPICLabel(StringRef Prefix, unsigned FunctionNumber,
792 unsigned LabelId, MCContext &Ctx) {
794 MCSymbol *Label = Ctx.getOrCreateSymbol(Twine(Prefix)
795 + "PC" + Twine(FunctionNumber) + "_" + Twine(LabelId));
796 return Label;
799 static MCSymbolRefExpr::VariantKind
800 getModifierVariantKind(ARMCP::ARMCPModifier Modifier) {
801 switch (Modifier) {
802 case ARMCP::no_modifier:
803 return MCSymbolRefExpr::VK_None;
804 case ARMCP::TLSGD:
805 return MCSymbolRefExpr::VK_TLSGD;
806 case ARMCP::TPOFF:
807 return MCSymbolRefExpr::VK_TPOFF;
808 case ARMCP::GOTTPOFF:
809 return MCSymbolRefExpr::VK_GOTTPOFF;
810 case ARMCP::SBREL:
811 return MCSymbolRefExpr::VK_ARM_SBREL;
812 case ARMCP::GOT_PREL:
813 return MCSymbolRefExpr::VK_ARM_GOT_PREL;
814 case ARMCP::SECREL:
815 return MCSymbolRefExpr::VK_SECREL;
817 llvm_unreachable("Invalid ARMCPModifier!");
820 MCSymbol *ARMAsmPrinter::GetARMGVSymbol(const GlobalValue *GV,
821 unsigned char TargetFlags) {
822 if (Subtarget->isTargetMachO()) {
823 bool IsIndirect =
824 (TargetFlags & ARMII::MO_NONLAZY) && Subtarget->isGVIndirectSymbol(GV);
826 if (!IsIndirect)
827 return getSymbol(GV);
829 // FIXME: Remove this when Darwin transition to @GOT like syntax.
830 MCSymbol *MCSym = getSymbolWithGlobalValueBase(GV, "$non_lazy_ptr");
831 MachineModuleInfoMachO &MMIMachO =
832 MMI->getObjFileInfo<MachineModuleInfoMachO>();
833 MachineModuleInfoImpl::StubValueTy &StubSym =
834 GV->isThreadLocal() ? MMIMachO.getThreadLocalGVStubEntry(MCSym)
835 : MMIMachO.getGVStubEntry(MCSym);
837 if (!StubSym.getPointer())
838 StubSym = MachineModuleInfoImpl::StubValueTy(getSymbol(GV),
839 !GV->hasInternalLinkage());
840 return MCSym;
841 } else if (Subtarget->isTargetCOFF()) {
842 assert(Subtarget->isTargetWindows() &&
843 "Windows is the only supported COFF target");
845 bool IsIndirect =
846 (TargetFlags & (ARMII::MO_DLLIMPORT | ARMII::MO_COFFSTUB));
847 if (!IsIndirect)
848 return getSymbol(GV);
850 SmallString<128> Name;
851 if (TargetFlags & ARMII::MO_DLLIMPORT)
852 Name = "__imp_";
853 else if (TargetFlags & ARMII::MO_COFFSTUB)
854 Name = ".refptr.";
855 getNameWithPrefix(Name, GV);
857 MCSymbol *MCSym = OutContext.getOrCreateSymbol(Name);
859 if (TargetFlags & ARMII::MO_COFFSTUB) {
860 MachineModuleInfoCOFF &MMICOFF =
861 MMI->getObjFileInfo<MachineModuleInfoCOFF>();
862 MachineModuleInfoImpl::StubValueTy &StubSym =
863 MMICOFF.getGVStubEntry(MCSym);
865 if (!StubSym.getPointer())
866 StubSym = MachineModuleInfoImpl::StubValueTy(getSymbol(GV), true);
869 return MCSym;
870 } else if (Subtarget->isTargetELF()) {
871 return getSymbol(GV);
873 llvm_unreachable("unexpected target");
876 void ARMAsmPrinter::emitMachineConstantPoolValue(
877 MachineConstantPoolValue *MCPV) {
878 const DataLayout &DL = getDataLayout();
879 int Size = DL.getTypeAllocSize(MCPV->getType());
881 ARMConstantPoolValue *ACPV = static_cast<ARMConstantPoolValue*>(MCPV);
883 if (ACPV->isPromotedGlobal()) {
884 // This constant pool entry is actually a global whose storage has been
885 // promoted into the constant pool. This global may be referenced still
886 // by debug information, and due to the way AsmPrinter is set up, the debug
887 // info is immutable by the time we decide to promote globals to constant
888 // pools. Because of this, we need to ensure we emit a symbol for the global
889 // with private linkage (the default) so debug info can refer to it.
891 // However, if this global is promoted into several functions we must ensure
892 // we don't try and emit duplicate symbols!
893 auto *ACPC = cast<ARMConstantPoolConstant>(ACPV);
894 for (const auto *GV : ACPC->promotedGlobals()) {
895 if (!EmittedPromotedGlobalLabels.count(GV)) {
896 MCSymbol *GVSym = getSymbol(GV);
897 OutStreamer->emitLabel(GVSym);
898 EmittedPromotedGlobalLabels.insert(GV);
901 return emitGlobalConstant(DL, ACPC->getPromotedGlobalInit());
904 MCSymbol *MCSym;
905 if (ACPV->isLSDA()) {
906 MCSym = getMBBExceptionSym(MF->front());
907 } else if (ACPV->isBlockAddress()) {
908 const BlockAddress *BA =
909 cast<ARMConstantPoolConstant>(ACPV)->getBlockAddress();
910 MCSym = GetBlockAddressSymbol(BA);
911 } else if (ACPV->isGlobalValue()) {
912 const GlobalValue *GV = cast<ARMConstantPoolConstant>(ACPV)->getGV();
914 // On Darwin, const-pool entries may get the "FOO$non_lazy_ptr" mangling, so
915 // flag the global as MO_NONLAZY.
916 unsigned char TF = Subtarget->isTargetMachO() ? ARMII::MO_NONLAZY : 0;
917 MCSym = GetARMGVSymbol(GV, TF);
918 } else if (ACPV->isMachineBasicBlock()) {
919 const MachineBasicBlock *MBB = cast<ARMConstantPoolMBB>(ACPV)->getMBB();
920 MCSym = MBB->getSymbol();
921 } else {
922 assert(ACPV->isExtSymbol() && "unrecognized constant pool value");
923 auto Sym = cast<ARMConstantPoolSymbol>(ACPV)->getSymbol();
924 MCSym = GetExternalSymbolSymbol(Sym);
927 // Create an MCSymbol for the reference.
928 const MCExpr *Expr =
929 MCSymbolRefExpr::create(MCSym, getModifierVariantKind(ACPV->getModifier()),
930 OutContext);
932 if (ACPV->getPCAdjustment()) {
933 MCSymbol *PCLabel =
934 getPICLabel(DL.getPrivateGlobalPrefix(), getFunctionNumber(),
935 ACPV->getLabelId(), OutContext);
936 const MCExpr *PCRelExpr = MCSymbolRefExpr::create(PCLabel, OutContext);
937 PCRelExpr =
938 MCBinaryExpr::createAdd(PCRelExpr,
939 MCConstantExpr::create(ACPV->getPCAdjustment(),
940 OutContext),
941 OutContext);
942 if (ACPV->mustAddCurrentAddress()) {
943 // We want "(<expr> - .)", but MC doesn't have a concept of the '.'
944 // label, so just emit a local label end reference that instead.
945 MCSymbol *DotSym = OutContext.createTempSymbol();
946 OutStreamer->emitLabel(DotSym);
947 const MCExpr *DotExpr = MCSymbolRefExpr::create(DotSym, OutContext);
948 PCRelExpr = MCBinaryExpr::createSub(PCRelExpr, DotExpr, OutContext);
950 Expr = MCBinaryExpr::createSub(Expr, PCRelExpr, OutContext);
952 OutStreamer->emitValue(Expr, Size);
955 void ARMAsmPrinter::emitJumpTableAddrs(const MachineInstr *MI) {
956 const MachineOperand &MO1 = MI->getOperand(1);
957 unsigned JTI = MO1.getIndex();
959 // Make sure the Thumb jump table is 4-byte aligned. This will be a nop for
960 // ARM mode tables.
961 emitAlignment(Align(4));
963 // Emit a label for the jump table.
964 MCSymbol *JTISymbol = GetARMJTIPICJumpTableLabel(JTI);
965 OutStreamer->emitLabel(JTISymbol);
967 // Mark the jump table as data-in-code.
968 OutStreamer->emitDataRegion(MCDR_DataRegionJT32);
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 // Construct an MCExpr for the entry. We want a value of the form:
977 // (BasicBlockAddr - TableBeginAddr)
979 // For example, a table with entries jumping to basic blocks BB0 and BB1
980 // would look like:
981 // LJTI_0_0:
982 // .word (LBB0 - LJTI_0_0)
983 // .word (LBB1 - LJTI_0_0)
984 const MCExpr *Expr = MCSymbolRefExpr::create(MBB->getSymbol(), OutContext);
986 if (isPositionIndependent() || Subtarget->isROPI())
987 Expr = MCBinaryExpr::createSub(Expr, MCSymbolRefExpr::create(JTISymbol,
988 OutContext),
989 OutContext);
990 // If we're generating a table of Thumb addresses in static relocation
991 // model, we need to add one to keep interworking correctly.
992 else if (AFI->isThumbFunction())
993 Expr = MCBinaryExpr::createAdd(Expr, MCConstantExpr::create(1,OutContext),
994 OutContext);
995 OutStreamer->emitValue(Expr, 4);
997 // Mark the end of jump table data-in-code region.
998 OutStreamer->emitDataRegion(MCDR_DataRegionEnd);
1001 void ARMAsmPrinter::emitJumpTableInsts(const MachineInstr *MI) {
1002 const MachineOperand &MO1 = MI->getOperand(1);
1003 unsigned JTI = MO1.getIndex();
1005 // Make sure the Thumb jump table is 4-byte aligned. This will be a nop for
1006 // ARM mode tables.
1007 emitAlignment(Align(4));
1009 // Emit a label for the jump table.
1010 MCSymbol *JTISymbol = GetARMJTIPICJumpTableLabel(JTI);
1011 OutStreamer->emitLabel(JTISymbol);
1013 // Emit each entry of the table.
1014 const MachineJumpTableInfo *MJTI = MF->getJumpTableInfo();
1015 const std::vector<MachineJumpTableEntry> &JT = MJTI->getJumpTables();
1016 const std::vector<MachineBasicBlock*> &JTBBs = JT[JTI].MBBs;
1018 for (MachineBasicBlock *MBB : JTBBs) {
1019 const MCExpr *MBBSymbolExpr = MCSymbolRefExpr::create(MBB->getSymbol(),
1020 OutContext);
1021 // If this isn't a TBB or TBH, the entries are direct branch instructions.
1022 EmitToStreamer(*OutStreamer, MCInstBuilder(ARM::t2B)
1023 .addExpr(MBBSymbolExpr)
1024 .addImm(ARMCC::AL)
1025 .addReg(0));
1029 void ARMAsmPrinter::emitJumpTableTBInst(const MachineInstr *MI,
1030 unsigned OffsetWidth) {
1031 assert((OffsetWidth == 1 || OffsetWidth == 2) && "invalid tbb/tbh width");
1032 const MachineOperand &MO1 = MI->getOperand(1);
1033 unsigned JTI = MO1.getIndex();
1035 if (Subtarget->isThumb1Only())
1036 emitAlignment(Align(4));
1038 MCSymbol *JTISymbol = GetARMJTIPICJumpTableLabel(JTI);
1039 OutStreamer->emitLabel(JTISymbol);
1041 // Emit each entry of the table.
1042 const MachineJumpTableInfo *MJTI = MF->getJumpTableInfo();
1043 const std::vector<MachineJumpTableEntry> &JT = MJTI->getJumpTables();
1044 const std::vector<MachineBasicBlock*> &JTBBs = JT[JTI].MBBs;
1046 // Mark the jump table as data-in-code.
1047 OutStreamer->emitDataRegion(OffsetWidth == 1 ? MCDR_DataRegionJT8
1048 : MCDR_DataRegionJT16);
1050 for (auto MBB : JTBBs) {
1051 const MCExpr *MBBSymbolExpr = MCSymbolRefExpr::create(MBB->getSymbol(),
1052 OutContext);
1053 // Otherwise it's an offset from the dispatch instruction. Construct an
1054 // MCExpr for the entry. We want a value of the form:
1055 // (BasicBlockAddr - TBBInstAddr + 4) / 2
1057 // For example, a TBB table with entries jumping to basic blocks BB0 and BB1
1058 // would look like:
1059 // LJTI_0_0:
1060 // .byte (LBB0 - (LCPI0_0 + 4)) / 2
1061 // .byte (LBB1 - (LCPI0_0 + 4)) / 2
1062 // where LCPI0_0 is a label defined just before the TBB instruction using
1063 // this table.
1064 MCSymbol *TBInstPC = GetCPISymbol(MI->getOperand(0).getImm());
1065 const MCExpr *Expr = MCBinaryExpr::createAdd(
1066 MCSymbolRefExpr::create(TBInstPC, OutContext),
1067 MCConstantExpr::create(4, OutContext), OutContext);
1068 Expr = MCBinaryExpr::createSub(MBBSymbolExpr, Expr, OutContext);
1069 Expr = MCBinaryExpr::createDiv(Expr, MCConstantExpr::create(2, OutContext),
1070 OutContext);
1071 OutStreamer->emitValue(Expr, OffsetWidth);
1073 // Mark the end of jump table data-in-code region. 32-bit offsets use
1074 // actual branch instructions here, so we don't mark those as a data-region
1075 // at all.
1076 OutStreamer->emitDataRegion(MCDR_DataRegionEnd);
1078 // Make sure the next instruction is 2-byte aligned.
1079 emitAlignment(Align(2));
1082 void ARMAsmPrinter::EmitUnwindingInstruction(const MachineInstr *MI) {
1083 assert(MI->getFlag(MachineInstr::FrameSetup) &&
1084 "Only instruction which are involved into frame setup code are allowed");
1086 MCTargetStreamer &TS = *OutStreamer->getTargetStreamer();
1087 ARMTargetStreamer &ATS = static_cast<ARMTargetStreamer &>(TS);
1088 const MachineFunction &MF = *MI->getParent()->getParent();
1089 const TargetRegisterInfo *TargetRegInfo =
1090 MF.getSubtarget().getRegisterInfo();
1091 const MachineRegisterInfo &MachineRegInfo = MF.getRegInfo();
1093 Register FramePtr = TargetRegInfo->getFrameRegister(MF);
1094 unsigned Opc = MI->getOpcode();
1095 unsigned SrcReg, DstReg;
1097 switch (Opc) {
1098 case ARM::tPUSH:
1099 // special case: tPUSH does not have src/dst regs.
1100 SrcReg = DstReg = ARM::SP;
1101 break;
1102 case ARM::tLDRpci:
1103 case ARM::t2MOVi16:
1104 case ARM::t2MOVTi16:
1105 // special cases:
1106 // 1) for Thumb1 code we sometimes materialize the constant via constpool
1107 // load.
1108 // 2) for Thumb2 execute only code we materialize the constant via
1109 // immediate constants in 2 separate instructions (MOVW/MOVT).
1110 SrcReg = ~0U;
1111 DstReg = MI->getOperand(0).getReg();
1112 break;
1113 default:
1114 SrcReg = MI->getOperand(1).getReg();
1115 DstReg = MI->getOperand(0).getReg();
1116 break;
1119 // Try to figure out the unwinding opcode out of src / dst regs.
1120 if (MI->mayStore()) {
1121 // Register saves.
1122 assert(DstReg == ARM::SP &&
1123 "Only stack pointer as a destination reg is supported");
1125 SmallVector<unsigned, 4> RegList;
1126 // Skip src & dst reg, and pred ops.
1127 unsigned StartOp = 2 + 2;
1128 // Use all the operands.
1129 unsigned NumOffset = 0;
1130 // Amount of SP adjustment folded into a push.
1131 unsigned Pad = 0;
1133 switch (Opc) {
1134 default:
1135 MI->print(errs());
1136 llvm_unreachable("Unsupported opcode for unwinding information");
1137 case ARM::tPUSH:
1138 // Special case here: no src & dst reg, but two extra imp ops.
1139 StartOp = 2; NumOffset = 2;
1140 LLVM_FALLTHROUGH;
1141 case ARM::STMDB_UPD:
1142 case ARM::t2STMDB_UPD:
1143 case ARM::VSTMDDB_UPD:
1144 assert(SrcReg == ARM::SP &&
1145 "Only stack pointer as a source reg is supported");
1146 for (unsigned i = StartOp, NumOps = MI->getNumOperands() - NumOffset;
1147 i != NumOps; ++i) {
1148 const MachineOperand &MO = MI->getOperand(i);
1149 // Actually, there should never be any impdef stuff here. Skip it
1150 // temporary to workaround PR11902.
1151 if (MO.isImplicit())
1152 continue;
1153 // Registers, pushed as a part of folding an SP update into the
1154 // push instruction are marked as undef and should not be
1155 // restored when unwinding, because the function can modify the
1156 // corresponding stack slots.
1157 if (MO.isUndef()) {
1158 assert(RegList.empty() &&
1159 "Pad registers must come before restored ones");
1160 unsigned Width =
1161 TargetRegInfo->getRegSizeInBits(MO.getReg(), MachineRegInfo) / 8;
1162 Pad += Width;
1163 continue;
1165 // Check for registers that are remapped (for a Thumb1 prologue that
1166 // saves high registers).
1167 Register Reg = MO.getReg();
1168 if (unsigned RemappedReg = AFI->EHPrologueRemappedRegs.lookup(Reg))
1169 Reg = RemappedReg;
1170 RegList.push_back(Reg);
1172 break;
1173 case ARM::STR_PRE_IMM:
1174 case ARM::STR_PRE_REG:
1175 case ARM::t2STR_PRE:
1176 assert(MI->getOperand(2).getReg() == ARM::SP &&
1177 "Only stack pointer as a source reg is supported");
1178 RegList.push_back(SrcReg);
1179 break;
1181 if (MAI->getExceptionHandlingType() == ExceptionHandling::ARM) {
1182 ATS.emitRegSave(RegList, Opc == ARM::VSTMDDB_UPD);
1183 // Account for the SP adjustment, folded into the push.
1184 if (Pad)
1185 ATS.emitPad(Pad);
1187 } else {
1188 // Changes of stack / frame pointer.
1189 if (SrcReg == ARM::SP) {
1190 int64_t Offset = 0;
1191 switch (Opc) {
1192 default:
1193 MI->print(errs());
1194 llvm_unreachable("Unsupported opcode for unwinding information");
1195 case ARM::MOVr:
1196 case ARM::tMOVr:
1197 Offset = 0;
1198 break;
1199 case ARM::ADDri:
1200 case ARM::t2ADDri:
1201 case ARM::t2ADDri12:
1202 case ARM::t2ADDspImm:
1203 case ARM::t2ADDspImm12:
1204 Offset = -MI->getOperand(2).getImm();
1205 break;
1206 case ARM::SUBri:
1207 case ARM::t2SUBri:
1208 case ARM::t2SUBri12:
1209 case ARM::t2SUBspImm:
1210 case ARM::t2SUBspImm12:
1211 Offset = MI->getOperand(2).getImm();
1212 break;
1213 case ARM::tSUBspi:
1214 Offset = MI->getOperand(2).getImm()*4;
1215 break;
1216 case ARM::tADDspi:
1217 case ARM::tADDrSPi:
1218 Offset = -MI->getOperand(2).getImm()*4;
1219 break;
1220 case ARM::tADDhirr:
1221 Offset =
1222 -AFI->EHPrologueOffsetInRegs.lookup(MI->getOperand(2).getReg());
1223 break;
1226 if (MAI->getExceptionHandlingType() == ExceptionHandling::ARM) {
1227 if (DstReg == FramePtr && FramePtr != ARM::SP)
1228 // Set-up of the frame pointer. Positive values correspond to "add"
1229 // instruction.
1230 ATS.emitSetFP(FramePtr, ARM::SP, -Offset);
1231 else if (DstReg == ARM::SP) {
1232 // Change of SP by an offset. Positive values correspond to "sub"
1233 // instruction.
1234 ATS.emitPad(Offset);
1235 } else {
1236 // Move of SP to a register. Positive values correspond to an "add"
1237 // instruction.
1238 ATS.emitMovSP(DstReg, -Offset);
1241 } else if (DstReg == ARM::SP) {
1242 MI->print(errs());
1243 llvm_unreachable("Unsupported opcode for unwinding information");
1244 } else {
1245 int64_t Offset = 0;
1246 switch (Opc) {
1247 case ARM::tMOVr:
1248 // If a Thumb1 function spills r8-r11, we copy the values to low
1249 // registers before pushing them. Record the copy so we can emit the
1250 // correct ".save" later.
1251 AFI->EHPrologueRemappedRegs[DstReg] = SrcReg;
1252 break;
1253 case ARM::tLDRpci: {
1254 // Grab the constpool index and check, whether it corresponds to
1255 // original or cloned constpool entry.
1256 unsigned CPI = MI->getOperand(1).getIndex();
1257 const MachineConstantPool *MCP = MF.getConstantPool();
1258 if (CPI >= MCP->getConstants().size())
1259 CPI = AFI->getOriginalCPIdx(CPI);
1260 assert(CPI != -1U && "Invalid constpool index");
1262 // Derive the actual offset.
1263 const MachineConstantPoolEntry &CPE = MCP->getConstants()[CPI];
1264 assert(!CPE.isMachineConstantPoolEntry() && "Invalid constpool entry");
1265 Offset = cast<ConstantInt>(CPE.Val.ConstVal)->getSExtValue();
1266 AFI->EHPrologueOffsetInRegs[DstReg] = Offset;
1267 break;
1269 case ARM::t2MOVi16:
1270 Offset = MI->getOperand(1).getImm();
1271 AFI->EHPrologueOffsetInRegs[DstReg] = Offset;
1272 break;
1273 case ARM::t2MOVTi16:
1274 Offset = MI->getOperand(2).getImm();
1275 AFI->EHPrologueOffsetInRegs[DstReg] |= (Offset << 16);
1276 break;
1277 default:
1278 MI->print(errs());
1279 llvm_unreachable("Unsupported opcode for unwinding information");
1285 // Simple pseudo-instructions have their lowering (with expansion to real
1286 // instructions) auto-generated.
1287 #include "ARMGenMCPseudoLowering.inc"
1289 void ARMAsmPrinter::emitInstruction(const MachineInstr *MI) {
1290 const DataLayout &DL = getDataLayout();
1291 MCTargetStreamer &TS = *OutStreamer->getTargetStreamer();
1292 ARMTargetStreamer &ATS = static_cast<ARMTargetStreamer &>(TS);
1294 const MachineFunction &MF = *MI->getParent()->getParent();
1295 const ARMSubtarget &STI = MF.getSubtarget<ARMSubtarget>();
1297 // If we just ended a constant pool, mark it as such.
1298 if (InConstantPool && MI->getOpcode() != ARM::CONSTPOOL_ENTRY) {
1299 OutStreamer->emitDataRegion(MCDR_DataRegionEnd);
1300 InConstantPool = false;
1303 // Emit unwinding stuff for frame-related instructions
1304 if (Subtarget->isTargetEHABICompatible() &&
1305 MI->getFlag(MachineInstr::FrameSetup))
1306 EmitUnwindingInstruction(MI);
1308 // Do any auto-generated pseudo lowerings.
1309 if (emitPseudoExpansionLowering(*OutStreamer, MI))
1310 return;
1312 assert(!convertAddSubFlagsOpcode(MI->getOpcode()) &&
1313 "Pseudo flag setting opcode should be expanded early");
1315 // Check for manual lowerings.
1316 unsigned Opc = MI->getOpcode();
1317 switch (Opc) {
1318 case ARM::t2MOVi32imm: llvm_unreachable("Should be lowered by thumb2it pass");
1319 case ARM::DBG_VALUE: llvm_unreachable("Should be handled by generic printing");
1320 case ARM::LEApcrel:
1321 case ARM::tLEApcrel:
1322 case ARM::t2LEApcrel: {
1323 // FIXME: Need to also handle globals and externals
1324 MCSymbol *CPISymbol = GetCPISymbol(MI->getOperand(1).getIndex());
1325 EmitToStreamer(*OutStreamer, MCInstBuilder(MI->getOpcode() ==
1326 ARM::t2LEApcrel ? ARM::t2ADR
1327 : (MI->getOpcode() == ARM::tLEApcrel ? ARM::tADR
1328 : ARM::ADR))
1329 .addReg(MI->getOperand(0).getReg())
1330 .addExpr(MCSymbolRefExpr::create(CPISymbol, OutContext))
1331 // Add predicate operands.
1332 .addImm(MI->getOperand(2).getImm())
1333 .addReg(MI->getOperand(3).getReg()));
1334 return;
1336 case ARM::LEApcrelJT:
1337 case ARM::tLEApcrelJT:
1338 case ARM::t2LEApcrelJT: {
1339 MCSymbol *JTIPICSymbol =
1340 GetARMJTIPICJumpTableLabel(MI->getOperand(1).getIndex());
1341 EmitToStreamer(*OutStreamer, MCInstBuilder(MI->getOpcode() ==
1342 ARM::t2LEApcrelJT ? ARM::t2ADR
1343 : (MI->getOpcode() == ARM::tLEApcrelJT ? ARM::tADR
1344 : ARM::ADR))
1345 .addReg(MI->getOperand(0).getReg())
1346 .addExpr(MCSymbolRefExpr::create(JTIPICSymbol, OutContext))
1347 // Add predicate operands.
1348 .addImm(MI->getOperand(2).getImm())
1349 .addReg(MI->getOperand(3).getReg()));
1350 return;
1352 // Darwin call instructions are just normal call instructions with different
1353 // clobber semantics (they clobber R9).
1354 case ARM::BX_CALL: {
1355 EmitToStreamer(*OutStreamer, MCInstBuilder(ARM::MOVr)
1356 .addReg(ARM::LR)
1357 .addReg(ARM::PC)
1358 // Add predicate operands.
1359 .addImm(ARMCC::AL)
1360 .addReg(0)
1361 // Add 's' bit operand (always reg0 for this)
1362 .addReg(0));
1364 assert(Subtarget->hasV4TOps());
1365 EmitToStreamer(*OutStreamer, MCInstBuilder(ARM::BX)
1366 .addReg(MI->getOperand(0).getReg()));
1367 return;
1369 case ARM::tBX_CALL: {
1370 if (Subtarget->hasV5TOps())
1371 llvm_unreachable("Expected BLX to be selected for v5t+");
1373 // On ARM v4t, when doing a call from thumb mode, we need to ensure
1374 // that the saved lr has its LSB set correctly (the arch doesn't
1375 // have blx).
1376 // So here we generate a bl to a small jump pad that does bx rN.
1377 // The jump pads are emitted after the function body.
1379 Register TReg = MI->getOperand(0).getReg();
1380 MCSymbol *TRegSym = nullptr;
1381 for (std::pair<unsigned, MCSymbol *> &TIP : ThumbIndirectPads) {
1382 if (TIP.first == TReg) {
1383 TRegSym = TIP.second;
1384 break;
1388 if (!TRegSym) {
1389 TRegSym = OutContext.createTempSymbol();
1390 ThumbIndirectPads.push_back(std::make_pair(TReg, TRegSym));
1393 // Create a link-saving branch to the Reg Indirect Jump Pad.
1394 EmitToStreamer(*OutStreamer, MCInstBuilder(ARM::tBL)
1395 // Predicate comes first here.
1396 .addImm(ARMCC::AL).addReg(0)
1397 .addExpr(MCSymbolRefExpr::create(TRegSym, OutContext)));
1398 return;
1400 case ARM::BMOVPCRX_CALL: {
1401 EmitToStreamer(*OutStreamer, MCInstBuilder(ARM::MOVr)
1402 .addReg(ARM::LR)
1403 .addReg(ARM::PC)
1404 // Add predicate operands.
1405 .addImm(ARMCC::AL)
1406 .addReg(0)
1407 // Add 's' bit operand (always reg0 for this)
1408 .addReg(0));
1410 EmitToStreamer(*OutStreamer, MCInstBuilder(ARM::MOVr)
1411 .addReg(ARM::PC)
1412 .addReg(MI->getOperand(0).getReg())
1413 // Add predicate operands.
1414 .addImm(ARMCC::AL)
1415 .addReg(0)
1416 // Add 's' bit operand (always reg0 for this)
1417 .addReg(0));
1418 return;
1420 case ARM::BMOVPCB_CALL: {
1421 EmitToStreamer(*OutStreamer, MCInstBuilder(ARM::MOVr)
1422 .addReg(ARM::LR)
1423 .addReg(ARM::PC)
1424 // Add predicate operands.
1425 .addImm(ARMCC::AL)
1426 .addReg(0)
1427 // Add 's' bit operand (always reg0 for this)
1428 .addReg(0));
1430 const MachineOperand &Op = MI->getOperand(0);
1431 const GlobalValue *GV = Op.getGlobal();
1432 const unsigned TF = Op.getTargetFlags();
1433 MCSymbol *GVSym = GetARMGVSymbol(GV, TF);
1434 const MCExpr *GVSymExpr = MCSymbolRefExpr::create(GVSym, OutContext);
1435 EmitToStreamer(*OutStreamer, MCInstBuilder(ARM::Bcc)
1436 .addExpr(GVSymExpr)
1437 // Add predicate operands.
1438 .addImm(ARMCC::AL)
1439 .addReg(0));
1440 return;
1442 case ARM::MOVi16_ga_pcrel:
1443 case ARM::t2MOVi16_ga_pcrel: {
1444 MCInst TmpInst;
1445 TmpInst.setOpcode(Opc == ARM::MOVi16_ga_pcrel? ARM::MOVi16 : ARM::t2MOVi16);
1446 TmpInst.addOperand(MCOperand::createReg(MI->getOperand(0).getReg()));
1448 unsigned TF = MI->getOperand(1).getTargetFlags();
1449 const GlobalValue *GV = MI->getOperand(1).getGlobal();
1450 MCSymbol *GVSym = GetARMGVSymbol(GV, TF);
1451 const MCExpr *GVSymExpr = MCSymbolRefExpr::create(GVSym, OutContext);
1453 MCSymbol *LabelSym =
1454 getPICLabel(DL.getPrivateGlobalPrefix(), getFunctionNumber(),
1455 MI->getOperand(2).getImm(), OutContext);
1456 const MCExpr *LabelSymExpr= MCSymbolRefExpr::create(LabelSym, OutContext);
1457 unsigned PCAdj = (Opc == ARM::MOVi16_ga_pcrel) ? 8 : 4;
1458 const MCExpr *PCRelExpr =
1459 ARMMCExpr::createLower16(MCBinaryExpr::createSub(GVSymExpr,
1460 MCBinaryExpr::createAdd(LabelSymExpr,
1461 MCConstantExpr::create(PCAdj, OutContext),
1462 OutContext), OutContext), OutContext);
1463 TmpInst.addOperand(MCOperand::createExpr(PCRelExpr));
1465 // Add predicate operands.
1466 TmpInst.addOperand(MCOperand::createImm(ARMCC::AL));
1467 TmpInst.addOperand(MCOperand::createReg(0));
1468 // Add 's' bit operand (always reg0 for this)
1469 TmpInst.addOperand(MCOperand::createReg(0));
1470 EmitToStreamer(*OutStreamer, TmpInst);
1471 return;
1473 case ARM::MOVTi16_ga_pcrel:
1474 case ARM::t2MOVTi16_ga_pcrel: {
1475 MCInst TmpInst;
1476 TmpInst.setOpcode(Opc == ARM::MOVTi16_ga_pcrel
1477 ? ARM::MOVTi16 : ARM::t2MOVTi16);
1478 TmpInst.addOperand(MCOperand::createReg(MI->getOperand(0).getReg()));
1479 TmpInst.addOperand(MCOperand::createReg(MI->getOperand(1).getReg()));
1481 unsigned TF = MI->getOperand(2).getTargetFlags();
1482 const GlobalValue *GV = MI->getOperand(2).getGlobal();
1483 MCSymbol *GVSym = GetARMGVSymbol(GV, TF);
1484 const MCExpr *GVSymExpr = MCSymbolRefExpr::create(GVSym, OutContext);
1486 MCSymbol *LabelSym =
1487 getPICLabel(DL.getPrivateGlobalPrefix(), getFunctionNumber(),
1488 MI->getOperand(3).getImm(), OutContext);
1489 const MCExpr *LabelSymExpr= MCSymbolRefExpr::create(LabelSym, OutContext);
1490 unsigned PCAdj = (Opc == ARM::MOVTi16_ga_pcrel) ? 8 : 4;
1491 const MCExpr *PCRelExpr =
1492 ARMMCExpr::createUpper16(MCBinaryExpr::createSub(GVSymExpr,
1493 MCBinaryExpr::createAdd(LabelSymExpr,
1494 MCConstantExpr::create(PCAdj, OutContext),
1495 OutContext), OutContext), OutContext);
1496 TmpInst.addOperand(MCOperand::createExpr(PCRelExpr));
1497 // Add predicate operands.
1498 TmpInst.addOperand(MCOperand::createImm(ARMCC::AL));
1499 TmpInst.addOperand(MCOperand::createReg(0));
1500 // Add 's' bit operand (always reg0 for this)
1501 TmpInst.addOperand(MCOperand::createReg(0));
1502 EmitToStreamer(*OutStreamer, TmpInst);
1503 return;
1505 case ARM::t2BFi:
1506 case ARM::t2BFic:
1507 case ARM::t2BFLi:
1508 case ARM::t2BFr:
1509 case ARM::t2BFLr: {
1510 // This is a Branch Future instruction.
1512 const MCExpr *BranchLabel = MCSymbolRefExpr::create(
1513 getBFLabel(DL.getPrivateGlobalPrefix(), getFunctionNumber(),
1514 MI->getOperand(0).getIndex(), OutContext),
1515 OutContext);
1517 auto MCInst = MCInstBuilder(Opc).addExpr(BranchLabel);
1518 if (MI->getOperand(1).isReg()) {
1519 // For BFr/BFLr
1520 MCInst.addReg(MI->getOperand(1).getReg());
1521 } else {
1522 // For BFi/BFLi/BFic
1523 const MCExpr *BranchTarget;
1524 if (MI->getOperand(1).isMBB())
1525 BranchTarget = MCSymbolRefExpr::create(
1526 MI->getOperand(1).getMBB()->getSymbol(), OutContext);
1527 else if (MI->getOperand(1).isGlobal()) {
1528 const GlobalValue *GV = MI->getOperand(1).getGlobal();
1529 BranchTarget = MCSymbolRefExpr::create(
1530 GetARMGVSymbol(GV, MI->getOperand(1).getTargetFlags()), OutContext);
1531 } else if (MI->getOperand(1).isSymbol()) {
1532 BranchTarget = MCSymbolRefExpr::create(
1533 GetExternalSymbolSymbol(MI->getOperand(1).getSymbolName()),
1534 OutContext);
1535 } else
1536 llvm_unreachable("Unhandled operand kind in Branch Future instruction");
1538 MCInst.addExpr(BranchTarget);
1541 if (Opc == ARM::t2BFic) {
1542 const MCExpr *ElseLabel = MCSymbolRefExpr::create(
1543 getBFLabel(DL.getPrivateGlobalPrefix(), getFunctionNumber(),
1544 MI->getOperand(2).getIndex(), OutContext),
1545 OutContext);
1546 MCInst.addExpr(ElseLabel);
1547 MCInst.addImm(MI->getOperand(3).getImm());
1548 } else {
1549 MCInst.addImm(MI->getOperand(2).getImm())
1550 .addReg(MI->getOperand(3).getReg());
1553 EmitToStreamer(*OutStreamer, MCInst);
1554 return;
1556 case ARM::t2BF_LabelPseudo: {
1557 // This is a pseudo op for a label used by a branch future instruction
1559 // Emit the label.
1560 OutStreamer->emitLabel(getBFLabel(DL.getPrivateGlobalPrefix(),
1561 getFunctionNumber(),
1562 MI->getOperand(0).getIndex(), OutContext));
1563 return;
1565 case ARM::tPICADD: {
1566 // This is a pseudo op for a label + instruction sequence, which looks like:
1567 // LPC0:
1568 // add r0, pc
1569 // This adds the address of LPC0 to r0.
1571 // Emit the label.
1572 OutStreamer->emitLabel(getPICLabel(DL.getPrivateGlobalPrefix(),
1573 getFunctionNumber(),
1574 MI->getOperand(2).getImm(), OutContext));
1576 // Form and emit the add.
1577 EmitToStreamer(*OutStreamer, MCInstBuilder(ARM::tADDhirr)
1578 .addReg(MI->getOperand(0).getReg())
1579 .addReg(MI->getOperand(0).getReg())
1580 .addReg(ARM::PC)
1581 // Add predicate operands.
1582 .addImm(ARMCC::AL)
1583 .addReg(0));
1584 return;
1586 case ARM::PICADD: {
1587 // This is a pseudo op for a label + instruction sequence, which looks like:
1588 // LPC0:
1589 // add r0, pc, r0
1590 // This adds the address of LPC0 to r0.
1592 // Emit the label.
1593 OutStreamer->emitLabel(getPICLabel(DL.getPrivateGlobalPrefix(),
1594 getFunctionNumber(),
1595 MI->getOperand(2).getImm(), OutContext));
1597 // Form and emit the add.
1598 EmitToStreamer(*OutStreamer, MCInstBuilder(ARM::ADDrr)
1599 .addReg(MI->getOperand(0).getReg())
1600 .addReg(ARM::PC)
1601 .addReg(MI->getOperand(1).getReg())
1602 // Add predicate operands.
1603 .addImm(MI->getOperand(3).getImm())
1604 .addReg(MI->getOperand(4).getReg())
1605 // Add 's' bit operand (always reg0 for this)
1606 .addReg(0));
1607 return;
1609 case ARM::PICSTR:
1610 case ARM::PICSTRB:
1611 case ARM::PICSTRH:
1612 case ARM::PICLDR:
1613 case ARM::PICLDRB:
1614 case ARM::PICLDRH:
1615 case ARM::PICLDRSB:
1616 case ARM::PICLDRSH: {
1617 // This is a pseudo op for a label + instruction sequence, which looks like:
1618 // LPC0:
1619 // OP r0, [pc, r0]
1620 // The LCP0 label is referenced by a constant pool entry in order to get
1621 // a PC-relative address at the ldr instruction.
1623 // Emit the label.
1624 OutStreamer->emitLabel(getPICLabel(DL.getPrivateGlobalPrefix(),
1625 getFunctionNumber(),
1626 MI->getOperand(2).getImm(), OutContext));
1628 // Form and emit the load
1629 unsigned Opcode;
1630 switch (MI->getOpcode()) {
1631 default:
1632 llvm_unreachable("Unexpected opcode!");
1633 case ARM::PICSTR: Opcode = ARM::STRrs; break;
1634 case ARM::PICSTRB: Opcode = ARM::STRBrs; break;
1635 case ARM::PICSTRH: Opcode = ARM::STRH; break;
1636 case ARM::PICLDR: Opcode = ARM::LDRrs; break;
1637 case ARM::PICLDRB: Opcode = ARM::LDRBrs; break;
1638 case ARM::PICLDRH: Opcode = ARM::LDRH; break;
1639 case ARM::PICLDRSB: Opcode = ARM::LDRSB; break;
1640 case ARM::PICLDRSH: Opcode = ARM::LDRSH; break;
1642 EmitToStreamer(*OutStreamer, MCInstBuilder(Opcode)
1643 .addReg(MI->getOperand(0).getReg())
1644 .addReg(ARM::PC)
1645 .addReg(MI->getOperand(1).getReg())
1646 .addImm(0)
1647 // Add predicate operands.
1648 .addImm(MI->getOperand(3).getImm())
1649 .addReg(MI->getOperand(4).getReg()));
1651 return;
1653 case ARM::CONSTPOOL_ENTRY: {
1654 if (Subtarget->genExecuteOnly())
1655 llvm_unreachable("execute-only should not generate constant pools");
1657 /// CONSTPOOL_ENTRY - This instruction represents a floating constant pool
1658 /// in the function. The first operand is the ID# for this instruction, the
1659 /// second is the index into the MachineConstantPool that this is, the third
1660 /// is the size in bytes of this constant pool entry.
1661 /// The required alignment is specified on the basic block holding this MI.
1662 unsigned LabelId = (unsigned)MI->getOperand(0).getImm();
1663 unsigned CPIdx = (unsigned)MI->getOperand(1).getIndex();
1665 // If this is the first entry of the pool, mark it.
1666 if (!InConstantPool) {
1667 OutStreamer->emitDataRegion(MCDR_DataRegion);
1668 InConstantPool = true;
1671 OutStreamer->emitLabel(GetCPISymbol(LabelId));
1673 const MachineConstantPoolEntry &MCPE = MCP->getConstants()[CPIdx];
1674 if (MCPE.isMachineConstantPoolEntry())
1675 emitMachineConstantPoolValue(MCPE.Val.MachineCPVal);
1676 else
1677 emitGlobalConstant(DL, MCPE.Val.ConstVal);
1678 return;
1680 case ARM::JUMPTABLE_ADDRS:
1681 emitJumpTableAddrs(MI);
1682 return;
1683 case ARM::JUMPTABLE_INSTS:
1684 emitJumpTableInsts(MI);
1685 return;
1686 case ARM::JUMPTABLE_TBB:
1687 case ARM::JUMPTABLE_TBH:
1688 emitJumpTableTBInst(MI, MI->getOpcode() == ARM::JUMPTABLE_TBB ? 1 : 2);
1689 return;
1690 case ARM::t2BR_JT: {
1691 EmitToStreamer(*OutStreamer, MCInstBuilder(ARM::tMOVr)
1692 .addReg(ARM::PC)
1693 .addReg(MI->getOperand(0).getReg())
1694 // Add predicate operands.
1695 .addImm(ARMCC::AL)
1696 .addReg(0));
1697 return;
1699 case ARM::t2TBB_JT:
1700 case ARM::t2TBH_JT: {
1701 unsigned Opc = MI->getOpcode() == ARM::t2TBB_JT ? ARM::t2TBB : ARM::t2TBH;
1702 // Lower and emit the PC label, then the instruction itself.
1703 OutStreamer->emitLabel(GetCPISymbol(MI->getOperand(3).getImm()));
1704 EmitToStreamer(*OutStreamer, MCInstBuilder(Opc)
1705 .addReg(MI->getOperand(0).getReg())
1706 .addReg(MI->getOperand(1).getReg())
1707 // Add predicate operands.
1708 .addImm(ARMCC::AL)
1709 .addReg(0));
1710 return;
1712 case ARM::tTBB_JT:
1713 case ARM::tTBH_JT: {
1715 bool Is8Bit = MI->getOpcode() == ARM::tTBB_JT;
1716 Register Base = MI->getOperand(0).getReg();
1717 Register Idx = MI->getOperand(1).getReg();
1718 assert(MI->getOperand(1).isKill() && "We need the index register as scratch!");
1720 // Multiply up idx if necessary.
1721 if (!Is8Bit)
1722 EmitToStreamer(*OutStreamer, MCInstBuilder(ARM::tLSLri)
1723 .addReg(Idx)
1724 .addReg(ARM::CPSR)
1725 .addReg(Idx)
1726 .addImm(1)
1727 // Add predicate operands.
1728 .addImm(ARMCC::AL)
1729 .addReg(0));
1731 if (Base == ARM::PC) {
1732 // TBB [base, idx] =
1733 // ADDS idx, idx, base
1734 // LDRB idx, [idx, #4] ; or LDRH if TBH
1735 // LSLS idx, #1
1736 // ADDS pc, pc, idx
1738 // When using PC as the base, it's important that there is no padding
1739 // between the last ADDS and the start of the jump table. The jump table
1740 // is 4-byte aligned, so we ensure we're 4 byte aligned here too.
1742 // FIXME: Ideally we could vary the LDRB index based on the padding
1743 // between the sequence and jump table, however that relies on MCExprs
1744 // for load indexes which are currently not supported.
1745 OutStreamer->emitCodeAlignment(4);
1746 EmitToStreamer(*OutStreamer, MCInstBuilder(ARM::tADDhirr)
1747 .addReg(Idx)
1748 .addReg(Idx)
1749 .addReg(Base)
1750 // Add predicate operands.
1751 .addImm(ARMCC::AL)
1752 .addReg(0));
1754 unsigned Opc = Is8Bit ? ARM::tLDRBi : ARM::tLDRHi;
1755 EmitToStreamer(*OutStreamer, MCInstBuilder(Opc)
1756 .addReg(Idx)
1757 .addReg(Idx)
1758 .addImm(Is8Bit ? 4 : 2)
1759 // Add predicate operands.
1760 .addImm(ARMCC::AL)
1761 .addReg(0));
1762 } else {
1763 // TBB [base, idx] =
1764 // LDRB idx, [base, idx] ; or LDRH if TBH
1765 // LSLS idx, #1
1766 // ADDS pc, pc, idx
1768 unsigned Opc = Is8Bit ? ARM::tLDRBr : ARM::tLDRHr;
1769 EmitToStreamer(*OutStreamer, MCInstBuilder(Opc)
1770 .addReg(Idx)
1771 .addReg(Base)
1772 .addReg(Idx)
1773 // Add predicate operands.
1774 .addImm(ARMCC::AL)
1775 .addReg(0));
1778 EmitToStreamer(*OutStreamer, MCInstBuilder(ARM::tLSLri)
1779 .addReg(Idx)
1780 .addReg(ARM::CPSR)
1781 .addReg(Idx)
1782 .addImm(1)
1783 // Add predicate operands.
1784 .addImm(ARMCC::AL)
1785 .addReg(0));
1787 OutStreamer->emitLabel(GetCPISymbol(MI->getOperand(3).getImm()));
1788 EmitToStreamer(*OutStreamer, MCInstBuilder(ARM::tADDhirr)
1789 .addReg(ARM::PC)
1790 .addReg(ARM::PC)
1791 .addReg(Idx)
1792 // Add predicate operands.
1793 .addImm(ARMCC::AL)
1794 .addReg(0));
1795 return;
1797 case ARM::tBR_JTr:
1798 case ARM::BR_JTr: {
1799 // mov pc, target
1800 MCInst TmpInst;
1801 unsigned Opc = MI->getOpcode() == ARM::BR_JTr ?
1802 ARM::MOVr : ARM::tMOVr;
1803 TmpInst.setOpcode(Opc);
1804 TmpInst.addOperand(MCOperand::createReg(ARM::PC));
1805 TmpInst.addOperand(MCOperand::createReg(MI->getOperand(0).getReg()));
1806 // Add predicate operands.
1807 TmpInst.addOperand(MCOperand::createImm(ARMCC::AL));
1808 TmpInst.addOperand(MCOperand::createReg(0));
1809 // Add 's' bit operand (always reg0 for this)
1810 if (Opc == ARM::MOVr)
1811 TmpInst.addOperand(MCOperand::createReg(0));
1812 EmitToStreamer(*OutStreamer, TmpInst);
1813 return;
1815 case ARM::BR_JTm_i12: {
1816 // ldr pc, target
1817 MCInst TmpInst;
1818 TmpInst.setOpcode(ARM::LDRi12);
1819 TmpInst.addOperand(MCOperand::createReg(ARM::PC));
1820 TmpInst.addOperand(MCOperand::createReg(MI->getOperand(0).getReg()));
1821 TmpInst.addOperand(MCOperand::createImm(MI->getOperand(2).getImm()));
1822 // Add predicate operands.
1823 TmpInst.addOperand(MCOperand::createImm(ARMCC::AL));
1824 TmpInst.addOperand(MCOperand::createReg(0));
1825 EmitToStreamer(*OutStreamer, TmpInst);
1826 return;
1828 case ARM::BR_JTm_rs: {
1829 // ldr pc, target
1830 MCInst TmpInst;
1831 TmpInst.setOpcode(ARM::LDRrs);
1832 TmpInst.addOperand(MCOperand::createReg(ARM::PC));
1833 TmpInst.addOperand(MCOperand::createReg(MI->getOperand(0).getReg()));
1834 TmpInst.addOperand(MCOperand::createReg(MI->getOperand(1).getReg()));
1835 TmpInst.addOperand(MCOperand::createImm(MI->getOperand(2).getImm()));
1836 // Add predicate operands.
1837 TmpInst.addOperand(MCOperand::createImm(ARMCC::AL));
1838 TmpInst.addOperand(MCOperand::createReg(0));
1839 EmitToStreamer(*OutStreamer, TmpInst);
1840 return;
1842 case ARM::BR_JTadd: {
1843 // add pc, target, idx
1844 EmitToStreamer(*OutStreamer, MCInstBuilder(ARM::ADDrr)
1845 .addReg(ARM::PC)
1846 .addReg(MI->getOperand(0).getReg())
1847 .addReg(MI->getOperand(1).getReg())
1848 // Add predicate operands.
1849 .addImm(ARMCC::AL)
1850 .addReg(0)
1851 // Add 's' bit operand (always reg0 for this)
1852 .addReg(0));
1853 return;
1855 case ARM::SPACE:
1856 OutStreamer->emitZeros(MI->getOperand(1).getImm());
1857 return;
1858 case ARM::TRAP: {
1859 // Non-Darwin binutils don't yet support the "trap" mnemonic.
1860 // FIXME: Remove this special case when they do.
1861 if (!Subtarget->isTargetMachO()) {
1862 uint32_t Val = 0xe7ffdefeUL;
1863 OutStreamer->AddComment("trap");
1864 ATS.emitInst(Val);
1865 return;
1867 break;
1869 case ARM::TRAPNaCl: {
1870 uint32_t Val = 0xe7fedef0UL;
1871 OutStreamer->AddComment("trap");
1872 ATS.emitInst(Val);
1873 return;
1875 case ARM::tTRAP: {
1876 // Non-Darwin binutils don't yet support the "trap" mnemonic.
1877 // FIXME: Remove this special case when they do.
1878 if (!Subtarget->isTargetMachO()) {
1879 uint16_t Val = 0xdefe;
1880 OutStreamer->AddComment("trap");
1881 ATS.emitInst(Val, 'n');
1882 return;
1884 break;
1886 case ARM::t2Int_eh_sjlj_setjmp:
1887 case ARM::t2Int_eh_sjlj_setjmp_nofp:
1888 case ARM::tInt_eh_sjlj_setjmp: {
1889 // Two incoming args: GPR:$src, GPR:$val
1890 // mov $val, pc
1891 // adds $val, #7
1892 // str $val, [$src, #4]
1893 // movs r0, #0
1894 // b LSJLJEH
1895 // movs r0, #1
1896 // LSJLJEH:
1897 Register SrcReg = MI->getOperand(0).getReg();
1898 Register ValReg = MI->getOperand(1).getReg();
1899 MCSymbol *Label = OutContext.createTempSymbol("SJLJEH");
1900 OutStreamer->AddComment("eh_setjmp begin");
1901 EmitToStreamer(*OutStreamer, MCInstBuilder(ARM::tMOVr)
1902 .addReg(ValReg)
1903 .addReg(ARM::PC)
1904 // Predicate.
1905 .addImm(ARMCC::AL)
1906 .addReg(0));
1908 EmitToStreamer(*OutStreamer, MCInstBuilder(ARM::tADDi3)
1909 .addReg(ValReg)
1910 // 's' bit operand
1911 .addReg(ARM::CPSR)
1912 .addReg(ValReg)
1913 .addImm(7)
1914 // Predicate.
1915 .addImm(ARMCC::AL)
1916 .addReg(0));
1918 EmitToStreamer(*OutStreamer, MCInstBuilder(ARM::tSTRi)
1919 .addReg(ValReg)
1920 .addReg(SrcReg)
1921 // The offset immediate is #4. The operand value is scaled by 4 for the
1922 // tSTR instruction.
1923 .addImm(1)
1924 // Predicate.
1925 .addImm(ARMCC::AL)
1926 .addReg(0));
1928 EmitToStreamer(*OutStreamer, MCInstBuilder(ARM::tMOVi8)
1929 .addReg(ARM::R0)
1930 .addReg(ARM::CPSR)
1931 .addImm(0)
1932 // Predicate.
1933 .addImm(ARMCC::AL)
1934 .addReg(0));
1936 const MCExpr *SymbolExpr = MCSymbolRefExpr::create(Label, OutContext);
1937 EmitToStreamer(*OutStreamer, MCInstBuilder(ARM::tB)
1938 .addExpr(SymbolExpr)
1939 .addImm(ARMCC::AL)
1940 .addReg(0));
1942 OutStreamer->AddComment("eh_setjmp end");
1943 EmitToStreamer(*OutStreamer, MCInstBuilder(ARM::tMOVi8)
1944 .addReg(ARM::R0)
1945 .addReg(ARM::CPSR)
1946 .addImm(1)
1947 // Predicate.
1948 .addImm(ARMCC::AL)
1949 .addReg(0));
1951 OutStreamer->emitLabel(Label);
1952 return;
1955 case ARM::Int_eh_sjlj_setjmp_nofp:
1956 case ARM::Int_eh_sjlj_setjmp: {
1957 // Two incoming args: GPR:$src, GPR:$val
1958 // add $val, pc, #8
1959 // str $val, [$src, #+4]
1960 // mov r0, #0
1961 // add pc, pc, #0
1962 // mov r0, #1
1963 Register SrcReg = MI->getOperand(0).getReg();
1964 Register ValReg = MI->getOperand(1).getReg();
1966 OutStreamer->AddComment("eh_setjmp begin");
1967 EmitToStreamer(*OutStreamer, MCInstBuilder(ARM::ADDri)
1968 .addReg(ValReg)
1969 .addReg(ARM::PC)
1970 .addImm(8)
1971 // Predicate.
1972 .addImm(ARMCC::AL)
1973 .addReg(0)
1974 // 's' bit operand (always reg0 for this).
1975 .addReg(0));
1977 EmitToStreamer(*OutStreamer, MCInstBuilder(ARM::STRi12)
1978 .addReg(ValReg)
1979 .addReg(SrcReg)
1980 .addImm(4)
1981 // Predicate.
1982 .addImm(ARMCC::AL)
1983 .addReg(0));
1985 EmitToStreamer(*OutStreamer, MCInstBuilder(ARM::MOVi)
1986 .addReg(ARM::R0)
1987 .addImm(0)
1988 // Predicate.
1989 .addImm(ARMCC::AL)
1990 .addReg(0)
1991 // 's' bit operand (always reg0 for this).
1992 .addReg(0));
1994 EmitToStreamer(*OutStreamer, MCInstBuilder(ARM::ADDri)
1995 .addReg(ARM::PC)
1996 .addReg(ARM::PC)
1997 .addImm(0)
1998 // Predicate.
1999 .addImm(ARMCC::AL)
2000 .addReg(0)
2001 // 's' bit operand (always reg0 for this).
2002 .addReg(0));
2004 OutStreamer->AddComment("eh_setjmp end");
2005 EmitToStreamer(*OutStreamer, MCInstBuilder(ARM::MOVi)
2006 .addReg(ARM::R0)
2007 .addImm(1)
2008 // Predicate.
2009 .addImm(ARMCC::AL)
2010 .addReg(0)
2011 // 's' bit operand (always reg0 for this).
2012 .addReg(0));
2013 return;
2015 case ARM::Int_eh_sjlj_longjmp: {
2016 // ldr sp, [$src, #8]
2017 // ldr $scratch, [$src, #4]
2018 // ldr r7, [$src]
2019 // bx $scratch
2020 Register SrcReg = MI->getOperand(0).getReg();
2021 Register ScratchReg = MI->getOperand(1).getReg();
2022 EmitToStreamer(*OutStreamer, MCInstBuilder(ARM::LDRi12)
2023 .addReg(ARM::SP)
2024 .addReg(SrcReg)
2025 .addImm(8)
2026 // Predicate.
2027 .addImm(ARMCC::AL)
2028 .addReg(0));
2030 EmitToStreamer(*OutStreamer, MCInstBuilder(ARM::LDRi12)
2031 .addReg(ScratchReg)
2032 .addReg(SrcReg)
2033 .addImm(4)
2034 // Predicate.
2035 .addImm(ARMCC::AL)
2036 .addReg(0));
2038 if (STI.isTargetDarwin() || STI.isTargetWindows()) {
2039 // These platforms always use the same frame register
2040 EmitToStreamer(*OutStreamer, MCInstBuilder(ARM::LDRi12)
2041 .addReg(STI.getFramePointerReg())
2042 .addReg(SrcReg)
2043 .addImm(0)
2044 // Predicate.
2045 .addImm(ARMCC::AL)
2046 .addReg(0));
2047 } else {
2048 // If the calling code might use either R7 or R11 as
2049 // frame pointer register, restore it into both.
2050 EmitToStreamer(*OutStreamer, MCInstBuilder(ARM::LDRi12)
2051 .addReg(ARM::R7)
2052 .addReg(SrcReg)
2053 .addImm(0)
2054 // Predicate.
2055 .addImm(ARMCC::AL)
2056 .addReg(0));
2057 EmitToStreamer(*OutStreamer, MCInstBuilder(ARM::LDRi12)
2058 .addReg(ARM::R11)
2059 .addReg(SrcReg)
2060 .addImm(0)
2061 // Predicate.
2062 .addImm(ARMCC::AL)
2063 .addReg(0));
2066 assert(Subtarget->hasV4TOps());
2067 EmitToStreamer(*OutStreamer, MCInstBuilder(ARM::BX)
2068 .addReg(ScratchReg)
2069 // Predicate.
2070 .addImm(ARMCC::AL)
2071 .addReg(0));
2072 return;
2074 case ARM::tInt_eh_sjlj_longjmp: {
2075 // ldr $scratch, [$src, #8]
2076 // mov sp, $scratch
2077 // ldr $scratch, [$src, #4]
2078 // ldr r7, [$src]
2079 // bx $scratch
2080 Register SrcReg = MI->getOperand(0).getReg();
2081 Register ScratchReg = MI->getOperand(1).getReg();
2083 EmitToStreamer(*OutStreamer, MCInstBuilder(ARM::tLDRi)
2084 .addReg(ScratchReg)
2085 .addReg(SrcReg)
2086 // The offset immediate is #8. The operand value is scaled by 4 for the
2087 // tLDR instruction.
2088 .addImm(2)
2089 // Predicate.
2090 .addImm(ARMCC::AL)
2091 .addReg(0));
2093 EmitToStreamer(*OutStreamer, MCInstBuilder(ARM::tMOVr)
2094 .addReg(ARM::SP)
2095 .addReg(ScratchReg)
2096 // Predicate.
2097 .addImm(ARMCC::AL)
2098 .addReg(0));
2100 EmitToStreamer(*OutStreamer, MCInstBuilder(ARM::tLDRi)
2101 .addReg(ScratchReg)
2102 .addReg(SrcReg)
2103 .addImm(1)
2104 // Predicate.
2105 .addImm(ARMCC::AL)
2106 .addReg(0));
2108 if (STI.isTargetDarwin() || STI.isTargetWindows()) {
2109 // These platforms always use the same frame register
2110 EmitToStreamer(*OutStreamer, MCInstBuilder(ARM::tLDRi)
2111 .addReg(STI.getFramePointerReg())
2112 .addReg(SrcReg)
2113 .addImm(0)
2114 // Predicate.
2115 .addImm(ARMCC::AL)
2116 .addReg(0));
2117 } else {
2118 // If the calling code might use either R7 or R11 as
2119 // frame pointer register, restore it into both.
2120 EmitToStreamer(*OutStreamer, MCInstBuilder(ARM::tLDRi)
2121 .addReg(ARM::R7)
2122 .addReg(SrcReg)
2123 .addImm(0)
2124 // Predicate.
2125 .addImm(ARMCC::AL)
2126 .addReg(0));
2127 EmitToStreamer(*OutStreamer, MCInstBuilder(ARM::tLDRi)
2128 .addReg(ARM::R11)
2129 .addReg(SrcReg)
2130 .addImm(0)
2131 // Predicate.
2132 .addImm(ARMCC::AL)
2133 .addReg(0));
2136 EmitToStreamer(*OutStreamer, MCInstBuilder(ARM::tBX)
2137 .addReg(ScratchReg)
2138 // Predicate.
2139 .addImm(ARMCC::AL)
2140 .addReg(0));
2141 return;
2143 case ARM::tInt_WIN_eh_sjlj_longjmp: {
2144 // ldr.w r11, [$src, #0]
2145 // ldr.w sp, [$src, #8]
2146 // ldr.w pc, [$src, #4]
2148 Register SrcReg = MI->getOperand(0).getReg();
2150 EmitToStreamer(*OutStreamer, MCInstBuilder(ARM::t2LDRi12)
2151 .addReg(ARM::R11)
2152 .addReg(SrcReg)
2153 .addImm(0)
2154 // Predicate
2155 .addImm(ARMCC::AL)
2156 .addReg(0));
2157 EmitToStreamer(*OutStreamer, MCInstBuilder(ARM::t2LDRi12)
2158 .addReg(ARM::SP)
2159 .addReg(SrcReg)
2160 .addImm(8)
2161 // Predicate
2162 .addImm(ARMCC::AL)
2163 .addReg(0));
2164 EmitToStreamer(*OutStreamer, MCInstBuilder(ARM::t2LDRi12)
2165 .addReg(ARM::PC)
2166 .addReg(SrcReg)
2167 .addImm(4)
2168 // Predicate
2169 .addImm(ARMCC::AL)
2170 .addReg(0));
2171 return;
2173 case ARM::PATCHABLE_FUNCTION_ENTER:
2174 LowerPATCHABLE_FUNCTION_ENTER(*MI);
2175 return;
2176 case ARM::PATCHABLE_FUNCTION_EXIT:
2177 LowerPATCHABLE_FUNCTION_EXIT(*MI);
2178 return;
2179 case ARM::PATCHABLE_TAIL_CALL:
2180 LowerPATCHABLE_TAIL_CALL(*MI);
2181 return;
2182 case ARM::SpeculationBarrierISBDSBEndBB: {
2183 // Print DSB SYS + ISB
2184 MCInst TmpInstDSB;
2185 TmpInstDSB.setOpcode(ARM::DSB);
2186 TmpInstDSB.addOperand(MCOperand::createImm(0xf));
2187 EmitToStreamer(*OutStreamer, TmpInstDSB);
2188 MCInst TmpInstISB;
2189 TmpInstISB.setOpcode(ARM::ISB);
2190 TmpInstISB.addOperand(MCOperand::createImm(0xf));
2191 EmitToStreamer(*OutStreamer, TmpInstISB);
2192 return;
2194 case ARM::t2SpeculationBarrierISBDSBEndBB: {
2195 // Print DSB SYS + ISB
2196 MCInst TmpInstDSB;
2197 TmpInstDSB.setOpcode(ARM::t2DSB);
2198 TmpInstDSB.addOperand(MCOperand::createImm(0xf));
2199 TmpInstDSB.addOperand(MCOperand::createImm(ARMCC::AL));
2200 TmpInstDSB.addOperand(MCOperand::createReg(0));
2201 EmitToStreamer(*OutStreamer, TmpInstDSB);
2202 MCInst TmpInstISB;
2203 TmpInstISB.setOpcode(ARM::t2ISB);
2204 TmpInstISB.addOperand(MCOperand::createImm(0xf));
2205 TmpInstISB.addOperand(MCOperand::createImm(ARMCC::AL));
2206 TmpInstISB.addOperand(MCOperand::createReg(0));
2207 EmitToStreamer(*OutStreamer, TmpInstISB);
2208 return;
2210 case ARM::SpeculationBarrierSBEndBB: {
2211 // Print SB
2212 MCInst TmpInstSB;
2213 TmpInstSB.setOpcode(ARM::SB);
2214 EmitToStreamer(*OutStreamer, TmpInstSB);
2215 return;
2217 case ARM::t2SpeculationBarrierSBEndBB: {
2218 // Print SB
2219 MCInst TmpInstSB;
2220 TmpInstSB.setOpcode(ARM::t2SB);
2221 EmitToStreamer(*OutStreamer, TmpInstSB);
2222 return;
2226 MCInst TmpInst;
2227 LowerARMMachineInstrToMCInst(MI, TmpInst, *this);
2229 EmitToStreamer(*OutStreamer, TmpInst);
2232 //===----------------------------------------------------------------------===//
2233 // Target Registry Stuff
2234 //===----------------------------------------------------------------------===//
2236 // Force static initialization.
2237 extern "C" LLVM_EXTERNAL_VISIBILITY void LLVMInitializeARMAsmPrinter() {
2238 RegisterAsmPrinter<ARMAsmPrinter> X(getTheARMLETarget());
2239 RegisterAsmPrinter<ARMAsmPrinter> Y(getTheARMBETarget());
2240 RegisterAsmPrinter<ARMAsmPrinter> A(getTheThumbLETarget());
2241 RegisterAsmPrinter<ARMAsmPrinter> B(getTheThumbBETarget());