1 //===-- ARMAsmPrinter.cpp - Print machine code to an ARM .s file ----------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file contains a printer that converts from our internal representation
11 // of machine-dependent LLVM code to GAS-format ARM assembly language.
13 //===----------------------------------------------------------------------===//
15 #include "ARMAsmPrinter.h"
17 #include "ARMConstantPoolValue.h"
18 #include "ARMFPUName.h"
19 #include "ARMMachineFunctionInfo.h"
20 #include "ARMTargetMachine.h"
21 #include "ARMTargetObjectFile.h"
22 #include "InstPrinter/ARMInstPrinter.h"
23 #include "MCTargetDesc/ARMAddressingModes.h"
24 #include "MCTargetDesc/ARMMCExpr.h"
25 #include "llvm/ADT/SetVector.h"
26 #include "llvm/ADT/SmallString.h"
27 #include "llvm/CodeGen/MachineFunctionPass.h"
28 #include "llvm/CodeGen/MachineJumpTableInfo.h"
29 #include "llvm/CodeGen/MachineModuleInfoImpls.h"
30 #include "llvm/IR/Constants.h"
31 #include "llvm/IR/DataLayout.h"
32 #include "llvm/IR/DebugInfo.h"
33 #include "llvm/IR/Mangler.h"
34 #include "llvm/IR/Module.h"
35 #include "llvm/IR/Type.h"
36 #include "llvm/MC/MCAsmInfo.h"
37 #include "llvm/MC/MCAssembler.h"
38 #include "llvm/MC/MCContext.h"
39 #include "llvm/MC/MCELFStreamer.h"
40 #include "llvm/MC/MCInst.h"
41 #include "llvm/MC/MCInstBuilder.h"
42 #include "llvm/MC/MCObjectStreamer.h"
43 #include "llvm/MC/MCSectionMachO.h"
44 #include "llvm/MC/MCStreamer.h"
45 #include "llvm/MC/MCSymbol.h"
46 #include "llvm/Support/ARMBuildAttributes.h"
47 #include "llvm/Support/COFF.h"
48 #include "llvm/Support/CommandLine.h"
49 #include "llvm/Support/Debug.h"
50 #include "llvm/Support/ELF.h"
51 #include "llvm/Support/ErrorHandling.h"
52 #include "llvm/Support/TargetRegistry.h"
53 #include "llvm/Support/raw_ostream.h"
54 #include "llvm/Target/TargetMachine.h"
58 #define DEBUG_TYPE "asm-printer"
60 void ARMAsmPrinter::EmitFunctionBodyEnd() {
61 // Make sure to terminate any constant pools that were at the end
65 InConstantPool = false;
66 OutStreamer.EmitDataRegion(MCDR_DataRegionEnd);
69 void ARMAsmPrinter::EmitFunctionEntryLabel() {
70 if (AFI->isThumbFunction()) {
71 OutStreamer.EmitAssemblerFlag(MCAF_Code16);
72 OutStreamer.EmitThumbFunc(CurrentFnSym);
75 OutStreamer.EmitLabel(CurrentFnSym);
78 void ARMAsmPrinter::EmitXXStructor(const Constant *CV) {
80 TM.getSubtargetImpl()->getDataLayout()->getTypeAllocSize(CV->getType());
81 assert(Size && "C++ constructor pointer had zero size!");
83 const GlobalValue *GV = dyn_cast<GlobalValue>(CV->stripPointerCasts());
84 assert(GV && "C++ constructor pointer was not a GlobalValue!");
86 const MCExpr *E = MCSymbolRefExpr::Create(GetARMGVSymbol(GV,
88 (Subtarget->isTargetELF()
89 ? MCSymbolRefExpr::VK_ARM_TARGET1
90 : MCSymbolRefExpr::VK_None),
93 OutStreamer.EmitValue(E, Size);
96 /// runOnMachineFunction - This uses the EmitInstruction()
97 /// method to print assembly for each instruction.
99 bool ARMAsmPrinter::runOnMachineFunction(MachineFunction &MF) {
100 AFI = MF.getInfo<ARMFunctionInfo>();
101 MCP = MF.getConstantPool();
103 SetupMachineFunction(MF);
105 if (Subtarget->isTargetCOFF()) {
106 bool Internal = MF.getFunction()->hasInternalLinkage();
107 COFF::SymbolStorageClass Scl = Internal ? COFF::IMAGE_SYM_CLASS_STATIC
108 : COFF::IMAGE_SYM_CLASS_EXTERNAL;
109 int Type = COFF::IMAGE_SYM_DTYPE_FUNCTION << COFF::SCT_COMPLEX_TYPE_SHIFT;
111 OutStreamer.BeginCOFFSymbolDef(CurrentFnSym);
112 OutStreamer.EmitCOFFSymbolStorageClass(Scl);
113 OutStreamer.EmitCOFFSymbolType(Type);
114 OutStreamer.EndCOFFSymbolDef();
117 // Have common code print out the function header with linkage info etc.
118 EmitFunctionHeader();
120 // Emit the rest of the function body.
123 // We didn't modify anything.
127 void ARMAsmPrinter::printOperand(const MachineInstr *MI, int OpNum,
128 raw_ostream &O, const char *Modifier) {
129 const MachineOperand &MO = MI->getOperand(OpNum);
130 unsigned TF = MO.getTargetFlags();
132 switch (MO.getType()) {
133 default: llvm_unreachable("<unknown operand type>");
134 case MachineOperand::MO_Register: {
135 unsigned Reg = MO.getReg();
136 assert(TargetRegisterInfo::isPhysicalRegister(Reg));
137 assert(!MO.getSubReg() && "Subregs should be eliminated!");
138 if(ARM::GPRPairRegClass.contains(Reg)) {
139 const MachineFunction &MF = *MI->getParent()->getParent();
140 const TargetRegisterInfo *TRI = MF.getSubtarget().getRegisterInfo();
141 Reg = TRI->getSubReg(Reg, ARM::gsub_0);
143 O << ARMInstPrinter::getRegisterName(Reg);
146 case MachineOperand::MO_Immediate: {
147 int64_t Imm = MO.getImm();
149 if ((Modifier && strcmp(Modifier, "lo16") == 0) ||
150 (TF == ARMII::MO_LO16))
152 else if ((Modifier && strcmp(Modifier, "hi16") == 0) ||
153 (TF == ARMII::MO_HI16))
158 case MachineOperand::MO_MachineBasicBlock:
159 O << *MO.getMBB()->getSymbol();
161 case MachineOperand::MO_GlobalAddress: {
162 const GlobalValue *GV = MO.getGlobal();
163 if ((Modifier && strcmp(Modifier, "lo16") == 0) ||
164 (TF & ARMII::MO_LO16))
166 else if ((Modifier && strcmp(Modifier, "hi16") == 0) ||
167 (TF & ARMII::MO_HI16))
169 O << *GetARMGVSymbol(GV, TF);
171 printOffset(MO.getOffset(), O);
172 if (TF == ARMII::MO_PLT)
176 case MachineOperand::MO_ConstantPoolIndex:
177 O << *GetCPISymbol(MO.getIndex());
182 //===--------------------------------------------------------------------===//
184 MCSymbol *ARMAsmPrinter::
185 GetARMJTIPICJumpTableLabel2(unsigned uid, unsigned uid2) const {
186 const DataLayout *DL = TM.getSubtargetImpl()->getDataLayout();
187 SmallString<60> Name;
188 raw_svector_ostream(Name) << DL->getPrivateGlobalPrefix() << "JTI"
189 << getFunctionNumber() << '_' << uid << '_' << uid2;
190 return OutContext.GetOrCreateSymbol(Name.str());
194 MCSymbol *ARMAsmPrinter::GetARMSJLJEHLabel() const {
195 const DataLayout *DL = TM.getSubtargetImpl()->getDataLayout();
196 SmallString<60> Name;
197 raw_svector_ostream(Name) << DL->getPrivateGlobalPrefix() << "SJLJEH"
198 << getFunctionNumber();
199 return OutContext.GetOrCreateSymbol(Name.str());
202 bool ARMAsmPrinter::PrintAsmOperand(const MachineInstr *MI, unsigned OpNum,
203 unsigned AsmVariant, const char *ExtraCode,
205 // Does this asm operand have a single letter operand modifier?
206 if (ExtraCode && ExtraCode[0]) {
207 if (ExtraCode[1] != 0) return true; // Unknown modifier.
209 switch (ExtraCode[0]) {
211 // See if this is a generic print operand
212 return AsmPrinter::PrintAsmOperand(MI, OpNum, AsmVariant, ExtraCode, O);
213 case 'a': // Print as a memory address.
214 if (MI->getOperand(OpNum).isReg()) {
216 << ARMInstPrinter::getRegisterName(MI->getOperand(OpNum).getReg())
221 case 'c': // Don't print "#" before an immediate operand.
222 if (!MI->getOperand(OpNum).isImm())
224 O << MI->getOperand(OpNum).getImm();
226 case 'P': // Print a VFP double precision register.
227 case 'q': // Print a NEON quad precision register.
228 printOperand(MI, OpNum, O);
230 case 'y': // Print a VFP single precision register as indexed double.
231 if (MI->getOperand(OpNum).isReg()) {
232 unsigned Reg = MI->getOperand(OpNum).getReg();
233 const TargetRegisterInfo *TRI = MF->getSubtarget().getRegisterInfo();
234 // Find the 'd' register that has this 's' register as a sub-register,
235 // and determine the lane number.
236 for (MCSuperRegIterator SR(Reg, TRI); SR.isValid(); ++SR) {
237 if (!ARM::DPRRegClass.contains(*SR))
239 bool Lane0 = TRI->getSubReg(*SR, ARM::ssub_0) == Reg;
240 O << ARMInstPrinter::getRegisterName(*SR) << (Lane0 ? "[0]" : "[1]");
245 case 'B': // Bitwise inverse of integer or symbol without a preceding #.
246 if (!MI->getOperand(OpNum).isImm())
248 O << ~(MI->getOperand(OpNum).getImm());
250 case 'L': // The low 16 bits of an immediate constant.
251 if (!MI->getOperand(OpNum).isImm())
253 O << (MI->getOperand(OpNum).getImm() & 0xffff);
255 case 'M': { // A register range suitable for LDM/STM.
256 if (!MI->getOperand(OpNum).isReg())
258 const MachineOperand &MO = MI->getOperand(OpNum);
259 unsigned RegBegin = MO.getReg();
260 // This takes advantage of the 2 operand-ness of ldm/stm and that we've
261 // already got the operands in registers that are operands to the
262 // inline asm statement.
264 if (ARM::GPRPairRegClass.contains(RegBegin)) {
265 const TargetRegisterInfo *TRI = MF->getSubtarget().getRegisterInfo();
266 unsigned Reg0 = TRI->getSubReg(RegBegin, ARM::gsub_0);
267 O << ARMInstPrinter::getRegisterName(Reg0) << ", ";
268 RegBegin = TRI->getSubReg(RegBegin, ARM::gsub_1);
270 O << ARMInstPrinter::getRegisterName(RegBegin);
272 // FIXME: The register allocator not only may not have given us the
273 // registers in sequence, but may not be in ascending registers. This
274 // will require changes in the register allocator that'll need to be
275 // propagated down here if the operands change.
276 unsigned RegOps = OpNum + 1;
277 while (MI->getOperand(RegOps).isReg()) {
279 << ARMInstPrinter::getRegisterName(MI->getOperand(RegOps).getReg());
287 case 'R': // The most significant register of a pair.
288 case 'Q': { // The least significant register of a pair.
291 const MachineOperand &FlagsOP = MI->getOperand(OpNum - 1);
292 if (!FlagsOP.isImm())
294 unsigned Flags = FlagsOP.getImm();
296 // This operand may not be the one that actually provides the register. If
297 // it's tied to a previous one then we should refer instead to that one
298 // for registers and their classes.
300 if (InlineAsm::isUseOperandTiedToDef(Flags, TiedIdx)) {
301 for (OpNum = InlineAsm::MIOp_FirstOperand; TiedIdx; --TiedIdx) {
302 unsigned OpFlags = MI->getOperand(OpNum).getImm();
303 OpNum += InlineAsm::getNumOperandRegisters(OpFlags) + 1;
305 Flags = MI->getOperand(OpNum).getImm();
307 // Later code expects OpNum to be pointing at the register rather than
312 unsigned NumVals = InlineAsm::getNumOperandRegisters(Flags);
314 InlineAsm::hasRegClassConstraint(Flags, RC);
315 if (RC == ARM::GPRPairRegClassID) {
318 const MachineOperand &MO = MI->getOperand(OpNum);
321 const TargetRegisterInfo *TRI = MF->getSubtarget().getRegisterInfo();
322 unsigned Reg = TRI->getSubReg(MO.getReg(), ExtraCode[0] == 'Q' ?
323 ARM::gsub_0 : ARM::gsub_1);
324 O << ARMInstPrinter::getRegisterName(Reg);
329 unsigned RegOp = ExtraCode[0] == 'Q' ? OpNum : OpNum + 1;
330 if (RegOp >= MI->getNumOperands())
332 const MachineOperand &MO = MI->getOperand(RegOp);
335 unsigned Reg = MO.getReg();
336 O << ARMInstPrinter::getRegisterName(Reg);
340 case 'e': // The low doubleword register of a NEON quad register.
341 case 'f': { // The high doubleword register of a NEON quad register.
342 if (!MI->getOperand(OpNum).isReg())
344 unsigned Reg = MI->getOperand(OpNum).getReg();
345 if (!ARM::QPRRegClass.contains(Reg))
347 const TargetRegisterInfo *TRI = MF->getSubtarget().getRegisterInfo();
348 unsigned SubReg = TRI->getSubReg(Reg, ExtraCode[0] == 'e' ?
349 ARM::dsub_0 : ARM::dsub_1);
350 O << ARMInstPrinter::getRegisterName(SubReg);
354 // This modifier is not yet supported.
355 case 'h': // A range of VFP/NEON registers suitable for VLD1/VST1.
357 case 'H': { // The highest-numbered register of a pair.
358 const MachineOperand &MO = MI->getOperand(OpNum);
361 const MachineFunction &MF = *MI->getParent()->getParent();
362 const TargetRegisterInfo *TRI = MF.getSubtarget().getRegisterInfo();
363 unsigned Reg = MO.getReg();
364 if(!ARM::GPRPairRegClass.contains(Reg))
366 Reg = TRI->getSubReg(Reg, ARM::gsub_1);
367 O << ARMInstPrinter::getRegisterName(Reg);
373 printOperand(MI, OpNum, O);
377 bool ARMAsmPrinter::PrintAsmMemoryOperand(const MachineInstr *MI,
378 unsigned OpNum, unsigned AsmVariant,
379 const char *ExtraCode,
381 // Does this asm operand have a single letter operand modifier?
382 if (ExtraCode && ExtraCode[0]) {
383 if (ExtraCode[1] != 0) return true; // Unknown modifier.
385 switch (ExtraCode[0]) {
386 case 'A': // A memory operand for a VLD1/VST1 instruction.
387 default: return true; // Unknown modifier.
388 case 'm': // The base register of a memory operand.
389 if (!MI->getOperand(OpNum).isReg())
391 O << ARMInstPrinter::getRegisterName(MI->getOperand(OpNum).getReg());
396 const MachineOperand &MO = MI->getOperand(OpNum);
397 assert(MO.isReg() && "unexpected inline asm memory operand");
398 O << "[" << ARMInstPrinter::getRegisterName(MO.getReg()) << "]";
402 static bool isThumb(const MCSubtargetInfo& STI) {
403 return (STI.getFeatureBits() & ARM::ModeThumb) != 0;
406 void ARMAsmPrinter::emitInlineAsmEnd(const MCSubtargetInfo &StartInfo,
407 const MCSubtargetInfo *EndInfo) const {
408 // If either end mode is unknown (EndInfo == NULL) or different than
409 // the start mode, then restore the start mode.
410 const bool WasThumb = isThumb(StartInfo);
411 if (!EndInfo || WasThumb != isThumb(*EndInfo)) {
412 OutStreamer.EmitAssemblerFlag(WasThumb ? MCAF_Code16 : MCAF_Code32);
416 void ARMAsmPrinter::EmitStartOfAsmFile(Module &M) {
417 if (Subtarget->isTargetMachO()) {
418 Reloc::Model RelocM = TM.getRelocationModel();
419 if (RelocM == Reloc::PIC_ || RelocM == Reloc::DynamicNoPIC) {
420 // Declare all the text sections up front (before the DWARF sections
421 // emitted by AsmPrinter::doInitialization) so the assembler will keep
422 // them together at the beginning of the object file. This helps
423 // avoid out-of-range branches that are due a fundamental limitation of
424 // the way symbol offsets are encoded with the current Darwin ARM
426 const TargetLoweringObjectFileMachO &TLOFMacho =
427 static_cast<const TargetLoweringObjectFileMachO &>(
428 getObjFileLowering());
430 // Collect the set of sections our functions will go into.
431 SetVector<const MCSection *, SmallVector<const MCSection *, 8>,
432 SmallPtrSet<const MCSection *, 8> > TextSections;
433 // Default text section comes first.
434 TextSections.insert(TLOFMacho.getTextSection());
435 // Now any user defined text sections from function attributes.
436 for (Module::iterator F = M.begin(), e = M.end(); F != e; ++F)
437 if (!F->isDeclaration() && !F->hasAvailableExternallyLinkage())
438 TextSections.insert(TLOFMacho.SectionForGlobal(F, *Mang, TM));
439 // Now the coalescable sections.
440 TextSections.insert(TLOFMacho.getTextCoalSection());
441 TextSections.insert(TLOFMacho.getConstTextCoalSection());
443 // Emit the sections in the .s file header to fix the order.
444 for (unsigned i = 0, e = TextSections.size(); i != e; ++i)
445 OutStreamer.SwitchSection(TextSections[i]);
447 if (RelocM == Reloc::DynamicNoPIC) {
448 const MCSection *sect =
449 OutContext.getMachOSection("__TEXT", "__symbol_stub4",
450 MachO::S_SYMBOL_STUBS,
451 12, SectionKind::getText());
452 OutStreamer.SwitchSection(sect);
454 const MCSection *sect =
455 OutContext.getMachOSection("__TEXT", "__picsymbolstub4",
456 MachO::S_SYMBOL_STUBS,
457 16, SectionKind::getText());
458 OutStreamer.SwitchSection(sect);
460 const MCSection *StaticInitSect =
461 OutContext.getMachOSection("__TEXT", "__StaticInit",
463 MachO::S_ATTR_PURE_INSTRUCTIONS,
464 SectionKind::getText());
465 OutStreamer.SwitchSection(StaticInitSect);
468 // Compiling with debug info should not affect the code
469 // generation. Ensure the cstring section comes before the
470 // optional __DWARF secion. Otherwise, PC-relative loads would
471 // have to use different instruction sequences at "-g" in order to
472 // reach global data in the same object file.
473 OutStreamer.SwitchSection(getObjFileLowering().getCStringSection());
476 // Use unified assembler syntax.
477 OutStreamer.EmitAssemblerFlag(MCAF_SyntaxUnified);
479 // Emit ARM Build Attributes
480 if (Subtarget->isTargetELF())
483 if (!M.getModuleInlineAsm().empty() && Subtarget->isThumb())
484 OutStreamer.EmitAssemblerFlag(MCAF_Code16);
488 emitNonLazySymbolPointer(MCStreamer &OutStreamer, MCSymbol *StubLabel,
489 MachineModuleInfoImpl::StubValueTy &MCSym) {
491 OutStreamer.EmitLabel(StubLabel);
492 // .indirect_symbol _foo
493 OutStreamer.EmitSymbolAttribute(MCSym.getPointer(), MCSA_IndirectSymbol);
496 // External to current translation unit.
497 OutStreamer.EmitIntValue(0, 4/*size*/);
499 // Internal to current translation unit.
501 // When we place the LSDA into the TEXT section, the type info
502 // pointers need to be indirect and pc-rel. We accomplish this by
503 // using NLPs; however, sometimes the types are local to the file.
504 // We need to fill in the value for the NLP in those cases.
505 OutStreamer.EmitValue(
506 MCSymbolRefExpr::Create(MCSym.getPointer(), OutStreamer.getContext()),
511 void ARMAsmPrinter::EmitEndOfAsmFile(Module &M) {
512 if (Subtarget->isTargetMachO()) {
513 // All darwin targets use mach-o.
514 const TargetLoweringObjectFileMachO &TLOFMacho =
515 static_cast<const TargetLoweringObjectFileMachO &>(getObjFileLowering());
516 MachineModuleInfoMachO &MMIMacho =
517 MMI->getObjFileInfo<MachineModuleInfoMachO>();
519 // Output non-lazy-pointers for external and common global variables.
520 MachineModuleInfoMachO::SymbolListTy Stubs = MMIMacho.GetGVStubList();
522 if (!Stubs.empty()) {
523 // Switch with ".non_lazy_symbol_pointer" directive.
524 OutStreamer.SwitchSection(TLOFMacho.getNonLazySymbolPointerSection());
527 for (auto &Stub : Stubs)
528 emitNonLazySymbolPointer(OutStreamer, Stub.first, Stub.second);
531 OutStreamer.AddBlankLine();
534 Stubs = MMIMacho.GetHiddenGVStubList();
535 if (!Stubs.empty()) {
536 OutStreamer.SwitchSection(TLOFMacho.getNonLazySymbolPointerSection());
539 for (auto &Stub : Stubs)
540 emitNonLazySymbolPointer(OutStreamer, Stub.first, Stub.second);
543 OutStreamer.AddBlankLine();
546 // Funny Darwin hack: This flag tells the linker that no global symbols
547 // contain code that falls through to other global symbols (e.g. the obvious
548 // implementation of multiple entry points). If this doesn't occur, the
549 // linker can safely perform dead code stripping. Since LLVM never
550 // generates code that does this, it is always safe to set.
551 OutStreamer.EmitAssemblerFlag(MCAF_SubsectionsViaSymbols);
554 // Emit a .data.rel section containing any stubs that were created.
555 if (Subtarget->isTargetELF()) {
556 const TargetLoweringObjectFileELF &TLOFELF =
557 static_cast<const TargetLoweringObjectFileELF &>(getObjFileLowering());
559 MachineModuleInfoELF &MMIELF = MMI->getObjFileInfo<MachineModuleInfoELF>();
561 // Output stubs for external and common global variables.
562 MachineModuleInfoELF::SymbolListTy Stubs = MMIELF.GetGVStubList();
563 if (!Stubs.empty()) {
564 OutStreamer.SwitchSection(TLOFELF.getDataRelSection());
565 const DataLayout *TD = TM.getSubtargetImpl()->getDataLayout();
567 for (auto &stub: Stubs) {
568 OutStreamer.EmitLabel(stub.first);
569 OutStreamer.EmitSymbolValue(stub.second.getPointer(),
570 TD->getPointerSize(0));
577 //===----------------------------------------------------------------------===//
578 // Helper routines for EmitStartOfAsmFile() and EmitEndOfAsmFile()
580 // The following seem like one-off assembler flags, but they actually need
581 // to appear in the .ARM.attributes section in ELF.
582 // Instead of subclassing the MCELFStreamer, we do the work here.
584 static ARMBuildAttrs::CPUArch getArchForCPU(StringRef CPU,
585 const ARMSubtarget *Subtarget) {
587 return ARMBuildAttrs::v5TEJ;
589 if (Subtarget->hasV8Ops())
590 return ARMBuildAttrs::v8;
591 else if (Subtarget->hasV7Ops()) {
592 if (Subtarget->isMClass() && Subtarget->hasThumb2DSP())
593 return ARMBuildAttrs::v7E_M;
594 return ARMBuildAttrs::v7;
595 } else if (Subtarget->hasV6T2Ops())
596 return ARMBuildAttrs::v6T2;
597 else if (Subtarget->hasV6MOps())
598 return ARMBuildAttrs::v6S_M;
599 else if (Subtarget->hasV6Ops())
600 return ARMBuildAttrs::v6;
601 else if (Subtarget->hasV5TEOps())
602 return ARMBuildAttrs::v5TE;
603 else if (Subtarget->hasV5TOps())
604 return ARMBuildAttrs::v5T;
605 else if (Subtarget->hasV4TOps())
606 return ARMBuildAttrs::v4T;
608 return ARMBuildAttrs::v4;
611 void ARMAsmPrinter::emitAttributes() {
612 MCTargetStreamer &TS = *OutStreamer.getTargetStreamer();
613 ARMTargetStreamer &ATS = static_cast<ARMTargetStreamer &>(TS);
615 ATS.switchVendor("aeabi");
617 std::string CPUString = Subtarget->getCPUString();
619 // FIXME: remove krait check when GNU tools support krait cpu
620 if (CPUString != "generic" && CPUString != "krait")
621 ATS.emitTextAttribute(ARMBuildAttrs::CPU_name, CPUString);
623 ATS.emitAttribute(ARMBuildAttrs::CPU_arch,
624 getArchForCPU(CPUString, Subtarget));
626 // Tag_CPU_arch_profile must have the default value of 0 when "Architecture
627 // profile is not applicable (e.g. pre v7, or cross-profile code)".
628 if (Subtarget->hasV7Ops()) {
629 if (Subtarget->isAClass()) {
630 ATS.emitAttribute(ARMBuildAttrs::CPU_arch_profile,
631 ARMBuildAttrs::ApplicationProfile);
632 } else if (Subtarget->isRClass()) {
633 ATS.emitAttribute(ARMBuildAttrs::CPU_arch_profile,
634 ARMBuildAttrs::RealTimeProfile);
635 } else if (Subtarget->isMClass()) {
636 ATS.emitAttribute(ARMBuildAttrs::CPU_arch_profile,
637 ARMBuildAttrs::MicroControllerProfile);
641 ATS.emitAttribute(ARMBuildAttrs::ARM_ISA_use, Subtarget->hasARMOps() ?
642 ARMBuildAttrs::Allowed : ARMBuildAttrs::Not_Allowed);
643 if (Subtarget->isThumb1Only()) {
644 ATS.emitAttribute(ARMBuildAttrs::THUMB_ISA_use,
645 ARMBuildAttrs::Allowed);
646 } else if (Subtarget->hasThumb2()) {
647 ATS.emitAttribute(ARMBuildAttrs::THUMB_ISA_use,
648 ARMBuildAttrs::AllowThumb32);
651 if (Subtarget->hasNEON()) {
652 /* NEON is not exactly a VFP architecture, but GAS emit one of
653 * neon/neon-fp-armv8/neon-vfpv4/vfpv3/vfpv2 for .fpu parameters */
654 if (Subtarget->hasFPARMv8()) {
655 if (Subtarget->hasCrypto())
656 ATS.emitFPU(ARM::CRYPTO_NEON_FP_ARMV8);
658 ATS.emitFPU(ARM::NEON_FP_ARMV8);
660 else if (Subtarget->hasVFP4())
661 ATS.emitFPU(ARM::NEON_VFPV4);
663 ATS.emitFPU(ARM::NEON);
664 // Emit Tag_Advanced_SIMD_arch for ARMv8 architecture
665 if (Subtarget->hasV8Ops())
666 ATS.emitAttribute(ARMBuildAttrs::Advanced_SIMD_arch,
667 ARMBuildAttrs::AllowNeonARMv8);
669 if (Subtarget->hasFPARMv8())
670 // FPv5 and FP-ARMv8 have the same instructions, so are modeled as one
671 // FPU, but there are two different names for it depending on the CPU.
672 ATS.emitFPU(Subtarget->hasD16() ? ARM::FPV5_D16 : ARM::FP_ARMV8);
673 else if (Subtarget->hasVFP4())
674 ATS.emitFPU(Subtarget->hasD16() ? ARM::VFPV4_D16 : ARM::VFPV4);
675 else if (Subtarget->hasVFP3())
676 ATS.emitFPU(Subtarget->hasD16() ? ARM::VFPV3_D16 : ARM::VFPV3);
677 else if (Subtarget->hasVFP2())
678 ATS.emitFPU(ARM::VFPV2);
681 if (TM.getRelocationModel() == Reloc::PIC_) {
682 // PIC specific attributes.
683 ATS.emitAttribute(ARMBuildAttrs::ABI_PCS_RW_data,
684 ARMBuildAttrs::AddressRWPCRel);
685 ATS.emitAttribute(ARMBuildAttrs::ABI_PCS_RO_data,
686 ARMBuildAttrs::AddressROPCRel);
687 ATS.emitAttribute(ARMBuildAttrs::ABI_PCS_GOT_use,
688 ARMBuildAttrs::AddressGOT);
690 // Allow direct addressing of imported data for all other relocation models.
691 ATS.emitAttribute(ARMBuildAttrs::ABI_PCS_GOT_use,
692 ARMBuildAttrs::AddressDirect);
695 // Signal various FP modes.
696 if (!TM.Options.UnsafeFPMath) {
697 ATS.emitAttribute(ARMBuildAttrs::ABI_FP_denormal,
698 ARMBuildAttrs::IEEEDenormals);
699 ATS.emitAttribute(ARMBuildAttrs::ABI_FP_exceptions,
700 ARMBuildAttrs::Allowed);
702 if (!Subtarget->hasVFP2()) {
703 // When the target doesn't have an FPU (by design or
704 // intention), the assumptions made on the software support
705 // mirror that of the equivalent hardware support *if it
706 // existed*. For v7 and better we indicate that denormals are
707 // flushed preserving sign, and for V6 we indicate that
708 // denormals are flushed to positive zero.
709 if (Subtarget->hasV7Ops())
710 ATS.emitAttribute(ARMBuildAttrs::ABI_FP_denormal,
711 ARMBuildAttrs::PreserveFPSign);
712 } else if (Subtarget->hasVFP3()) {
713 // In VFPv4, VFPv4U, VFPv3, or VFPv3U, it is preserved. That is,
714 // the sign bit of the zero matches the sign bit of the input or
715 // result that is being flushed to zero.
716 ATS.emitAttribute(ARMBuildAttrs::ABI_FP_denormal,
717 ARMBuildAttrs::PreserveFPSign);
719 // For VFPv2 implementations it is implementation defined as
720 // to whether denormals are flushed to positive zero or to
721 // whatever the sign of zero is (ARM v7AR ARM 2.7.5). Historically
722 // LLVM has chosen to flush this to positive zero (most likely for
723 // GCC compatibility), so that's the chosen value here (the
724 // absence of its emission implies zero).
727 if (TM.Options.NoInfsFPMath && TM.Options.NoNaNsFPMath)
728 ATS.emitAttribute(ARMBuildAttrs::ABI_FP_number_model,
729 ARMBuildAttrs::Allowed);
731 ATS.emitAttribute(ARMBuildAttrs::ABI_FP_number_model,
732 ARMBuildAttrs::AllowIEE754);
734 if (Subtarget->allowsUnalignedMem())
735 ATS.emitAttribute(ARMBuildAttrs::CPU_unaligned_access,
736 ARMBuildAttrs::Allowed);
738 ATS.emitAttribute(ARMBuildAttrs::CPU_unaligned_access,
739 ARMBuildAttrs::Not_Allowed);
741 // FIXME: add more flags to ARMBuildAttributes.h
742 // 8-bytes alignment stuff.
743 ATS.emitAttribute(ARMBuildAttrs::ABI_align_needed, 1);
744 ATS.emitAttribute(ARMBuildAttrs::ABI_align_preserved, 1);
746 // ABI_HardFP_use attribute to indicate single precision FP.
747 if (Subtarget->isFPOnlySP())
748 ATS.emitAttribute(ARMBuildAttrs::ABI_HardFP_use,
749 ARMBuildAttrs::HardFPSinglePrecision);
751 // Hard float. Use both S and D registers and conform to AAPCS-VFP.
752 if (Subtarget->isAAPCS_ABI() && TM.Options.FloatABIType == FloatABI::Hard)
753 ATS.emitAttribute(ARMBuildAttrs::ABI_VFP_args, ARMBuildAttrs::HardFPAAPCS);
755 // FIXME: Should we signal R9 usage?
757 if (Subtarget->hasFP16())
758 ATS.emitAttribute(ARMBuildAttrs::FP_HP_extension, ARMBuildAttrs::AllowHPFP);
760 if (Subtarget->hasMPExtension())
761 ATS.emitAttribute(ARMBuildAttrs::MPextension_use, ARMBuildAttrs::AllowMP);
763 // Hardware divide in ARM mode is part of base arch, starting from ARMv8.
764 // If only Thumb hwdiv is present, it must also be in base arch (ARMv7-R/M).
765 // It is not possible to produce DisallowDIV: if hwdiv is present in the base
766 // arch, supplying -hwdiv downgrades the effective arch, via ClearImpliedBits.
767 // AllowDIVExt is only emitted if hwdiv isn't available in the base arch;
768 // otherwise, the default value (AllowDIVIfExists) applies.
769 if (Subtarget->hasDivideInARMMode() && !Subtarget->hasV8Ops())
770 ATS.emitAttribute(ARMBuildAttrs::DIV_use, ARMBuildAttrs::AllowDIVExt);
773 if (const Module *SourceModule = MMI->getModule()) {
774 // ABI_PCS_wchar_t to indicate wchar_t width
775 // FIXME: There is no way to emit value 0 (wchar_t prohibited).
776 if (auto WCharWidthValue = cast_or_null<ConstantInt>(
777 SourceModule->getModuleFlag("wchar_size"))) {
778 int WCharWidth = WCharWidthValue->getZExtValue();
779 assert((WCharWidth == 2 || WCharWidth == 4) &&
780 "wchar_t width must be 2 or 4 bytes");
781 ATS.emitAttribute(ARMBuildAttrs::ABI_PCS_wchar_t, WCharWidth);
784 // ABI_enum_size to indicate enum width
785 // FIXME: There is no way to emit value 0 (enums prohibited) or value 3
786 // (all enums contain a value needing 32 bits to encode).
787 if (auto EnumWidthValue = cast_or_null<ConstantInt>(
788 SourceModule->getModuleFlag("min_enum_size"))) {
789 int EnumWidth = EnumWidthValue->getZExtValue();
790 assert((EnumWidth == 1 || EnumWidth == 4) &&
791 "Minimum enum width must be 1 or 4 bytes");
792 int EnumBuildAttr = EnumWidth == 1 ? 1 : 2;
793 ATS.emitAttribute(ARMBuildAttrs::ABI_enum_size, EnumBuildAttr);
798 // TODO: We currently only support either reserving the register, or treating
799 // it as another callee-saved register, but not as SB or a TLS pointer; It
800 // would instead be nicer to push this from the frontend as metadata, as we do
801 // for the wchar and enum size tags
802 if (Subtarget->isR9Reserved())
803 ATS.emitAttribute(ARMBuildAttrs::ABI_PCS_R9_use,
804 ARMBuildAttrs::R9Reserved);
806 ATS.emitAttribute(ARMBuildAttrs::ABI_PCS_R9_use,
807 ARMBuildAttrs::R9IsGPR);
809 if (Subtarget->hasTrustZone() && Subtarget->hasVirtualization())
810 ATS.emitAttribute(ARMBuildAttrs::Virtualization_use,
811 ARMBuildAttrs::AllowTZVirtualization);
812 else if (Subtarget->hasTrustZone())
813 ATS.emitAttribute(ARMBuildAttrs::Virtualization_use,
814 ARMBuildAttrs::AllowTZ);
815 else if (Subtarget->hasVirtualization())
816 ATS.emitAttribute(ARMBuildAttrs::Virtualization_use,
817 ARMBuildAttrs::AllowVirtualization);
819 ATS.finishAttributeSection();
822 //===----------------------------------------------------------------------===//
824 static MCSymbol *getPICLabel(const char *Prefix, unsigned FunctionNumber,
825 unsigned LabelId, MCContext &Ctx) {
827 MCSymbol *Label = Ctx.GetOrCreateSymbol(Twine(Prefix)
828 + "PC" + Twine(FunctionNumber) + "_" + Twine(LabelId));
832 static MCSymbolRefExpr::VariantKind
833 getModifierVariantKind(ARMCP::ARMCPModifier Modifier) {
835 case ARMCP::no_modifier: return MCSymbolRefExpr::VK_None;
836 case ARMCP::TLSGD: return MCSymbolRefExpr::VK_TLSGD;
837 case ARMCP::TPOFF: return MCSymbolRefExpr::VK_TPOFF;
838 case ARMCP::GOTTPOFF: return MCSymbolRefExpr::VK_GOTTPOFF;
839 case ARMCP::GOT: return MCSymbolRefExpr::VK_GOT;
840 case ARMCP::GOTOFF: return MCSymbolRefExpr::VK_GOTOFF;
842 llvm_unreachable("Invalid ARMCPModifier!");
845 MCSymbol *ARMAsmPrinter::GetARMGVSymbol(const GlobalValue *GV,
846 unsigned char TargetFlags) {
847 if (Subtarget->isTargetMachO()) {
848 bool IsIndirect = (TargetFlags & ARMII::MO_NONLAZY) &&
849 Subtarget->GVIsIndirectSymbol(GV, TM.getRelocationModel());
852 return getSymbol(GV);
854 // FIXME: Remove this when Darwin transition to @GOT like syntax.
855 MCSymbol *MCSym = getSymbolWithGlobalValueBase(GV, "$non_lazy_ptr");
856 MachineModuleInfoMachO &MMIMachO =
857 MMI->getObjFileInfo<MachineModuleInfoMachO>();
858 MachineModuleInfoImpl::StubValueTy &StubSym =
859 GV->hasHiddenVisibility() ? MMIMachO.getHiddenGVStubEntry(MCSym)
860 : MMIMachO.getGVStubEntry(MCSym);
861 if (!StubSym.getPointer())
862 StubSym = MachineModuleInfoImpl::StubValueTy(getSymbol(GV),
863 !GV->hasInternalLinkage());
865 } else if (Subtarget->isTargetCOFF()) {
866 assert(Subtarget->isTargetWindows() &&
867 "Windows is the only supported COFF target");
869 bool IsIndirect = (TargetFlags & ARMII::MO_DLLIMPORT);
871 return getSymbol(GV);
873 SmallString<128> Name;
875 getNameWithPrefix(Name, GV);
877 return OutContext.GetOrCreateSymbol(Name);
878 } else if (Subtarget->isTargetELF()) {
879 return getSymbol(GV);
881 llvm_unreachable("unexpected target");
885 EmitMachineConstantPoolValue(MachineConstantPoolValue *MCPV) {
886 const DataLayout *DL = TM.getSubtargetImpl()->getDataLayout();
888 TM.getSubtargetImpl()->getDataLayout()->getTypeAllocSize(MCPV->getType());
890 ARMConstantPoolValue *ACPV = static_cast<ARMConstantPoolValue*>(MCPV);
893 if (ACPV->isLSDA()) {
894 SmallString<128> Str;
895 raw_svector_ostream OS(Str);
896 OS << DL->getPrivateGlobalPrefix() << "_LSDA_" << getFunctionNumber();
897 MCSym = OutContext.GetOrCreateSymbol(OS.str());
898 } else if (ACPV->isBlockAddress()) {
899 const BlockAddress *BA =
900 cast<ARMConstantPoolConstant>(ACPV)->getBlockAddress();
901 MCSym = GetBlockAddressSymbol(BA);
902 } else if (ACPV->isGlobalValue()) {
903 const GlobalValue *GV = cast<ARMConstantPoolConstant>(ACPV)->getGV();
905 // On Darwin, const-pool entries may get the "FOO$non_lazy_ptr" mangling, so
906 // flag the global as MO_NONLAZY.
907 unsigned char TF = Subtarget->isTargetMachO() ? ARMII::MO_NONLAZY : 0;
908 MCSym = GetARMGVSymbol(GV, TF);
909 } else if (ACPV->isMachineBasicBlock()) {
910 const MachineBasicBlock *MBB = cast<ARMConstantPoolMBB>(ACPV)->getMBB();
911 MCSym = MBB->getSymbol();
913 assert(ACPV->isExtSymbol() && "unrecognized constant pool value");
914 const char *Sym = cast<ARMConstantPoolSymbol>(ACPV)->getSymbol();
915 MCSym = GetExternalSymbolSymbol(Sym);
918 // Create an MCSymbol for the reference.
920 MCSymbolRefExpr::Create(MCSym, getModifierVariantKind(ACPV->getModifier()),
923 if (ACPV->getPCAdjustment()) {
924 MCSymbol *PCLabel = getPICLabel(DL->getPrivateGlobalPrefix(),
928 const MCExpr *PCRelExpr = MCSymbolRefExpr::Create(PCLabel, OutContext);
930 MCBinaryExpr::CreateAdd(PCRelExpr,
931 MCConstantExpr::Create(ACPV->getPCAdjustment(),
934 if (ACPV->mustAddCurrentAddress()) {
935 // We want "(<expr> - .)", but MC doesn't have a concept of the '.'
936 // label, so just emit a local label end reference that instead.
937 MCSymbol *DotSym = OutContext.CreateTempSymbol();
938 OutStreamer.EmitLabel(DotSym);
939 const MCExpr *DotExpr = MCSymbolRefExpr::Create(DotSym, OutContext);
940 PCRelExpr = MCBinaryExpr::CreateSub(PCRelExpr, DotExpr, OutContext);
942 Expr = MCBinaryExpr::CreateSub(Expr, PCRelExpr, OutContext);
944 OutStreamer.EmitValue(Expr, Size);
947 void ARMAsmPrinter::EmitJumpTable(const MachineInstr *MI) {
948 unsigned Opcode = MI->getOpcode();
950 if (Opcode == ARM::BR_JTadd)
952 else if (Opcode == ARM::BR_JTm)
955 const MachineOperand &MO1 = MI->getOperand(OpNum);
956 const MachineOperand &MO2 = MI->getOperand(OpNum+1); // Unique Id
957 unsigned JTI = MO1.getIndex();
959 // Emit a label for the jump table.
960 MCSymbol *JTISymbol = GetARMJTIPICJumpTableLabel2(JTI, MO2.getImm());
961 OutStreamer.EmitLabel(JTISymbol);
963 // Mark the jump table as data-in-code.
964 OutStreamer.EmitDataRegion(MCDR_DataRegionJT32);
966 // Emit each entry of the table.
967 const MachineJumpTableInfo *MJTI = MF->getJumpTableInfo();
968 const std::vector<MachineJumpTableEntry> &JT = MJTI->getJumpTables();
969 const std::vector<MachineBasicBlock*> &JTBBs = JT[JTI].MBBs;
971 for (unsigned i = 0, e = JTBBs.size(); i != e; ++i) {
972 MachineBasicBlock *MBB = JTBBs[i];
973 // Construct an MCExpr for the entry. We want a value of the form:
974 // (BasicBlockAddr - TableBeginAddr)
976 // For example, a table with entries jumping to basic blocks BB0 and BB1
979 // .word (LBB0 - LJTI_0_0)
980 // .word (LBB1 - LJTI_0_0)
981 const MCExpr *Expr = MCSymbolRefExpr::Create(MBB->getSymbol(), OutContext);
983 if (TM.getRelocationModel() == Reloc::PIC_)
984 Expr = MCBinaryExpr::CreateSub(Expr, MCSymbolRefExpr::Create(JTISymbol,
987 // If we're generating a table of Thumb addresses in static relocation
988 // model, we need to add one to keep interworking correctly.
989 else if (AFI->isThumbFunction())
990 Expr = MCBinaryExpr::CreateAdd(Expr, MCConstantExpr::Create(1,OutContext),
992 OutStreamer.EmitValue(Expr, 4);
994 // Mark the end of jump table data-in-code region.
995 OutStreamer.EmitDataRegion(MCDR_DataRegionEnd);
998 void ARMAsmPrinter::EmitJump2Table(const MachineInstr *MI) {
999 unsigned Opcode = MI->getOpcode();
1000 int OpNum = (Opcode == ARM::t2BR_JT) ? 2 : 1;
1001 const MachineOperand &MO1 = MI->getOperand(OpNum);
1002 const MachineOperand &MO2 = MI->getOperand(OpNum+1); // Unique Id
1003 unsigned JTI = MO1.getIndex();
1005 MCSymbol *JTISymbol = GetARMJTIPICJumpTableLabel2(JTI, MO2.getImm());
1006 OutStreamer.EmitLabel(JTISymbol);
1008 // Emit each entry of the table.
1009 const MachineJumpTableInfo *MJTI = MF->getJumpTableInfo();
1010 const std::vector<MachineJumpTableEntry> &JT = MJTI->getJumpTables();
1011 const std::vector<MachineBasicBlock*> &JTBBs = JT[JTI].MBBs;
1012 unsigned OffsetWidth = 4;
1013 if (MI->getOpcode() == ARM::t2TBB_JT) {
1015 // Mark the jump table as data-in-code.
1016 OutStreamer.EmitDataRegion(MCDR_DataRegionJT8);
1017 } else if (MI->getOpcode() == ARM::t2TBH_JT) {
1019 // Mark the jump table as data-in-code.
1020 OutStreamer.EmitDataRegion(MCDR_DataRegionJT16);
1023 for (unsigned i = 0, e = JTBBs.size(); i != e; ++i) {
1024 MachineBasicBlock *MBB = JTBBs[i];
1025 const MCExpr *MBBSymbolExpr = MCSymbolRefExpr::Create(MBB->getSymbol(),
1027 // If this isn't a TBB or TBH, the entries are direct branch instructions.
1028 if (OffsetWidth == 4) {
1029 EmitToStreamer(OutStreamer, MCInstBuilder(ARM::t2B)
1030 .addExpr(MBBSymbolExpr)
1035 // Otherwise it's an offset from the dispatch instruction. Construct an
1036 // MCExpr for the entry. We want a value of the form:
1037 // (BasicBlockAddr - TableBeginAddr) / 2
1039 // For example, a TBB table with entries jumping to basic blocks BB0 and BB1
1042 // .byte (LBB0 - LJTI_0_0) / 2
1043 // .byte (LBB1 - LJTI_0_0) / 2
1044 const MCExpr *Expr =
1045 MCBinaryExpr::CreateSub(MBBSymbolExpr,
1046 MCSymbolRefExpr::Create(JTISymbol, OutContext),
1048 Expr = MCBinaryExpr::CreateDiv(Expr, MCConstantExpr::Create(2, OutContext),
1050 OutStreamer.EmitValue(Expr, OffsetWidth);
1052 // Mark the end of jump table data-in-code region. 32-bit offsets use
1053 // actual branch instructions here, so we don't mark those as a data-region
1055 if (OffsetWidth != 4)
1056 OutStreamer.EmitDataRegion(MCDR_DataRegionEnd);
1059 void ARMAsmPrinter::EmitUnwindingInstruction(const MachineInstr *MI) {
1060 assert(MI->getFlag(MachineInstr::FrameSetup) &&
1061 "Only instruction which are involved into frame setup code are allowed");
1063 MCTargetStreamer &TS = *OutStreamer.getTargetStreamer();
1064 ARMTargetStreamer &ATS = static_cast<ARMTargetStreamer &>(TS);
1065 const MachineFunction &MF = *MI->getParent()->getParent();
1066 const TargetRegisterInfo *RegInfo = MF.getSubtarget().getRegisterInfo();
1067 const ARMFunctionInfo &AFI = *MF.getInfo<ARMFunctionInfo>();
1069 unsigned FramePtr = RegInfo->getFrameRegister(MF);
1070 unsigned Opc = MI->getOpcode();
1071 unsigned SrcReg, DstReg;
1073 if (Opc == ARM::tPUSH || Opc == ARM::tLDRpci) {
1074 // Two special cases:
1075 // 1) tPUSH does not have src/dst regs.
1076 // 2) for Thumb1 code we sometimes materialize the constant via constpool
1077 // load. Yes, this is pretty fragile, but for now I don't see better
1079 SrcReg = DstReg = ARM::SP;
1081 SrcReg = MI->getOperand(1).getReg();
1082 DstReg = MI->getOperand(0).getReg();
1085 // Try to figure out the unwinding opcode out of src / dst regs.
1086 if (MI->mayStore()) {
1088 assert(DstReg == ARM::SP &&
1089 "Only stack pointer as a destination reg is supported");
1091 SmallVector<unsigned, 4> RegList;
1092 // Skip src & dst reg, and pred ops.
1093 unsigned StartOp = 2 + 2;
1094 // Use all the operands.
1095 unsigned NumOffset = 0;
1100 llvm_unreachable("Unsupported opcode for unwinding information");
1102 // Special case here: no src & dst reg, but two extra imp ops.
1103 StartOp = 2; NumOffset = 2;
1104 case ARM::STMDB_UPD:
1105 case ARM::t2STMDB_UPD:
1106 case ARM::VSTMDDB_UPD:
1107 assert(SrcReg == ARM::SP &&
1108 "Only stack pointer as a source reg is supported");
1109 for (unsigned i = StartOp, NumOps = MI->getNumOperands() - NumOffset;
1111 const MachineOperand &MO = MI->getOperand(i);
1112 // Actually, there should never be any impdef stuff here. Skip it
1113 // temporary to workaround PR11902.
1114 if (MO.isImplicit())
1116 RegList.push_back(MO.getReg());
1119 case ARM::STR_PRE_IMM:
1120 case ARM::STR_PRE_REG:
1121 case ARM::t2STR_PRE:
1122 assert(MI->getOperand(2).getReg() == ARM::SP &&
1123 "Only stack pointer as a source reg is supported");
1124 RegList.push_back(SrcReg);
1127 if (MAI->getExceptionHandlingType() == ExceptionHandling::ARM)
1128 ATS.emitRegSave(RegList, Opc == ARM::VSTMDDB_UPD);
1130 // Changes of stack / frame pointer.
1131 if (SrcReg == ARM::SP) {
1136 llvm_unreachable("Unsupported opcode for unwinding information");
1142 Offset = -MI->getOperand(2).getImm();
1146 Offset = MI->getOperand(2).getImm();
1149 Offset = MI->getOperand(2).getImm()*4;
1153 Offset = -MI->getOperand(2).getImm()*4;
1155 case ARM::tLDRpci: {
1156 // Grab the constpool index and check, whether it corresponds to
1157 // original or cloned constpool entry.
1158 unsigned CPI = MI->getOperand(1).getIndex();
1159 const MachineConstantPool *MCP = MF.getConstantPool();
1160 if (CPI >= MCP->getConstants().size())
1161 CPI = AFI.getOriginalCPIdx(CPI);
1162 assert(CPI != -1U && "Invalid constpool index");
1164 // Derive the actual offset.
1165 const MachineConstantPoolEntry &CPE = MCP->getConstants()[CPI];
1166 assert(!CPE.isMachineConstantPoolEntry() && "Invalid constpool entry");
1167 // FIXME: Check for user, it should be "add" instruction!
1168 Offset = -cast<ConstantInt>(CPE.Val.ConstVal)->getSExtValue();
1173 if (MAI->getExceptionHandlingType() == ExceptionHandling::ARM) {
1174 if (DstReg == FramePtr && FramePtr != ARM::SP)
1175 // Set-up of the frame pointer. Positive values correspond to "add"
1177 ATS.emitSetFP(FramePtr, ARM::SP, -Offset);
1178 else if (DstReg == ARM::SP) {
1179 // Change of SP by an offset. Positive values correspond to "sub"
1181 ATS.emitPad(Offset);
1183 // Move of SP to a register. Positive values correspond to an "add"
1185 ATS.emitMovSP(DstReg, -Offset);
1188 } else if (DstReg == ARM::SP) {
1190 llvm_unreachable("Unsupported opcode for unwinding information");
1194 llvm_unreachable("Unsupported opcode for unwinding information");
1199 // Simple pseudo-instructions have their lowering (with expansion to real
1200 // instructions) auto-generated.
1201 #include "ARMGenMCPseudoLowering.inc"
1203 void ARMAsmPrinter::EmitInstruction(const MachineInstr *MI) {
1204 const DataLayout *DL = TM.getSubtargetImpl()->getDataLayout();
1206 // If we just ended a constant pool, mark it as such.
1207 if (InConstantPool && MI->getOpcode() != ARM::CONSTPOOL_ENTRY) {
1208 OutStreamer.EmitDataRegion(MCDR_DataRegionEnd);
1209 InConstantPool = false;
1212 // Emit unwinding stuff for frame-related instructions
1213 if (Subtarget->isTargetEHABICompatible() &&
1214 MI->getFlag(MachineInstr::FrameSetup))
1215 EmitUnwindingInstruction(MI);
1217 // Do any auto-generated pseudo lowerings.
1218 if (emitPseudoExpansionLowering(OutStreamer, MI))
1221 assert(!convertAddSubFlagsOpcode(MI->getOpcode()) &&
1222 "Pseudo flag setting opcode should be expanded early");
1224 // Check for manual lowerings.
1225 unsigned Opc = MI->getOpcode();
1227 case ARM::t2MOVi32imm: llvm_unreachable("Should be lowered by thumb2it pass");
1228 case ARM::DBG_VALUE: llvm_unreachable("Should be handled by generic printing");
1230 case ARM::tLEApcrel:
1231 case ARM::t2LEApcrel: {
1232 // FIXME: Need to also handle globals and externals
1233 MCSymbol *CPISymbol = GetCPISymbol(MI->getOperand(1).getIndex());
1234 EmitToStreamer(OutStreamer, MCInstBuilder(MI->getOpcode() ==
1235 ARM::t2LEApcrel ? ARM::t2ADR
1236 : (MI->getOpcode() == ARM::tLEApcrel ? ARM::tADR
1238 .addReg(MI->getOperand(0).getReg())
1239 .addExpr(MCSymbolRefExpr::Create(CPISymbol, OutContext))
1240 // Add predicate operands.
1241 .addImm(MI->getOperand(2).getImm())
1242 .addReg(MI->getOperand(3).getReg()));
1245 case ARM::LEApcrelJT:
1246 case ARM::tLEApcrelJT:
1247 case ARM::t2LEApcrelJT: {
1248 MCSymbol *JTIPICSymbol =
1249 GetARMJTIPICJumpTableLabel2(MI->getOperand(1).getIndex(),
1250 MI->getOperand(2).getImm());
1251 EmitToStreamer(OutStreamer, MCInstBuilder(MI->getOpcode() ==
1252 ARM::t2LEApcrelJT ? ARM::t2ADR
1253 : (MI->getOpcode() == ARM::tLEApcrelJT ? ARM::tADR
1255 .addReg(MI->getOperand(0).getReg())
1256 .addExpr(MCSymbolRefExpr::Create(JTIPICSymbol, OutContext))
1257 // Add predicate operands.
1258 .addImm(MI->getOperand(3).getImm())
1259 .addReg(MI->getOperand(4).getReg()));
1262 // Darwin call instructions are just normal call instructions with different
1263 // clobber semantics (they clobber R9).
1264 case ARM::BX_CALL: {
1265 EmitToStreamer(OutStreamer, MCInstBuilder(ARM::MOVr)
1268 // Add predicate operands.
1271 // Add 's' bit operand (always reg0 for this)
1274 EmitToStreamer(OutStreamer, MCInstBuilder(ARM::BX)
1275 .addReg(MI->getOperand(0).getReg()));
1278 case ARM::tBX_CALL: {
1279 EmitToStreamer(OutStreamer, MCInstBuilder(ARM::tMOVr)
1282 // Add predicate operands.
1286 EmitToStreamer(OutStreamer, MCInstBuilder(ARM::tBX)
1287 .addReg(MI->getOperand(0).getReg())
1288 // Add predicate operands.
1293 case ARM::BMOVPCRX_CALL: {
1294 EmitToStreamer(OutStreamer, MCInstBuilder(ARM::MOVr)
1297 // Add predicate operands.
1300 // Add 's' bit operand (always reg0 for this)
1303 EmitToStreamer(OutStreamer, MCInstBuilder(ARM::MOVr)
1305 .addReg(MI->getOperand(0).getReg())
1306 // Add predicate operands.
1309 // Add 's' bit operand (always reg0 for this)
1313 case ARM::BMOVPCB_CALL: {
1314 EmitToStreamer(OutStreamer, MCInstBuilder(ARM::MOVr)
1317 // Add predicate operands.
1320 // Add 's' bit operand (always reg0 for this)
1323 const MachineOperand &Op = MI->getOperand(0);
1324 const GlobalValue *GV = Op.getGlobal();
1325 const unsigned TF = Op.getTargetFlags();
1326 MCSymbol *GVSym = GetARMGVSymbol(GV, TF);
1327 const MCExpr *GVSymExpr = MCSymbolRefExpr::Create(GVSym, OutContext);
1328 EmitToStreamer(OutStreamer, MCInstBuilder(ARM::Bcc)
1330 // Add predicate operands.
1335 case ARM::MOVi16_ga_pcrel:
1336 case ARM::t2MOVi16_ga_pcrel: {
1338 TmpInst.setOpcode(Opc == ARM::MOVi16_ga_pcrel? ARM::MOVi16 : ARM::t2MOVi16);
1339 TmpInst.addOperand(MCOperand::CreateReg(MI->getOperand(0).getReg()));
1341 unsigned TF = MI->getOperand(1).getTargetFlags();
1342 const GlobalValue *GV = MI->getOperand(1).getGlobal();
1343 MCSymbol *GVSym = GetARMGVSymbol(GV, TF);
1344 const MCExpr *GVSymExpr = MCSymbolRefExpr::Create(GVSym, OutContext);
1346 MCSymbol *LabelSym = getPICLabel(DL->getPrivateGlobalPrefix(),
1347 getFunctionNumber(),
1348 MI->getOperand(2).getImm(), OutContext);
1349 const MCExpr *LabelSymExpr= MCSymbolRefExpr::Create(LabelSym, OutContext);
1350 unsigned PCAdj = (Opc == ARM::MOVi16_ga_pcrel) ? 8 : 4;
1351 const MCExpr *PCRelExpr =
1352 ARMMCExpr::CreateLower16(MCBinaryExpr::CreateSub(GVSymExpr,
1353 MCBinaryExpr::CreateAdd(LabelSymExpr,
1354 MCConstantExpr::Create(PCAdj, OutContext),
1355 OutContext), OutContext), OutContext);
1356 TmpInst.addOperand(MCOperand::CreateExpr(PCRelExpr));
1358 // Add predicate operands.
1359 TmpInst.addOperand(MCOperand::CreateImm(ARMCC::AL));
1360 TmpInst.addOperand(MCOperand::CreateReg(0));
1361 // Add 's' bit operand (always reg0 for this)
1362 TmpInst.addOperand(MCOperand::CreateReg(0));
1363 EmitToStreamer(OutStreamer, TmpInst);
1366 case ARM::MOVTi16_ga_pcrel:
1367 case ARM::t2MOVTi16_ga_pcrel: {
1369 TmpInst.setOpcode(Opc == ARM::MOVTi16_ga_pcrel
1370 ? ARM::MOVTi16 : ARM::t2MOVTi16);
1371 TmpInst.addOperand(MCOperand::CreateReg(MI->getOperand(0).getReg()));
1372 TmpInst.addOperand(MCOperand::CreateReg(MI->getOperand(1).getReg()));
1374 unsigned TF = MI->getOperand(2).getTargetFlags();
1375 const GlobalValue *GV = MI->getOperand(2).getGlobal();
1376 MCSymbol *GVSym = GetARMGVSymbol(GV, TF);
1377 const MCExpr *GVSymExpr = MCSymbolRefExpr::Create(GVSym, OutContext);
1379 MCSymbol *LabelSym = getPICLabel(DL->getPrivateGlobalPrefix(),
1380 getFunctionNumber(),
1381 MI->getOperand(3).getImm(), OutContext);
1382 const MCExpr *LabelSymExpr= MCSymbolRefExpr::Create(LabelSym, OutContext);
1383 unsigned PCAdj = (Opc == ARM::MOVTi16_ga_pcrel) ? 8 : 4;
1384 const MCExpr *PCRelExpr =
1385 ARMMCExpr::CreateUpper16(MCBinaryExpr::CreateSub(GVSymExpr,
1386 MCBinaryExpr::CreateAdd(LabelSymExpr,
1387 MCConstantExpr::Create(PCAdj, OutContext),
1388 OutContext), OutContext), OutContext);
1389 TmpInst.addOperand(MCOperand::CreateExpr(PCRelExpr));
1390 // Add predicate operands.
1391 TmpInst.addOperand(MCOperand::CreateImm(ARMCC::AL));
1392 TmpInst.addOperand(MCOperand::CreateReg(0));
1393 // Add 's' bit operand (always reg0 for this)
1394 TmpInst.addOperand(MCOperand::CreateReg(0));
1395 EmitToStreamer(OutStreamer, TmpInst);
1398 case ARM::tPICADD: {
1399 // This is a pseudo op for a label + instruction sequence, which looks like:
1402 // This adds the address of LPC0 to r0.
1405 OutStreamer.EmitLabel(getPICLabel(DL->getPrivateGlobalPrefix(),
1406 getFunctionNumber(), MI->getOperand(2).getImm(),
1409 // Form and emit the add.
1410 EmitToStreamer(OutStreamer, MCInstBuilder(ARM::tADDhirr)
1411 .addReg(MI->getOperand(0).getReg())
1412 .addReg(MI->getOperand(0).getReg())
1414 // Add predicate operands.
1420 // This is a pseudo op for a label + instruction sequence, which looks like:
1423 // This adds the address of LPC0 to r0.
1426 OutStreamer.EmitLabel(getPICLabel(DL->getPrivateGlobalPrefix(),
1427 getFunctionNumber(), MI->getOperand(2).getImm(),
1430 // Form and emit the add.
1431 EmitToStreamer(OutStreamer, MCInstBuilder(ARM::ADDrr)
1432 .addReg(MI->getOperand(0).getReg())
1434 .addReg(MI->getOperand(1).getReg())
1435 // Add predicate operands.
1436 .addImm(MI->getOperand(3).getImm())
1437 .addReg(MI->getOperand(4).getReg())
1438 // Add 's' bit operand (always reg0 for this)
1449 case ARM::PICLDRSH: {
1450 // This is a pseudo op for a label + instruction sequence, which looks like:
1453 // The LCP0 label is referenced by a constant pool entry in order to get
1454 // a PC-relative address at the ldr instruction.
1457 OutStreamer.EmitLabel(getPICLabel(DL->getPrivateGlobalPrefix(),
1458 getFunctionNumber(), MI->getOperand(2).getImm(),
1461 // Form and emit the load
1463 switch (MI->getOpcode()) {
1465 llvm_unreachable("Unexpected opcode!");
1466 case ARM::PICSTR: Opcode = ARM::STRrs; break;
1467 case ARM::PICSTRB: Opcode = ARM::STRBrs; break;
1468 case ARM::PICSTRH: Opcode = ARM::STRH; break;
1469 case ARM::PICLDR: Opcode = ARM::LDRrs; break;
1470 case ARM::PICLDRB: Opcode = ARM::LDRBrs; break;
1471 case ARM::PICLDRH: Opcode = ARM::LDRH; break;
1472 case ARM::PICLDRSB: Opcode = ARM::LDRSB; break;
1473 case ARM::PICLDRSH: Opcode = ARM::LDRSH; break;
1475 EmitToStreamer(OutStreamer, MCInstBuilder(Opcode)
1476 .addReg(MI->getOperand(0).getReg())
1478 .addReg(MI->getOperand(1).getReg())
1480 // Add predicate operands.
1481 .addImm(MI->getOperand(3).getImm())
1482 .addReg(MI->getOperand(4).getReg()));
1486 case ARM::CONSTPOOL_ENTRY: {
1487 /// CONSTPOOL_ENTRY - This instruction represents a floating constant pool
1488 /// in the function. The first operand is the ID# for this instruction, the
1489 /// second is the index into the MachineConstantPool that this is, the third
1490 /// is the size in bytes of this constant pool entry.
1491 /// The required alignment is specified on the basic block holding this MI.
1492 unsigned LabelId = (unsigned)MI->getOperand(0).getImm();
1493 unsigned CPIdx = (unsigned)MI->getOperand(1).getIndex();
1495 // If this is the first entry of the pool, mark it.
1496 if (!InConstantPool) {
1497 OutStreamer.EmitDataRegion(MCDR_DataRegion);
1498 InConstantPool = true;
1501 OutStreamer.EmitLabel(GetCPISymbol(LabelId));
1503 const MachineConstantPoolEntry &MCPE = MCP->getConstants()[CPIdx];
1504 if (MCPE.isMachineConstantPoolEntry())
1505 EmitMachineConstantPoolValue(MCPE.Val.MachineCPVal);
1507 EmitGlobalConstant(MCPE.Val.ConstVal);
1510 case ARM::t2BR_JT: {
1511 // Lower and emit the instruction itself, then the jump table following it.
1512 EmitToStreamer(OutStreamer, MCInstBuilder(ARM::tMOVr)
1514 .addReg(MI->getOperand(0).getReg())
1515 // Add predicate operands.
1519 // Output the data for the jump table itself
1523 case ARM::t2TBB_JT: {
1524 // Lower and emit the instruction itself, then the jump table following it.
1525 EmitToStreamer(OutStreamer, MCInstBuilder(ARM::t2TBB)
1527 .addReg(MI->getOperand(0).getReg())
1528 // Add predicate operands.
1532 // Output the data for the jump table itself
1534 // Make sure the next instruction is 2-byte aligned.
1538 case ARM::t2TBH_JT: {
1539 // Lower and emit the instruction itself, then the jump table following it.
1540 EmitToStreamer(OutStreamer, MCInstBuilder(ARM::t2TBH)
1542 .addReg(MI->getOperand(0).getReg())
1543 // Add predicate operands.
1547 // Output the data for the jump table itself
1553 // Lower and emit the instruction itself, then the jump table following it.
1556 unsigned Opc = MI->getOpcode() == ARM::BR_JTr ?
1557 ARM::MOVr : ARM::tMOVr;
1558 TmpInst.setOpcode(Opc);
1559 TmpInst.addOperand(MCOperand::CreateReg(ARM::PC));
1560 TmpInst.addOperand(MCOperand::CreateReg(MI->getOperand(0).getReg()));
1561 // Add predicate operands.
1562 TmpInst.addOperand(MCOperand::CreateImm(ARMCC::AL));
1563 TmpInst.addOperand(MCOperand::CreateReg(0));
1564 // Add 's' bit operand (always reg0 for this)
1565 if (Opc == ARM::MOVr)
1566 TmpInst.addOperand(MCOperand::CreateReg(0));
1567 EmitToStreamer(OutStreamer, TmpInst);
1569 // Make sure the Thumb jump table is 4-byte aligned.
1570 if (Opc == ARM::tMOVr)
1573 // Output the data for the jump table itself
1578 // Lower and emit the instruction itself, then the jump table following it.
1581 if (MI->getOperand(1).getReg() == 0) {
1583 TmpInst.setOpcode(ARM::LDRi12);
1584 TmpInst.addOperand(MCOperand::CreateReg(ARM::PC));
1585 TmpInst.addOperand(MCOperand::CreateReg(MI->getOperand(0).getReg()));
1586 TmpInst.addOperand(MCOperand::CreateImm(MI->getOperand(2).getImm()));
1588 TmpInst.setOpcode(ARM::LDRrs);
1589 TmpInst.addOperand(MCOperand::CreateReg(ARM::PC));
1590 TmpInst.addOperand(MCOperand::CreateReg(MI->getOperand(0).getReg()));
1591 TmpInst.addOperand(MCOperand::CreateReg(MI->getOperand(1).getReg()));
1592 TmpInst.addOperand(MCOperand::CreateImm(0));
1594 // Add predicate operands.
1595 TmpInst.addOperand(MCOperand::CreateImm(ARMCC::AL));
1596 TmpInst.addOperand(MCOperand::CreateReg(0));
1597 EmitToStreamer(OutStreamer, TmpInst);
1599 // Output the data for the jump table itself
1603 case ARM::BR_JTadd: {
1604 // Lower and emit the instruction itself, then the jump table following it.
1605 // add pc, target, idx
1606 EmitToStreamer(OutStreamer, MCInstBuilder(ARM::ADDrr)
1608 .addReg(MI->getOperand(0).getReg())
1609 .addReg(MI->getOperand(1).getReg())
1610 // Add predicate operands.
1613 // Add 's' bit operand (always reg0 for this)
1616 // Output the data for the jump table itself
1621 OutStreamer.EmitZeros(MI->getOperand(1).getImm());
1624 // Non-Darwin binutils don't yet support the "trap" mnemonic.
1625 // FIXME: Remove this special case when they do.
1626 if (!Subtarget->isTargetMachO()) {
1627 //.long 0xe7ffdefe @ trap
1628 uint32_t Val = 0xe7ffdefeUL;
1629 OutStreamer.AddComment("trap");
1630 OutStreamer.EmitIntValue(Val, 4);
1635 case ARM::TRAPNaCl: {
1636 //.long 0xe7fedef0 @ trap
1637 uint32_t Val = 0xe7fedef0UL;
1638 OutStreamer.AddComment("trap");
1639 OutStreamer.EmitIntValue(Val, 4);
1643 // Non-Darwin binutils don't yet support the "trap" mnemonic.
1644 // FIXME: Remove this special case when they do.
1645 if (!Subtarget->isTargetMachO()) {
1646 //.short 57086 @ trap
1647 uint16_t Val = 0xdefe;
1648 OutStreamer.AddComment("trap");
1649 OutStreamer.EmitIntValue(Val, 2);
1654 case ARM::t2Int_eh_sjlj_setjmp:
1655 case ARM::t2Int_eh_sjlj_setjmp_nofp:
1656 case ARM::tInt_eh_sjlj_setjmp: {
1657 // Two incoming args: GPR:$src, GPR:$val
1660 // str $val, [$src, #4]
1665 unsigned SrcReg = MI->getOperand(0).getReg();
1666 unsigned ValReg = MI->getOperand(1).getReg();
1667 MCSymbol *Label = GetARMSJLJEHLabel();
1668 OutStreamer.AddComment("eh_setjmp begin");
1669 EmitToStreamer(OutStreamer, MCInstBuilder(ARM::tMOVr)
1676 EmitToStreamer(OutStreamer, MCInstBuilder(ARM::tADDi3)
1686 EmitToStreamer(OutStreamer, MCInstBuilder(ARM::tSTRi)
1689 // The offset immediate is #4. The operand value is scaled by 4 for the
1690 // tSTR instruction.
1696 EmitToStreamer(OutStreamer, MCInstBuilder(ARM::tMOVi8)
1704 const MCExpr *SymbolExpr = MCSymbolRefExpr::Create(Label, OutContext);
1705 EmitToStreamer(OutStreamer, MCInstBuilder(ARM::tB)
1706 .addExpr(SymbolExpr)
1710 OutStreamer.AddComment("eh_setjmp end");
1711 EmitToStreamer(OutStreamer, MCInstBuilder(ARM::tMOVi8)
1719 OutStreamer.EmitLabel(Label);
1723 case ARM::Int_eh_sjlj_setjmp_nofp:
1724 case ARM::Int_eh_sjlj_setjmp: {
1725 // Two incoming args: GPR:$src, GPR:$val
1727 // str $val, [$src, #+4]
1731 unsigned SrcReg = MI->getOperand(0).getReg();
1732 unsigned ValReg = MI->getOperand(1).getReg();
1734 OutStreamer.AddComment("eh_setjmp begin");
1735 EmitToStreamer(OutStreamer, MCInstBuilder(ARM::ADDri)
1742 // 's' bit operand (always reg0 for this).
1745 EmitToStreamer(OutStreamer, MCInstBuilder(ARM::STRi12)
1753 EmitToStreamer(OutStreamer, MCInstBuilder(ARM::MOVi)
1759 // 's' bit operand (always reg0 for this).
1762 EmitToStreamer(OutStreamer, MCInstBuilder(ARM::ADDri)
1769 // 's' bit operand (always reg0 for this).
1772 OutStreamer.AddComment("eh_setjmp end");
1773 EmitToStreamer(OutStreamer, MCInstBuilder(ARM::MOVi)
1779 // 's' bit operand (always reg0 for this).
1783 case ARM::Int_eh_sjlj_longjmp: {
1784 // ldr sp, [$src, #8]
1785 // ldr $scratch, [$src, #4]
1788 unsigned SrcReg = MI->getOperand(0).getReg();
1789 unsigned ScratchReg = MI->getOperand(1).getReg();
1790 EmitToStreamer(OutStreamer, MCInstBuilder(ARM::LDRi12)
1798 EmitToStreamer(OutStreamer, MCInstBuilder(ARM::LDRi12)
1806 EmitToStreamer(OutStreamer, MCInstBuilder(ARM::LDRi12)
1814 EmitToStreamer(OutStreamer, MCInstBuilder(ARM::BX)
1821 case ARM::tInt_eh_sjlj_longjmp: {
1822 // ldr $scratch, [$src, #8]
1824 // ldr $scratch, [$src, #4]
1827 unsigned SrcReg = MI->getOperand(0).getReg();
1828 unsigned ScratchReg = MI->getOperand(1).getReg();
1829 EmitToStreamer(OutStreamer, MCInstBuilder(ARM::tLDRi)
1832 // The offset immediate is #8. The operand value is scaled by 4 for the
1833 // tLDR instruction.
1839 EmitToStreamer(OutStreamer, MCInstBuilder(ARM::tMOVr)
1846 EmitToStreamer(OutStreamer, MCInstBuilder(ARM::tLDRi)
1854 EmitToStreamer(OutStreamer, MCInstBuilder(ARM::tLDRi)
1862 EmitToStreamer(OutStreamer, MCInstBuilder(ARM::tBX)
1872 LowerARMMachineInstrToMCInst(MI, TmpInst, *this);
1874 EmitToStreamer(OutStreamer, TmpInst);
1877 //===----------------------------------------------------------------------===//
1878 // Target Registry Stuff
1879 //===----------------------------------------------------------------------===//
1881 // Force static initialization.
1882 extern "C" void LLVMInitializeARMAsmPrinter() {
1883 RegisterAsmPrinter<ARMAsmPrinter> X(TheARMLETarget);
1884 RegisterAsmPrinter<ARMAsmPrinter> Y(TheARMBETarget);
1885 RegisterAsmPrinter<ARMAsmPrinter> A(TheThumbLETarget);
1886 RegisterAsmPrinter<ARMAsmPrinter> B(TheThumbBETarget);