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 #define DEBUG_TYPE "asm-printer"
17 #include "ARMBuildAttrs.h"
18 #include "ARMAddressingModes.h"
19 #include "ARMConstantPoolValue.h"
20 #include "AsmPrinter/ARMInstPrinter.h"
21 #include "ARMMachineFunctionInfo.h"
22 #include "ARMMCInstLower.h"
23 #include "ARMTargetMachine.h"
24 #include "llvm/Analysis/DebugInfo.h"
25 #include "llvm/Constants.h"
26 #include "llvm/Module.h"
27 #include "llvm/Type.h"
28 #include "llvm/Assembly/Writer.h"
29 #include "llvm/CodeGen/AsmPrinter.h"
30 #include "llvm/CodeGen/MachineModuleInfoImpls.h"
31 #include "llvm/CodeGen/MachineFunctionPass.h"
32 #include "llvm/CodeGen/MachineJumpTableInfo.h"
33 #include "llvm/CodeGen/TargetLoweringObjectFileImpl.h"
34 #include "llvm/MC/MCAsmInfo.h"
35 #include "llvm/MC/MCContext.h"
36 #include "llvm/MC/MCExpr.h"
37 #include "llvm/MC/MCInst.h"
38 #include "llvm/MC/MCSectionMachO.h"
39 #include "llvm/MC/MCStreamer.h"
40 #include "llvm/MC/MCSymbol.h"
41 #include "llvm/Target/Mangler.h"
42 #include "llvm/Target/TargetData.h"
43 #include "llvm/Target/TargetMachine.h"
44 #include "llvm/Target/TargetOptions.h"
45 #include "llvm/Target/TargetRegistry.h"
46 #include "llvm/ADT/SmallPtrSet.h"
47 #include "llvm/ADT/SmallString.h"
48 #include "llvm/ADT/StringExtras.h"
49 #include "llvm/Support/CommandLine.h"
50 #include "llvm/Support/Debug.h"
51 #include "llvm/Support/ErrorHandling.h"
52 #include "llvm/Support/raw_ostream.h"
57 EnableMCInst("enable-arm-mcinst-printer", cl::Hidden,
58 cl::desc("enable experimental asmprinter gunk in the arm backend"));
70 class ARMAsmPrinter : public AsmPrinter {
72 /// Subtarget - Keep a pointer to the ARMSubtarget around so that we can
73 /// make the right decision when printing asm code for different targets.
74 const ARMSubtarget *Subtarget;
76 /// AFI - Keep a pointer to ARMFunctionInfo for the current
80 /// MCP - Keep a pointer to constantpool entries of the current
82 const MachineConstantPool *MCP;
85 explicit ARMAsmPrinter(TargetMachine &TM, MCStreamer &Streamer)
86 : AsmPrinter(TM, Streamer), AFI(NULL), MCP(NULL) {
87 Subtarget = &TM.getSubtarget<ARMSubtarget>();
90 virtual const char *getPassName() const {
91 return "ARM Assembly Printer";
94 void printInstructionThroughMCStreamer(const MachineInstr *MI);
97 void printOperand(const MachineInstr *MI, int OpNum, raw_ostream &O,
98 const char *Modifier = 0);
99 void printSOImmOperand(const MachineInstr *MI, int OpNum, raw_ostream &O);
100 void printSOImm2PartOperand(const MachineInstr *MI, int OpNum,
102 void printSORegOperand(const MachineInstr *MI, int OpNum,
104 void printAddrMode2Operand(const MachineInstr *MI, int OpNum,
106 void printAddrMode2OffsetOperand(const MachineInstr *MI, int OpNum,
108 void printAddrMode3Operand(const MachineInstr *MI, int OpNum,
110 void printAddrMode3OffsetOperand(const MachineInstr *MI, int OpNum,
112 void printAddrMode4Operand(const MachineInstr *MI, int OpNum,raw_ostream &O,
113 const char *Modifier = 0);
114 void printAddrMode5Operand(const MachineInstr *MI, int OpNum,raw_ostream &O,
115 const char *Modifier = 0);
116 void printAddrMode6Operand(const MachineInstr *MI, int OpNum,
118 void printAddrMode6OffsetOperand(const MachineInstr *MI, int OpNum,
120 void printAddrModePCOperand(const MachineInstr *MI, int OpNum,
122 const char *Modifier = 0);
123 void printBitfieldInvMaskImmOperand (const MachineInstr *MI, int OpNum,
126 void printThumbS4ImmOperand(const MachineInstr *MI, int OpNum,
128 void printThumbITMask(const MachineInstr *MI, int OpNum, raw_ostream &O);
129 void printThumbAddrModeRROperand(const MachineInstr *MI, int OpNum,
131 void printThumbAddrModeRI5Operand(const MachineInstr *MI, int OpNum,
134 void printThumbAddrModeS1Operand(const MachineInstr *MI, int OpNum,
136 void printThumbAddrModeS2Operand(const MachineInstr *MI, int OpNum,
138 void printThumbAddrModeS4Operand(const MachineInstr *MI, int OpNum,
140 void printThumbAddrModeSPOperand(const MachineInstr *MI, int OpNum,
143 void printT2SOOperand(const MachineInstr *MI, int OpNum, raw_ostream &O);
144 void printT2AddrModeImm12Operand(const MachineInstr *MI, int OpNum,
146 void printT2AddrModeImm8Operand(const MachineInstr *MI, int OpNum,
148 void printT2AddrModeImm8s4Operand(const MachineInstr *MI, int OpNum,
150 void printT2AddrModeImm8OffsetOperand(const MachineInstr *MI, int OpNum,
152 void printT2AddrModeImm8s4OffsetOperand(const MachineInstr *MI, int OpNum,
154 void printT2AddrModeSoRegOperand(const MachineInstr *MI, int OpNum,
157 void printCPSOptionOperand(const MachineInstr *MI, int OpNum,
159 void printMSRMaskOperand(const MachineInstr *MI, int OpNum,
161 void printNegZeroOperand(const MachineInstr *MI, int OpNum,
163 void printPredicateOperand(const MachineInstr *MI, int OpNum,
165 void printMandatoryPredicateOperand(const MachineInstr *MI, int OpNum,
167 void printSBitModifierOperand(const MachineInstr *MI, int OpNum,
169 void printPCLabel(const MachineInstr *MI, int OpNum,
171 void printRegisterList(const MachineInstr *MI, int OpNum,
173 void printCPInstOperand(const MachineInstr *MI, int OpNum,
175 const char *Modifier);
176 void printJTBlockOperand(const MachineInstr *MI, int OpNum,
178 void printJT2BlockOperand(const MachineInstr *MI, int OpNum,
180 void printTBAddrMode(const MachineInstr *MI, int OpNum,
182 void printNoHashImmediate(const MachineInstr *MI, int OpNum,
184 void printVFPf32ImmOperand(const MachineInstr *MI, int OpNum,
186 void printVFPf64ImmOperand(const MachineInstr *MI, int OpNum,
188 void printNEONModImmOperand(const MachineInstr *MI, int OpNum,
191 virtual bool PrintAsmOperand(const MachineInstr *MI, unsigned OpNum,
192 unsigned AsmVariant, const char *ExtraCode,
194 virtual bool PrintAsmMemoryOperand(const MachineInstr *MI, unsigned OpNum,
196 const char *ExtraCode, raw_ostream &O);
198 void printInstruction(const MachineInstr *MI, raw_ostream &O); // autogen
199 static const char *getRegisterName(unsigned RegNo);
201 virtual void EmitInstruction(const MachineInstr *MI);
202 bool runOnMachineFunction(MachineFunction &F);
204 virtual void EmitConstantPool() {} // we emit constant pools customly!
205 virtual void EmitFunctionEntryLabel();
206 void EmitStartOfAsmFile(Module &M);
207 void EmitEndOfAsmFile(Module &M);
209 MachineLocation getDebugValueLocation(const MachineInstr *MI) const {
210 MachineLocation Location;
211 assert (MI->getNumOperands() == 4 && "Invalid no. of machine operands!");
212 // Frame address. Currently handles register +- offset only.
213 if (MI->getOperand(0).isReg() && MI->getOperand(1).isImm())
214 Location.set(MI->getOperand(0).getReg(), MI->getOperand(1).getImm());
216 DEBUG(dbgs() << "DBG_VALUE instruction ignored! " << *MI << "\n");
221 virtual unsigned getISAEncoding() {
222 // ARM/Darwin adds ISA to the DWARF info for each function.
223 if (!Subtarget->isTargetDarwin())
225 return Subtarget->isThumb() ?
226 llvm::ARM::DW_ISA_ARM_thumb : llvm::ARM::DW_ISA_ARM_arm;
229 MCSymbol *GetARMSetPICJumpTableLabel2(unsigned uid, unsigned uid2,
230 const MachineBasicBlock *MBB) const;
231 MCSymbol *GetARMJTIPICJumpTableLabel2(unsigned uid, unsigned uid2) const;
233 /// EmitMachineConstantPoolValue - Print a machine constantpool value to
235 virtual void EmitMachineConstantPoolValue(MachineConstantPoolValue *MCPV) {
236 SmallString<128> Str;
237 raw_svector_ostream OS(Str);
238 EmitMachineConstantPoolValue(MCPV, OS);
239 OutStreamer.EmitRawText(OS.str());
242 void EmitMachineConstantPoolValue(MachineConstantPoolValue *MCPV,
244 switch (TM.getTargetData()->getTypeAllocSize(MCPV->getType())) {
245 case 1: O << MAI->getData8bitsDirective(0); break;
246 case 2: O << MAI->getData16bitsDirective(0); break;
247 case 4: O << MAI->getData32bitsDirective(0); break;
248 default: assert(0 && "Unknown CPV size");
251 ARMConstantPoolValue *ACPV = static_cast<ARMConstantPoolValue*>(MCPV);
253 if (ACPV->isLSDA()) {
254 O << MAI->getPrivateGlobalPrefix() << "_LSDA_" << getFunctionNumber();
255 } else if (ACPV->isBlockAddress()) {
256 O << *GetBlockAddressSymbol(ACPV->getBlockAddress());
257 } else if (ACPV->isGlobalValue()) {
258 const GlobalValue *GV = ACPV->getGV();
259 bool isIndirect = Subtarget->isTargetDarwin() &&
260 Subtarget->GVIsIndirectSymbol(GV, TM.getRelocationModel());
262 O << *Mang->getSymbol(GV);
264 // FIXME: Remove this when Darwin transition to @GOT like syntax.
265 MCSymbol *Sym = GetSymbolWithGlobalValueBase(GV, "$non_lazy_ptr");
268 MachineModuleInfoMachO &MMIMachO =
269 MMI->getObjFileInfo<MachineModuleInfoMachO>();
270 MachineModuleInfoImpl::StubValueTy &StubSym =
271 GV->hasHiddenVisibility() ? MMIMachO.getHiddenGVStubEntry(Sym) :
272 MMIMachO.getGVStubEntry(Sym);
273 if (StubSym.getPointer() == 0)
274 StubSym = MachineModuleInfoImpl::
275 StubValueTy(Mang->getSymbol(GV), !GV->hasInternalLinkage());
278 assert(ACPV->isExtSymbol() && "unrecognized constant pool value");
279 O << *GetExternalSymbolSymbol(ACPV->getSymbol());
282 if (ACPV->hasModifier()) O << "(" << ACPV->getModifier() << ")";
283 if (ACPV->getPCAdjustment() != 0) {
284 O << "-(" << MAI->getPrivateGlobalPrefix() << "PC"
285 << getFunctionNumber() << "_" << ACPV->getLabelId()
286 << "+" << (unsigned)ACPV->getPCAdjustment();
287 if (ACPV->mustAddCurrentAddress())
293 } // end of anonymous namespace
295 #include "ARMGenAsmWriter.inc"
297 void ARMAsmPrinter::EmitFunctionEntryLabel() {
298 if (AFI->isThumbFunction()) {
299 OutStreamer.EmitRawText(StringRef("\t.code\t16"));
300 if (!Subtarget->isTargetDarwin())
301 OutStreamer.EmitRawText(StringRef("\t.thumb_func"));
303 // This needs to emit to a temporary string to get properly quoted
304 // MCSymbols when they have spaces in them.
305 SmallString<128> Tmp;
306 raw_svector_ostream OS(Tmp);
307 OS << "\t.thumb_func\t" << *CurrentFnSym;
308 OutStreamer.EmitRawText(OS.str());
312 OutStreamer.EmitLabel(CurrentFnSym);
315 /// runOnMachineFunction - This uses the printInstruction()
316 /// method to print assembly for each instruction.
318 bool ARMAsmPrinter::runOnMachineFunction(MachineFunction &MF) {
319 AFI = MF.getInfo<ARMFunctionInfo>();
320 MCP = MF.getConstantPool();
322 return AsmPrinter::runOnMachineFunction(MF);
325 void ARMAsmPrinter::printOperand(const MachineInstr *MI, int OpNum,
326 raw_ostream &O, const char *Modifier) {
327 const MachineOperand &MO = MI->getOperand(OpNum);
328 unsigned TF = MO.getTargetFlags();
330 switch (MO.getType()) {
332 assert(0 && "<unknown operand type>");
333 case MachineOperand::MO_Register: {
334 unsigned Reg = MO.getReg();
335 assert(TargetRegisterInfo::isPhysicalRegister(Reg));
336 if (Modifier && strcmp(Modifier, "dregpair") == 0) {
337 unsigned DRegLo = TM.getRegisterInfo()->getSubReg(Reg, ARM::dsub_0);
338 unsigned DRegHi = TM.getRegisterInfo()->getSubReg(Reg, ARM::dsub_1);
340 << getRegisterName(DRegLo) << ", " << getRegisterName(DRegHi)
342 } else if (Modifier && strcmp(Modifier, "lane") == 0) {
343 unsigned RegNum = ARMRegisterInfo::getRegisterNumbering(Reg);
345 TM.getRegisterInfo()->getMatchingSuperReg(Reg,
346 RegNum & 1 ? ARM::ssub_1 : ARM::ssub_0, &ARM::DPR_VFP2RegClass);
347 O << getRegisterName(DReg) << '[' << (RegNum & 1) << ']';
349 assert(!MO.getSubReg() && "Subregs should be eliminated!");
350 O << getRegisterName(Reg);
354 case MachineOperand::MO_Immediate: {
355 int64_t Imm = MO.getImm();
357 if ((Modifier && strcmp(Modifier, "lo16") == 0) ||
358 (TF & ARMII::MO_LO16))
360 else if ((Modifier && strcmp(Modifier, "hi16") == 0) ||
361 (TF & ARMII::MO_HI16))
366 case MachineOperand::MO_MachineBasicBlock:
367 O << *MO.getMBB()->getSymbol();
369 case MachineOperand::MO_GlobalAddress: {
370 bool isCallOp = Modifier && !strcmp(Modifier, "call");
371 const GlobalValue *GV = MO.getGlobal();
373 if ((Modifier && strcmp(Modifier, "lo16") == 0) ||
374 (TF & ARMII::MO_LO16))
376 else if ((Modifier && strcmp(Modifier, "hi16") == 0) ||
377 (TF & ARMII::MO_HI16))
379 O << *Mang->getSymbol(GV);
381 printOffset(MO.getOffset(), O);
383 if (isCallOp && Subtarget->isTargetELF() &&
384 TM.getRelocationModel() == Reloc::PIC_)
388 case MachineOperand::MO_ExternalSymbol: {
389 bool isCallOp = Modifier && !strcmp(Modifier, "call");
390 O << *GetExternalSymbolSymbol(MO.getSymbolName());
392 if (isCallOp && Subtarget->isTargetELF() &&
393 TM.getRelocationModel() == Reloc::PIC_)
397 case MachineOperand::MO_ConstantPoolIndex:
398 O << *GetCPISymbol(MO.getIndex());
400 case MachineOperand::MO_JumpTableIndex:
401 O << *GetJTISymbol(MO.getIndex());
406 static void printSOImm(raw_ostream &O, int64_t V, bool VerboseAsm,
407 const MCAsmInfo *MAI) {
408 // Break it up into two parts that make up a shifter immediate.
409 V = ARM_AM::getSOImmVal(V);
410 assert(V != -1 && "Not a valid so_imm value!");
412 unsigned Imm = ARM_AM::getSOImmValImm(V);
413 unsigned Rot = ARM_AM::getSOImmValRot(V);
415 // Print low-level immediate formation info, per
416 // A5.1.3: "Data-processing operands - Immediate".
418 O << "#" << Imm << ", " << Rot;
419 // Pretty printed version.
421 O << "\t" << MAI->getCommentString() << ' ';
422 O << (int)ARM_AM::rotr32(Imm, Rot);
429 /// printSOImmOperand - SOImm is 4-bit rotate amount in bits 8-11 with 8-bit
430 /// immediate in bits 0-7.
431 void ARMAsmPrinter::printSOImmOperand(const MachineInstr *MI, int OpNum,
433 const MachineOperand &MO = MI->getOperand(OpNum);
434 assert(MO.isImm() && "Not a valid so_imm value!");
435 printSOImm(O, MO.getImm(), isVerbose(), MAI);
438 /// printSOImm2PartOperand - SOImm is broken into two pieces using a 'mov'
439 /// followed by an 'orr' to materialize.
440 void ARMAsmPrinter::printSOImm2PartOperand(const MachineInstr *MI, int OpNum,
442 const MachineOperand &MO = MI->getOperand(OpNum);
443 assert(MO.isImm() && "Not a valid so_imm value!");
444 unsigned V1 = ARM_AM::getSOImmTwoPartFirst(MO.getImm());
445 unsigned V2 = ARM_AM::getSOImmTwoPartSecond(MO.getImm());
446 printSOImm(O, V1, isVerbose(), MAI);
448 printPredicateOperand(MI, 2, O);
450 printOperand(MI, 0, O);
452 printOperand(MI, 0, O);
454 printSOImm(O, V2, isVerbose(), MAI);
457 // so_reg is a 4-operand unit corresponding to register forms of the A5.1
458 // "Addressing Mode 1 - Data-processing operands" forms. This includes:
460 // REG REG 0,SH_OPC - e.g. R5, ROR R3
461 // REG 0 IMM,SH_OPC - e.g. R5, LSL #3
462 void ARMAsmPrinter::printSORegOperand(const MachineInstr *MI, int Op,
464 const MachineOperand &MO1 = MI->getOperand(Op);
465 const MachineOperand &MO2 = MI->getOperand(Op+1);
466 const MachineOperand &MO3 = MI->getOperand(Op+2);
468 O << getRegisterName(MO1.getReg());
470 // Print the shift opc.
472 << ARM_AM::getShiftOpcStr(ARM_AM::getSORegShOp(MO3.getImm()))
476 O << getRegisterName(MO2.getReg());
477 assert(ARM_AM::getSORegOffset(MO3.getImm()) == 0);
479 O << "#" << ARM_AM::getSORegOffset(MO3.getImm());
483 void ARMAsmPrinter::printAddrMode2Operand(const MachineInstr *MI, int Op,
485 const MachineOperand &MO1 = MI->getOperand(Op);
486 const MachineOperand &MO2 = MI->getOperand(Op+1);
487 const MachineOperand &MO3 = MI->getOperand(Op+2);
489 if (!MO1.isReg()) { // FIXME: This is for CP entries, but isn't right.
490 printOperand(MI, Op, O);
494 O << "[" << getRegisterName(MO1.getReg());
497 if (ARM_AM::getAM2Offset(MO3.getImm())) // Don't print +0.
499 << ARM_AM::getAddrOpcStr(ARM_AM::getAM2Op(MO3.getImm()))
500 << ARM_AM::getAM2Offset(MO3.getImm());
506 << ARM_AM::getAddrOpcStr(ARM_AM::getAM2Op(MO3.getImm()))
507 << getRegisterName(MO2.getReg());
509 if (unsigned ShImm = ARM_AM::getAM2Offset(MO3.getImm()))
511 << ARM_AM::getShiftOpcStr(ARM_AM::getAM2ShiftOpc(MO3.getImm()))
516 void ARMAsmPrinter::printAddrMode2OffsetOperand(const MachineInstr *MI, int Op,
518 const MachineOperand &MO1 = MI->getOperand(Op);
519 const MachineOperand &MO2 = MI->getOperand(Op+1);
522 unsigned ImmOffs = ARM_AM::getAM2Offset(MO2.getImm());
524 << ARM_AM::getAddrOpcStr(ARM_AM::getAM2Op(MO2.getImm()))
529 O << ARM_AM::getAddrOpcStr(ARM_AM::getAM2Op(MO2.getImm()))
530 << getRegisterName(MO1.getReg());
532 if (unsigned ShImm = ARM_AM::getAM2Offset(MO2.getImm()))
534 << ARM_AM::getShiftOpcStr(ARM_AM::getAM2ShiftOpc(MO2.getImm()))
538 void ARMAsmPrinter::printAddrMode3Operand(const MachineInstr *MI, int Op,
540 const MachineOperand &MO1 = MI->getOperand(Op);
541 const MachineOperand &MO2 = MI->getOperand(Op+1);
542 const MachineOperand &MO3 = MI->getOperand(Op+2);
544 assert(TargetRegisterInfo::isPhysicalRegister(MO1.getReg()));
545 O << "[" << getRegisterName(MO1.getReg());
549 << (char)ARM_AM::getAM3Op(MO3.getImm())
550 << getRegisterName(MO2.getReg())
555 if (unsigned ImmOffs = ARM_AM::getAM3Offset(MO3.getImm()))
557 << ARM_AM::getAddrOpcStr(ARM_AM::getAM3Op(MO3.getImm()))
562 void ARMAsmPrinter::printAddrMode3OffsetOperand(const MachineInstr *MI, int Op,
564 const MachineOperand &MO1 = MI->getOperand(Op);
565 const MachineOperand &MO2 = MI->getOperand(Op+1);
568 O << (char)ARM_AM::getAM3Op(MO2.getImm())
569 << getRegisterName(MO1.getReg());
573 unsigned ImmOffs = ARM_AM::getAM3Offset(MO2.getImm());
575 << ARM_AM::getAddrOpcStr(ARM_AM::getAM3Op(MO2.getImm()))
579 void ARMAsmPrinter::printAddrMode4Operand(const MachineInstr *MI, int Op,
581 const char *Modifier) {
582 const MachineOperand &MO2 = MI->getOperand(Op+1);
583 ARM_AM::AMSubMode Mode = ARM_AM::getAM4SubMode(MO2.getImm());
584 if (Modifier && strcmp(Modifier, "submode") == 0) {
585 O << ARM_AM::getAMSubModeStr(Mode);
586 } else if (Modifier && strcmp(Modifier, "wide") == 0) {
587 ARM_AM::AMSubMode Mode = ARM_AM::getAM4SubMode(MO2.getImm());
588 if (Mode == ARM_AM::ia)
591 printOperand(MI, Op, O);
595 void ARMAsmPrinter::printAddrMode5Operand(const MachineInstr *MI, int Op,
597 const char *Modifier) {
598 const MachineOperand &MO1 = MI->getOperand(Op);
599 const MachineOperand &MO2 = MI->getOperand(Op+1);
601 if (!MO1.isReg()) { // FIXME: This is for CP entries, but isn't right.
602 printOperand(MI, Op, O);
606 assert(TargetRegisterInfo::isPhysicalRegister(MO1.getReg()));
608 if (Modifier && strcmp(Modifier, "submode") == 0) {
609 ARM_AM::AMSubMode Mode = ARM_AM::getAM5SubMode(MO2.getImm());
610 O << ARM_AM::getAMSubModeStr(Mode);
612 } else if (Modifier && strcmp(Modifier, "base") == 0) {
613 // Used for FSTM{D|S} and LSTM{D|S} operations.
614 O << getRegisterName(MO1.getReg());
618 O << "[" << getRegisterName(MO1.getReg());
620 if (unsigned ImmOffs = ARM_AM::getAM5Offset(MO2.getImm())) {
622 << ARM_AM::getAddrOpcStr(ARM_AM::getAM5Op(MO2.getImm()))
628 void ARMAsmPrinter::printAddrMode6Operand(const MachineInstr *MI, int Op,
630 const MachineOperand &MO1 = MI->getOperand(Op);
631 const MachineOperand &MO2 = MI->getOperand(Op+1);
633 O << "[" << getRegisterName(MO1.getReg());
635 // FIXME: Both darwin as and GNU as violate ARM docs here.
636 O << ", :" << (MO2.getImm() << 3);
641 void ARMAsmPrinter::printAddrMode6OffsetOperand(const MachineInstr *MI, int Op,
643 const MachineOperand &MO = MI->getOperand(Op);
644 if (MO.getReg() == 0)
647 O << ", " << getRegisterName(MO.getReg());
650 void ARMAsmPrinter::printAddrModePCOperand(const MachineInstr *MI, int Op,
652 const char *Modifier) {
653 if (Modifier && strcmp(Modifier, "label") == 0) {
654 printPCLabel(MI, Op+1, O);
658 const MachineOperand &MO1 = MI->getOperand(Op);
659 assert(TargetRegisterInfo::isPhysicalRegister(MO1.getReg()));
660 O << "[pc, " << getRegisterName(MO1.getReg()) << "]";
664 ARMAsmPrinter::printBitfieldInvMaskImmOperand(const MachineInstr *MI, int Op,
666 const MachineOperand &MO = MI->getOperand(Op);
667 uint32_t v = ~MO.getImm();
668 int32_t lsb = CountTrailingZeros_32(v);
669 int32_t width = (32 - CountLeadingZeros_32 (v)) - lsb;
670 assert(MO.isImm() && "Not a valid bf_inv_mask_imm value!");
671 O << "#" << lsb << ", #" << width;
674 //===--------------------------------------------------------------------===//
676 void ARMAsmPrinter::printThumbS4ImmOperand(const MachineInstr *MI, int Op,
678 O << "#" << MI->getOperand(Op).getImm() * 4;
682 ARMAsmPrinter::printThumbITMask(const MachineInstr *MI, int Op,
684 // (3 - the number of trailing zeros) is the number of then / else.
685 unsigned Mask = MI->getOperand(Op).getImm();
686 unsigned CondBit0 = Mask >> 4 & 1;
687 unsigned NumTZ = CountTrailingZeros_32(Mask);
688 assert(NumTZ <= 3 && "Invalid IT mask!");
689 for (unsigned Pos = 3, e = NumTZ; Pos > e; --Pos) {
690 bool T = ((Mask >> Pos) & 1) == CondBit0;
699 ARMAsmPrinter::printThumbAddrModeRROperand(const MachineInstr *MI, int Op,
701 const MachineOperand &MO1 = MI->getOperand(Op);
702 const MachineOperand &MO2 = MI->getOperand(Op+1);
703 O << "[" << getRegisterName(MO1.getReg());
704 O << ", " << getRegisterName(MO2.getReg()) << "]";
708 ARMAsmPrinter::printThumbAddrModeRI5Operand(const MachineInstr *MI, int Op,
711 const MachineOperand &MO1 = MI->getOperand(Op);
712 const MachineOperand &MO2 = MI->getOperand(Op+1);
713 const MachineOperand &MO3 = MI->getOperand(Op+2);
715 if (!MO1.isReg()) { // FIXME: This is for CP entries, but isn't right.
716 printOperand(MI, Op, O);
720 O << "[" << getRegisterName(MO1.getReg());
722 O << ", " << getRegisterName(MO3.getReg());
723 else if (unsigned ImmOffs = MO2.getImm())
724 O << ", #" << ImmOffs * Scale;
729 ARMAsmPrinter::printThumbAddrModeS1Operand(const MachineInstr *MI, int Op,
731 printThumbAddrModeRI5Operand(MI, Op, O, 1);
734 ARMAsmPrinter::printThumbAddrModeS2Operand(const MachineInstr *MI, int Op,
736 printThumbAddrModeRI5Operand(MI, Op, O, 2);
739 ARMAsmPrinter::printThumbAddrModeS4Operand(const MachineInstr *MI, int Op,
741 printThumbAddrModeRI5Operand(MI, Op, O, 4);
744 void ARMAsmPrinter::printThumbAddrModeSPOperand(const MachineInstr *MI,int Op,
746 const MachineOperand &MO1 = MI->getOperand(Op);
747 const MachineOperand &MO2 = MI->getOperand(Op+1);
748 O << "[" << getRegisterName(MO1.getReg());
749 if (unsigned ImmOffs = MO2.getImm())
750 O << ", #" << ImmOffs*4;
754 //===--------------------------------------------------------------------===//
756 // Constant shifts t2_so_reg is a 2-operand unit corresponding to the Thumb2
757 // register with shift forms.
759 // REG IMM, SH_OPC - e.g. R5, LSL #3
760 void ARMAsmPrinter::printT2SOOperand(const MachineInstr *MI, int OpNum,
762 const MachineOperand &MO1 = MI->getOperand(OpNum);
763 const MachineOperand &MO2 = MI->getOperand(OpNum+1);
765 unsigned Reg = MO1.getReg();
766 assert(TargetRegisterInfo::isPhysicalRegister(Reg));
767 O << getRegisterName(Reg);
769 // Print the shift opc.
771 << ARM_AM::getShiftOpcStr(ARM_AM::getSORegShOp(MO2.getImm()))
774 assert(MO2.isImm() && "Not a valid t2_so_reg value!");
775 O << "#" << ARM_AM::getSORegOffset(MO2.getImm());
778 void ARMAsmPrinter::printT2AddrModeImm12Operand(const MachineInstr *MI,
781 const MachineOperand &MO1 = MI->getOperand(OpNum);
782 const MachineOperand &MO2 = MI->getOperand(OpNum+1);
784 O << "[" << getRegisterName(MO1.getReg());
786 unsigned OffImm = MO2.getImm();
787 if (OffImm) // Don't print +0.
788 O << ", #" << OffImm;
792 void ARMAsmPrinter::printT2AddrModeImm8Operand(const MachineInstr *MI,
795 const MachineOperand &MO1 = MI->getOperand(OpNum);
796 const MachineOperand &MO2 = MI->getOperand(OpNum+1);
798 O << "[" << getRegisterName(MO1.getReg());
800 int32_t OffImm = (int32_t)MO2.getImm();
803 O << ", #-" << -OffImm;
805 O << ", #" << OffImm;
809 void ARMAsmPrinter::printT2AddrModeImm8s4Operand(const MachineInstr *MI,
812 const MachineOperand &MO1 = MI->getOperand(OpNum);
813 const MachineOperand &MO2 = MI->getOperand(OpNum+1);
815 O << "[" << getRegisterName(MO1.getReg());
817 int32_t OffImm = (int32_t)MO2.getImm() / 4;
820 O << ", #-" << -OffImm * 4;
822 O << ", #" << OffImm * 4;
826 void ARMAsmPrinter::printT2AddrModeImm8OffsetOperand(const MachineInstr *MI,
829 const MachineOperand &MO1 = MI->getOperand(OpNum);
830 int32_t OffImm = (int32_t)MO1.getImm();
833 O << "#-" << -OffImm;
838 void ARMAsmPrinter::printT2AddrModeSoRegOperand(const MachineInstr *MI,
841 const MachineOperand &MO1 = MI->getOperand(OpNum);
842 const MachineOperand &MO2 = MI->getOperand(OpNum+1);
843 const MachineOperand &MO3 = MI->getOperand(OpNum+2);
845 O << "[" << getRegisterName(MO1.getReg());
847 assert(MO2.getReg() && "Invalid so_reg load / store address!");
848 O << ", " << getRegisterName(MO2.getReg());
850 unsigned ShAmt = MO3.getImm();
852 assert(ShAmt <= 3 && "Not a valid Thumb2 addressing mode!");
853 O << ", lsl #" << ShAmt;
859 //===--------------------------------------------------------------------===//
861 void ARMAsmPrinter::printPredicateOperand(const MachineInstr *MI, int OpNum,
863 ARMCC::CondCodes CC = (ARMCC::CondCodes)MI->getOperand(OpNum).getImm();
865 O << ARMCondCodeToString(CC);
868 void ARMAsmPrinter::printMandatoryPredicateOperand(const MachineInstr *MI,
871 ARMCC::CondCodes CC = (ARMCC::CondCodes)MI->getOperand(OpNum).getImm();
872 O << ARMCondCodeToString(CC);
875 void ARMAsmPrinter::printSBitModifierOperand(const MachineInstr *MI, int OpNum,
877 unsigned Reg = MI->getOperand(OpNum).getReg();
879 assert(Reg == ARM::CPSR && "Expect ARM CPSR register!");
884 void ARMAsmPrinter::printPCLabel(const MachineInstr *MI, int OpNum,
886 int Id = (int)MI->getOperand(OpNum).getImm();
887 O << MAI->getPrivateGlobalPrefix()
888 << "PC" << getFunctionNumber() << "_" << Id;
891 void ARMAsmPrinter::printRegisterList(const MachineInstr *MI, int OpNum,
894 for (unsigned i = OpNum, e = MI->getNumOperands(); i != e; ++i) {
895 if (MI->getOperand(i).isImplicit())
897 if ((int)i != OpNum) O << ", ";
898 printOperand(MI, i, O);
903 void ARMAsmPrinter::printCPInstOperand(const MachineInstr *MI, int OpNum,
904 raw_ostream &O, const char *Modifier) {
905 assert(Modifier && "This operand only works with a modifier!");
906 // There are two aspects to a CONSTANTPOOL_ENTRY operand, the label and the
908 if (!strcmp(Modifier, "label")) {
909 unsigned ID = MI->getOperand(OpNum).getImm();
910 OutStreamer.EmitLabel(GetCPISymbol(ID));
912 assert(!strcmp(Modifier, "cpentry") && "Unknown modifier for CPE");
913 unsigned CPI = MI->getOperand(OpNum).getIndex();
915 const MachineConstantPoolEntry &MCPE = MCP->getConstants()[CPI];
917 if (MCPE.isMachineConstantPoolEntry()) {
918 EmitMachineConstantPoolValue(MCPE.Val.MachineCPVal);
920 EmitGlobalConstant(MCPE.Val.ConstVal);
925 MCSymbol *ARMAsmPrinter::
926 GetARMSetPICJumpTableLabel2(unsigned uid, unsigned uid2,
927 const MachineBasicBlock *MBB) const {
928 SmallString<60> Name;
929 raw_svector_ostream(Name) << MAI->getPrivateGlobalPrefix()
930 << getFunctionNumber() << '_' << uid << '_' << uid2
931 << "_set_" << MBB->getNumber();
932 return OutContext.GetOrCreateSymbol(Name.str());
935 MCSymbol *ARMAsmPrinter::
936 GetARMJTIPICJumpTableLabel2(unsigned uid, unsigned uid2) const {
937 SmallString<60> Name;
938 raw_svector_ostream(Name) << MAI->getPrivateGlobalPrefix() << "JTI"
939 << getFunctionNumber() << '_' << uid << '_' << uid2;
940 return OutContext.GetOrCreateSymbol(Name.str());
943 void ARMAsmPrinter::printJTBlockOperand(const MachineInstr *MI, int OpNum,
945 assert(!Subtarget->isThumb2() && "Thumb2 should use double-jump jumptables!");
947 const MachineOperand &MO1 = MI->getOperand(OpNum);
948 const MachineOperand &MO2 = MI->getOperand(OpNum+1); // Unique Id
950 unsigned JTI = MO1.getIndex();
951 MCSymbol *JTISymbol = GetARMJTIPICJumpTableLabel2(JTI, MO2.getImm());
952 // Can't use EmitLabel until instprinter happens, label comes out in the wrong
954 O << "\n" << *JTISymbol << ":\n";
956 const char *JTEntryDirective = MAI->getData32bitsDirective();
958 const MachineJumpTableInfo *MJTI = MF->getJumpTableInfo();
959 const std::vector<MachineJumpTableEntry> &JT = MJTI->getJumpTables();
960 const std::vector<MachineBasicBlock*> &JTBBs = JT[JTI].MBBs;
961 bool UseSet= MAI->hasSetDirective() && TM.getRelocationModel() == Reloc::PIC_;
962 SmallPtrSet<MachineBasicBlock*, 8> JTSets;
963 for (unsigned i = 0, e = JTBBs.size(); i != e; ++i) {
964 MachineBasicBlock *MBB = JTBBs[i];
965 bool isNew = JTSets.insert(MBB);
967 if (UseSet && isNew) {
969 << *GetARMSetPICJumpTableLabel2(JTI, MO2.getImm(), MBB) << ','
970 << *MBB->getSymbol() << '-' << *JTISymbol << '\n';
973 O << JTEntryDirective << ' ';
975 O << *GetARMSetPICJumpTableLabel2(JTI, MO2.getImm(), MBB);
976 else if (TM.getRelocationModel() == Reloc::PIC_)
977 O << *MBB->getSymbol() << '-' << *JTISymbol;
979 O << *MBB->getSymbol();
986 void ARMAsmPrinter::printJT2BlockOperand(const MachineInstr *MI, int OpNum,
988 const MachineOperand &MO1 = MI->getOperand(OpNum);
989 const MachineOperand &MO2 = MI->getOperand(OpNum+1); // Unique Id
990 unsigned JTI = MO1.getIndex();
992 MCSymbol *JTISymbol = GetARMJTIPICJumpTableLabel2(JTI, MO2.getImm());
994 // Can't use EmitLabel until instprinter happens, label comes out in the wrong
996 O << "\n" << *JTISymbol << ":\n";
998 const MachineJumpTableInfo *MJTI = MF->getJumpTableInfo();
999 const std::vector<MachineJumpTableEntry> &JT = MJTI->getJumpTables();
1000 const std::vector<MachineBasicBlock*> &JTBBs = JT[JTI].MBBs;
1001 bool ByteOffset = false, HalfWordOffset = false;
1002 if (MI->getOpcode() == ARM::t2TBB)
1004 else if (MI->getOpcode() == ARM::t2TBH)
1005 HalfWordOffset = true;
1007 for (unsigned i = 0, e = JTBBs.size(); i != e; ++i) {
1008 MachineBasicBlock *MBB = JTBBs[i];
1010 O << MAI->getData8bitsDirective();
1011 else if (HalfWordOffset)
1012 O << MAI->getData16bitsDirective();
1014 if (ByteOffset || HalfWordOffset)
1015 O << '(' << *MBB->getSymbol() << "-" << *JTISymbol << ")/2";
1017 O << "\tb.w " << *MBB->getSymbol();
1024 void ARMAsmPrinter::printTBAddrMode(const MachineInstr *MI, int OpNum,
1026 O << "[pc, " << getRegisterName(MI->getOperand(OpNum).getReg());
1027 if (MI->getOpcode() == ARM::t2TBH)
1032 void ARMAsmPrinter::printNoHashImmediate(const MachineInstr *MI, int OpNum,
1034 O << MI->getOperand(OpNum).getImm();
1037 void ARMAsmPrinter::printVFPf32ImmOperand(const MachineInstr *MI, int OpNum,
1039 const ConstantFP *FP = MI->getOperand(OpNum).getFPImm();
1040 O << '#' << FP->getValueAPF().convertToFloat();
1042 O << "\t\t" << MAI->getCommentString() << ' ';
1043 WriteAsOperand(O, FP, /*PrintType=*/false);
1047 void ARMAsmPrinter::printVFPf64ImmOperand(const MachineInstr *MI, int OpNum,
1049 const ConstantFP *FP = MI->getOperand(OpNum).getFPImm();
1050 O << '#' << FP->getValueAPF().convertToDouble();
1052 O << "\t\t" << MAI->getCommentString() << ' ';
1053 WriteAsOperand(O, FP, /*PrintType=*/false);
1057 void ARMAsmPrinter::printNEONModImmOperand(const MachineInstr *MI, int OpNum,
1059 unsigned EncodedImm = MI->getOperand(OpNum).getImm();
1061 uint64_t Val = ARM_AM::decodeNEONModImm(EncodedImm, EltBits);
1062 O << "#0x" << utohexstr(Val);
1065 bool ARMAsmPrinter::PrintAsmOperand(const MachineInstr *MI, unsigned OpNum,
1066 unsigned AsmVariant, const char *ExtraCode,
1068 // Does this asm operand have a single letter operand modifier?
1069 if (ExtraCode && ExtraCode[0]) {
1070 if (ExtraCode[1] != 0) return true; // Unknown modifier.
1072 switch (ExtraCode[0]) {
1073 default: return true; // Unknown modifier.
1074 case 'a': // Print as a memory address.
1075 if (MI->getOperand(OpNum).isReg()) {
1076 O << "[" << getRegisterName(MI->getOperand(OpNum).getReg()) << "]";
1080 case 'c': // Don't print "#" before an immediate operand.
1081 if (!MI->getOperand(OpNum).isImm())
1083 printNoHashImmediate(MI, OpNum, O);
1085 case 'P': // Print a VFP double precision register.
1086 case 'q': // Print a NEON quad precision register.
1087 printOperand(MI, OpNum, O);
1092 report_fatal_error("llvm does not support 'Q', 'R', and 'H' modifiers!");
1097 printOperand(MI, OpNum, O);
1101 bool ARMAsmPrinter::PrintAsmMemoryOperand(const MachineInstr *MI,
1102 unsigned OpNum, unsigned AsmVariant,
1103 const char *ExtraCode,
1105 if (ExtraCode && ExtraCode[0])
1106 return true; // Unknown modifier.
1108 const MachineOperand &MO = MI->getOperand(OpNum);
1109 assert(MO.isReg() && "unexpected inline asm memory operand");
1110 O << "[" << getRegisterName(MO.getReg()) << "]";
1114 void ARMAsmPrinter::EmitInstruction(const MachineInstr *MI) {
1116 printInstructionThroughMCStreamer(MI);
1120 if (MI->getOpcode() == ARM::CONSTPOOL_ENTRY)
1123 SmallString<128> Str;
1124 raw_svector_ostream OS(Str);
1125 if (MI->getOpcode() == ARM::DBG_VALUE) {
1126 unsigned NOps = MI->getNumOperands();
1128 OS << '\t' << MAI->getCommentString() << "DEBUG_VALUE: ";
1129 // cast away const; DIetc do not take const operands for some reason.
1130 DIVariable V(const_cast<MDNode *>(MI->getOperand(NOps-1).getMetadata()));
1133 // Frame address. Currently handles register +- offset only.
1134 assert(MI->getOperand(0).isReg() && MI->getOperand(1).isImm());
1135 OS << '['; printOperand(MI, 0, OS); OS << '+'; printOperand(MI, 1, OS);
1138 printOperand(MI, NOps-2, OS);
1139 OutStreamer.EmitRawText(OS.str());
1143 printInstruction(MI, OS);
1144 OutStreamer.EmitRawText(OS.str());
1146 // Make sure the instruction that follows TBB is 2-byte aligned.
1147 // FIXME: Constant island pass should insert an "ALIGN" instruction instead.
1148 if (MI->getOpcode() == ARM::t2TBB)
1152 void ARMAsmPrinter::EmitStartOfAsmFile(Module &M) {
1153 if (Subtarget->isTargetDarwin()) {
1154 Reloc::Model RelocM = TM.getRelocationModel();
1155 if (RelocM == Reloc::PIC_ || RelocM == Reloc::DynamicNoPIC) {
1156 // Declare all the text sections up front (before the DWARF sections
1157 // emitted by AsmPrinter::doInitialization) so the assembler will keep
1158 // them together at the beginning of the object file. This helps
1159 // avoid out-of-range branches that are due a fundamental limitation of
1160 // the way symbol offsets are encoded with the current Darwin ARM
1162 const TargetLoweringObjectFileMachO &TLOFMacho =
1163 static_cast<const TargetLoweringObjectFileMachO &>(
1164 getObjFileLowering());
1165 OutStreamer.SwitchSection(TLOFMacho.getTextSection());
1166 OutStreamer.SwitchSection(TLOFMacho.getTextCoalSection());
1167 OutStreamer.SwitchSection(TLOFMacho.getConstTextCoalSection());
1168 if (RelocM == Reloc::DynamicNoPIC) {
1169 const MCSection *sect =
1170 OutContext.getMachOSection("__TEXT", "__symbol_stub4",
1171 MCSectionMachO::S_SYMBOL_STUBS,
1172 12, SectionKind::getText());
1173 OutStreamer.SwitchSection(sect);
1175 const MCSection *sect =
1176 OutContext.getMachOSection("__TEXT", "__picsymbolstub4",
1177 MCSectionMachO::S_SYMBOL_STUBS,
1178 16, SectionKind::getText());
1179 OutStreamer.SwitchSection(sect);
1181 const MCSection *StaticInitSect =
1182 OutContext.getMachOSection("__TEXT", "__StaticInit",
1183 MCSectionMachO::S_REGULAR |
1184 MCSectionMachO::S_ATTR_PURE_INSTRUCTIONS,
1185 SectionKind::getText());
1186 OutStreamer.SwitchSection(StaticInitSect);
1190 // Use unified assembler syntax.
1191 OutStreamer.EmitRawText(StringRef("\t.syntax unified"));
1193 // Emit ARM Build Attributes
1194 if (Subtarget->isTargetELF()) {
1196 std::string CPUString = Subtarget->getCPUString();
1197 if (CPUString != "generic")
1198 OutStreamer.EmitRawText("\t.cpu " + Twine(CPUString));
1200 // FIXME: Emit FPU type
1201 if (Subtarget->hasVFP2())
1202 OutStreamer.EmitRawText("\t.eabi_attribute " +
1203 Twine(ARMBuildAttrs::VFP_arch) + ", 2");
1205 // Signal various FP modes.
1206 if (!UnsafeFPMath) {
1207 OutStreamer.EmitRawText("\t.eabi_attribute " +
1208 Twine(ARMBuildAttrs::ABI_FP_denormal) + ", 1");
1209 OutStreamer.EmitRawText("\t.eabi_attribute " +
1210 Twine(ARMBuildAttrs::ABI_FP_exceptions) + ", 1");
1213 if (NoInfsFPMath && NoNaNsFPMath)
1214 OutStreamer.EmitRawText("\t.eabi_attribute " +
1215 Twine(ARMBuildAttrs::ABI_FP_number_model)+ ", 1");
1217 OutStreamer.EmitRawText("\t.eabi_attribute " +
1218 Twine(ARMBuildAttrs::ABI_FP_number_model)+ ", 3");
1220 // 8-bytes alignment stuff.
1221 OutStreamer.EmitRawText("\t.eabi_attribute " +
1222 Twine(ARMBuildAttrs::ABI_align8_needed) + ", 1");
1223 OutStreamer.EmitRawText("\t.eabi_attribute " +
1224 Twine(ARMBuildAttrs::ABI_align8_preserved) + ", 1");
1226 // Hard float. Use both S and D registers and conform to AAPCS-VFP.
1227 if (Subtarget->isAAPCS_ABI() && FloatABIType == FloatABI::Hard) {
1228 OutStreamer.EmitRawText("\t.eabi_attribute " +
1229 Twine(ARMBuildAttrs::ABI_HardFP_use) + ", 3");
1230 OutStreamer.EmitRawText("\t.eabi_attribute " +
1231 Twine(ARMBuildAttrs::ABI_VFP_args) + ", 1");
1233 // FIXME: Should we signal R9 usage?
1238 void ARMAsmPrinter::EmitEndOfAsmFile(Module &M) {
1239 if (Subtarget->isTargetDarwin()) {
1240 // All darwin targets use mach-o.
1241 const TargetLoweringObjectFileMachO &TLOFMacho =
1242 static_cast<const TargetLoweringObjectFileMachO &>(getObjFileLowering());
1243 MachineModuleInfoMachO &MMIMacho =
1244 MMI->getObjFileInfo<MachineModuleInfoMachO>();
1246 // Output non-lazy-pointers for external and common global variables.
1247 MachineModuleInfoMachO::SymbolListTy Stubs = MMIMacho.GetGVStubList();
1249 if (!Stubs.empty()) {
1250 // Switch with ".non_lazy_symbol_pointer" directive.
1251 OutStreamer.SwitchSection(TLOFMacho.getNonLazySymbolPointerSection());
1253 for (unsigned i = 0, e = Stubs.size(); i != e; ++i) {
1255 OutStreamer.EmitLabel(Stubs[i].first);
1256 // .indirect_symbol _foo
1257 MachineModuleInfoImpl::StubValueTy &MCSym = Stubs[i].second;
1258 OutStreamer.EmitSymbolAttribute(MCSym.getPointer(),MCSA_IndirectSymbol);
1261 // External to current translation unit.
1262 OutStreamer.EmitIntValue(0, 4/*size*/, 0/*addrspace*/);
1264 // Internal to current translation unit.
1266 // When we place the LSDA into the TEXT section, the type info pointers
1267 // need to be indirect and pc-rel. We accomplish this by using NLPs.
1268 // However, sometimes the types are local to the file. So we need to
1269 // fill in the value for the NLP in those cases.
1270 OutStreamer.EmitValue(MCSymbolRefExpr::Create(MCSym.getPointer(),
1272 4/*size*/, 0/*addrspace*/);
1276 OutStreamer.AddBlankLine();
1279 Stubs = MMIMacho.GetHiddenGVStubList();
1280 if (!Stubs.empty()) {
1281 OutStreamer.SwitchSection(getObjFileLowering().getDataSection());
1283 for (unsigned i = 0, e = Stubs.size(); i != e; ++i) {
1285 OutStreamer.EmitLabel(Stubs[i].first);
1287 OutStreamer.EmitValue(MCSymbolRefExpr::
1288 Create(Stubs[i].second.getPointer(),
1290 4/*size*/, 0/*addrspace*/);
1294 OutStreamer.AddBlankLine();
1297 // Funny Darwin hack: This flag tells the linker that no global symbols
1298 // contain code that falls through to other global symbols (e.g. the obvious
1299 // implementation of multiple entry points). If this doesn't occur, the
1300 // linker can safely perform dead code stripping. Since LLVM never
1301 // generates code that does this, it is always safe to set.
1302 OutStreamer.EmitAssemblerFlag(MCAF_SubsectionsViaSymbols);
1306 //===----------------------------------------------------------------------===//
1308 void ARMAsmPrinter::printInstructionThroughMCStreamer(const MachineInstr *MI) {
1309 ARMMCInstLower MCInstLowering(OutContext, *Mang, *this);
1310 switch (MI->getOpcode()) {
1311 case ARM::t2MOVi32imm:
1312 assert(0 && "Should be lowered by thumb2it pass");
1314 case ARM::PICADD: { // FIXME: Remove asm string from td file.
1315 // This is a pseudo op for a label + instruction sequence, which looks like:
1318 // This adds the address of LPC0 to r0.
1321 // FIXME: MOVE TO SHARED PLACE.
1322 unsigned Id = (unsigned)MI->getOperand(2).getImm();
1323 const char *Prefix = MAI->getPrivateGlobalPrefix();
1324 MCSymbol *Label =OutContext.GetOrCreateSymbol(Twine(Prefix)
1325 + "PC" + Twine(getFunctionNumber()) + "_" + Twine(Id));
1326 OutStreamer.EmitLabel(Label);
1329 // Form and emit tha dd.
1331 AddInst.setOpcode(ARM::ADDrr);
1332 AddInst.addOperand(MCOperand::CreateReg(MI->getOperand(0).getReg()));
1333 AddInst.addOperand(MCOperand::CreateReg(ARM::PC));
1334 AddInst.addOperand(MCOperand::CreateReg(MI->getOperand(1).getReg()));
1335 OutStreamer.EmitInstruction(AddInst);
1338 case ARM::CONSTPOOL_ENTRY: { // FIXME: Remove asm string from td file.
1339 /// CONSTPOOL_ENTRY - This instruction represents a floating constant pool
1340 /// in the function. The first operand is the ID# for this instruction, the
1341 /// second is the index into the MachineConstantPool that this is, the third
1342 /// is the size in bytes of this constant pool entry.
1343 unsigned LabelId = (unsigned)MI->getOperand(0).getImm();
1344 unsigned CPIdx = (unsigned)MI->getOperand(1).getIndex();
1347 OutStreamer.EmitLabel(GetCPISymbol(LabelId));
1349 const MachineConstantPoolEntry &MCPE = MCP->getConstants()[CPIdx];
1350 if (MCPE.isMachineConstantPoolEntry())
1351 EmitMachineConstantPoolValue(MCPE.Val.MachineCPVal);
1353 EmitGlobalConstant(MCPE.Val.ConstVal);
1357 case ARM::MOVi2pieces: { // FIXME: Remove asmstring from td file.
1358 // This is a hack that lowers as a two instruction sequence.
1359 unsigned DstReg = MI->getOperand(0).getReg();
1360 unsigned ImmVal = (unsigned)MI->getOperand(1).getImm();
1362 unsigned SOImmValV1 = ARM_AM::getSOImmTwoPartFirst(ImmVal);
1363 unsigned SOImmValV2 = ARM_AM::getSOImmTwoPartSecond(ImmVal);
1367 TmpInst.setOpcode(ARM::MOVi);
1368 TmpInst.addOperand(MCOperand::CreateReg(DstReg));
1369 TmpInst.addOperand(MCOperand::CreateImm(SOImmValV1));
1372 TmpInst.addOperand(MCOperand::CreateImm(MI->getOperand(2).getImm()));
1373 TmpInst.addOperand(MCOperand::CreateReg(MI->getOperand(3).getReg()));
1375 TmpInst.addOperand(MCOperand::CreateReg(0)); // cc_out
1376 OutStreamer.EmitInstruction(TmpInst);
1381 TmpInst.setOpcode(ARM::ORRri);
1382 TmpInst.addOperand(MCOperand::CreateReg(DstReg)); // dstreg
1383 TmpInst.addOperand(MCOperand::CreateReg(DstReg)); // inreg
1384 TmpInst.addOperand(MCOperand::CreateImm(SOImmValV2)); // so_imm
1386 TmpInst.addOperand(MCOperand::CreateImm(MI->getOperand(2).getImm()));
1387 TmpInst.addOperand(MCOperand::CreateReg(MI->getOperand(3).getReg()));
1389 TmpInst.addOperand(MCOperand::CreateReg(0)); // cc_out
1390 OutStreamer.EmitInstruction(TmpInst);
1394 case ARM::MOVi32imm: { // FIXME: Remove asmstring from td file.
1395 // This is a hack that lowers as a two instruction sequence.
1396 unsigned DstReg = MI->getOperand(0).getReg();
1397 const MachineOperand &MO = MI->getOperand(1);
1400 unsigned ImmVal = (unsigned)MI->getOperand(1).getImm();
1401 V1 = MCOperand::CreateImm(ImmVal & 65535);
1402 V2 = MCOperand::CreateImm(ImmVal >> 16);
1403 } else if (MO.isGlobal()) {
1404 MCSymbol *Symbol = MCInstLowering.GetGlobalAddressSymbol(MO);
1405 const MCSymbolRefExpr *SymRef1 =
1406 MCSymbolRefExpr::Create(Symbol,
1407 MCSymbolRefExpr::VK_ARM_LO16, OutContext);
1408 const MCSymbolRefExpr *SymRef2 =
1409 MCSymbolRefExpr::Create(Symbol,
1410 MCSymbolRefExpr::VK_ARM_HI16, OutContext);
1411 V1 = MCOperand::CreateExpr(SymRef1);
1412 V2 = MCOperand::CreateExpr(SymRef2);
1415 llvm_unreachable("cannot handle this operand");
1420 TmpInst.setOpcode(ARM::MOVi16);
1421 TmpInst.addOperand(MCOperand::CreateReg(DstReg)); // dstreg
1422 TmpInst.addOperand(V1); // lower16(imm)
1425 TmpInst.addOperand(MCOperand::CreateImm(MI->getOperand(2).getImm()));
1426 TmpInst.addOperand(MCOperand::CreateReg(MI->getOperand(3).getReg()));
1428 OutStreamer.EmitInstruction(TmpInst);
1433 TmpInst.setOpcode(ARM::MOVTi16);
1434 TmpInst.addOperand(MCOperand::CreateReg(DstReg)); // dstreg
1435 TmpInst.addOperand(MCOperand::CreateReg(DstReg)); // srcreg
1436 TmpInst.addOperand(V2); // upper16(imm)
1439 TmpInst.addOperand(MCOperand::CreateImm(MI->getOperand(2).getImm()));
1440 TmpInst.addOperand(MCOperand::CreateReg(MI->getOperand(3).getReg()));
1442 OutStreamer.EmitInstruction(TmpInst);
1450 MCInstLowering.Lower(MI, TmpInst);
1451 OutStreamer.EmitInstruction(TmpInst);
1454 //===----------------------------------------------------------------------===//
1455 // Target Registry Stuff
1456 //===----------------------------------------------------------------------===//
1458 static MCInstPrinter *createARMMCInstPrinter(const Target &T,
1459 unsigned SyntaxVariant,
1460 const MCAsmInfo &MAI) {
1461 if (SyntaxVariant == 0)
1462 return new ARMInstPrinter(MAI, false);
1466 // Force static initialization.
1467 extern "C" void LLVMInitializeARMAsmPrinter() {
1468 RegisterAsmPrinter<ARMAsmPrinter> X(TheARMTarget);
1469 RegisterAsmPrinter<ARMAsmPrinter> Y(TheThumbTarget);
1471 TargetRegistry::RegisterMCInstPrinter(TheARMTarget, createARMMCInstPrinter);
1472 TargetRegistry::RegisterMCInstPrinter(TheThumbTarget, createARMMCInstPrinter);