1 //===-- ARM/ARMCodeEmitter.cpp - Convert ARM code to machine code ---------===//
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 the pass that transforms the ARM machine instructions into
11 // relocatable machine code.
13 //===----------------------------------------------------------------------===//
15 #define DEBUG_TYPE "jit"
17 #include "ARMAddressingModes.h"
18 #include "ARMConstantPoolValue.h"
19 #include "ARMInstrInfo.h"
20 #include "ARMRelocations.h"
21 #include "ARMSubtarget.h"
22 #include "ARMTargetMachine.h"
23 #include "llvm/Constants.h"
24 #include "llvm/DerivedTypes.h"
25 #include "llvm/Function.h"
26 #include "llvm/PassManager.h"
27 #include "llvm/CodeGen/MachineCodeEmitter.h"
28 #include "llvm/CodeGen/JITCodeEmitter.h"
29 #include "llvm/CodeGen/ObjectCodeEmitter.h"
30 #include "llvm/CodeGen/MachineConstantPool.h"
31 #include "llvm/CodeGen/MachineFunctionPass.h"
32 #include "llvm/CodeGen/MachineInstr.h"
33 #include "llvm/CodeGen/MachineJumpTableInfo.h"
34 #include "llvm/CodeGen/Passes.h"
35 #include "llvm/ADT/Statistic.h"
36 #include "llvm/Support/Compiler.h"
37 #include "llvm/Support/Debug.h"
38 #include "llvm/Support/ErrorHandling.h"
39 #include "llvm/Support/raw_ostream.h"
45 STATISTIC(NumEmitted, "Number of machine instructions emitted");
49 class ARMCodeEmitter {
51 /// getBinaryCodeForInstr - This function, generated by the
52 /// CodeEmitterGenerator using TableGen, produces the binary encoding for
53 /// machine instructions.
54 unsigned getBinaryCodeForInstr(const MachineInstr &MI);
57 template<class CodeEmitter>
58 class VISIBILITY_HIDDEN Emitter : public MachineFunctionPass,
59 public ARMCodeEmitter {
61 const ARMInstrInfo *II;
65 const std::vector<MachineConstantPoolEntry> *MCPEs;
66 const std::vector<MachineJumpTableEntry> *MJTEs;
71 explicit Emitter(TargetMachine &tm, CodeEmitter &mce)
72 : MachineFunctionPass(&ID), JTI(0), II(0), TD(0), TM(tm),
73 MCE(mce), MCPEs(0), MJTEs(0),
74 IsPIC(TM.getRelocationModel() == Reloc::PIC_) {}
75 Emitter(TargetMachine &tm, CodeEmitter &mce,
76 const ARMInstrInfo &ii, const TargetData &td)
77 : MachineFunctionPass(&ID), JTI(0), II(&ii), TD(&td), TM(tm),
78 MCE(mce), MCPEs(0), MJTEs(0),
79 IsPIC(TM.getRelocationModel() == Reloc::PIC_) {}
81 bool runOnMachineFunction(MachineFunction &MF);
83 virtual const char *getPassName() const {
84 return "ARM Machine Code Emitter";
87 void emitInstruction(const MachineInstr &MI);
91 void emitWordLE(unsigned Binary);
93 void emitDWordLE(uint64_t Binary);
95 void emitConstPoolInstruction(const MachineInstr &MI);
97 void emitMOVi2piecesInstruction(const MachineInstr &MI);
99 void emitLEApcrelJTInstruction(const MachineInstr &MI);
101 void emitPseudoMoveInstruction(const MachineInstr &MI);
103 void addPCLabel(unsigned LabelID);
105 void emitPseudoInstruction(const MachineInstr &MI);
107 unsigned getMachineSoRegOpValue(const MachineInstr &MI,
108 const TargetInstrDesc &TID,
109 const MachineOperand &MO,
112 unsigned getMachineSoImmOpValue(unsigned SoImm);
114 unsigned getAddrModeSBit(const MachineInstr &MI,
115 const TargetInstrDesc &TID) const;
117 void emitDataProcessingInstruction(const MachineInstr &MI,
118 unsigned ImplicitRd = 0,
119 unsigned ImplicitRn = 0);
121 void emitLoadStoreInstruction(const MachineInstr &MI,
122 unsigned ImplicitRd = 0,
123 unsigned ImplicitRn = 0);
125 void emitMiscLoadStoreInstruction(const MachineInstr &MI,
126 unsigned ImplicitRn = 0);
128 void emitLoadStoreMultipleInstruction(const MachineInstr &MI);
130 void emitMulFrmInstruction(const MachineInstr &MI);
132 void emitExtendInstruction(const MachineInstr &MI);
134 void emitMiscArithInstruction(const MachineInstr &MI);
136 void emitBranchInstruction(const MachineInstr &MI);
138 void emitInlineJumpTable(unsigned JTIndex);
140 void emitMiscBranchInstruction(const MachineInstr &MI);
142 void emitVFPArithInstruction(const MachineInstr &MI);
144 void emitVFPConversionInstruction(const MachineInstr &MI);
146 void emitVFPLoadStoreInstruction(const MachineInstr &MI);
148 void emitVFPLoadStoreMultipleInstruction(const MachineInstr &MI);
150 void emitMiscInstruction(const MachineInstr &MI);
152 /// getMachineOpValue - Return binary encoding of operand. If the machine
153 /// operand requires relocation, record the relocation and return zero.
154 unsigned getMachineOpValue(const MachineInstr &MI,const MachineOperand &MO);
155 unsigned getMachineOpValue(const MachineInstr &MI, unsigned OpIdx) {
156 return getMachineOpValue(MI, MI.getOperand(OpIdx));
159 /// getShiftOp - Return the shift opcode (bit[6:5]) of the immediate value.
161 unsigned getShiftOp(unsigned Imm) const ;
163 /// Routines that handle operands which add machine relocations which are
164 /// fixed up by the relocation stage.
165 void emitGlobalAddress(GlobalValue *GV, unsigned Reloc,
166 bool NeedStub, intptr_t ACPV = 0);
167 void emitExternalSymbolAddress(const char *ES, unsigned Reloc);
168 void emitConstPoolAddress(unsigned CPI, unsigned Reloc);
169 void emitJumpTableAddress(unsigned JTIndex, unsigned Reloc);
170 void emitMachineBasicBlock(MachineBasicBlock *BB, unsigned Reloc,
171 intptr_t JTBase = 0);
173 template <class CodeEmitter>
174 char Emitter<CodeEmitter>::ID = 0;
177 /// createARMCodeEmitterPass - Return a pass that emits the collected ARM code
178 /// to the specified MCE object.
180 FunctionPass *llvm::createARMCodeEmitterPass(ARMBaseTargetMachine &TM,
181 MachineCodeEmitter &MCE) {
182 return new Emitter<MachineCodeEmitter>(TM, MCE);
184 FunctionPass *llvm::createARMJITCodeEmitterPass(ARMBaseTargetMachine &TM,
185 JITCodeEmitter &JCE) {
186 return new Emitter<JITCodeEmitter>(TM, JCE);
188 FunctionPass *llvm::createARMObjectCodeEmitterPass(ARMBaseTargetMachine &TM,
189 ObjectCodeEmitter &OCE) {
190 return new Emitter<ObjectCodeEmitter>(TM, OCE);
193 template<class CodeEmitter>
194 bool Emitter<CodeEmitter>::runOnMachineFunction(MachineFunction &MF) {
195 assert((MF.getTarget().getRelocationModel() != Reloc::Default ||
196 MF.getTarget().getRelocationModel() != Reloc::Static) &&
197 "JIT relocation model must be set to static or default!");
198 II = ((ARMTargetMachine&)MF.getTarget()).getInstrInfo();
199 TD = ((ARMTargetMachine&)MF.getTarget()).getTargetData();
200 JTI = ((ARMTargetMachine&)MF.getTarget()).getJITInfo();
201 MCPEs = &MF.getConstantPool()->getConstants();
202 MJTEs = &MF.getJumpTableInfo()->getJumpTables();
203 IsPIC = TM.getRelocationModel() == Reloc::PIC_;
204 JTI->Initialize(MF, IsPIC);
207 DEBUG(errs() << "JITTing function '"
208 << MF.getFunction()->getName() << "'\n");
209 MCE.startFunction(MF);
210 for (MachineFunction::iterator MBB = MF.begin(), E = MF.end();
212 MCE.StartMachineBasicBlock(MBB);
213 for (MachineBasicBlock::const_iterator I = MBB->begin(), E = MBB->end();
217 } while (MCE.finishFunction(MF));
222 /// getShiftOp - Return the shift opcode (bit[6:5]) of the immediate value.
224 template<class CodeEmitter>
225 unsigned Emitter<CodeEmitter>::getShiftOp(unsigned Imm) const {
226 switch (ARM_AM::getAM2ShiftOpc(Imm)) {
227 default: llvm_unreachable("Unknown shift opc!");
228 case ARM_AM::asr: return 2;
229 case ARM_AM::lsl: return 0;
230 case ARM_AM::lsr: return 1;
232 case ARM_AM::rrx: return 3;
237 /// getMachineOpValue - Return binary encoding of operand. If the machine
238 /// operand requires relocation, record the relocation and return zero.
239 template<class CodeEmitter>
240 unsigned Emitter<CodeEmitter>::getMachineOpValue(const MachineInstr &MI,
241 const MachineOperand &MO) {
243 return ARMRegisterInfo::getRegisterNumbering(MO.getReg());
245 return static_cast<unsigned>(MO.getImm());
246 else if (MO.isGlobal())
247 emitGlobalAddress(MO.getGlobal(), ARM::reloc_arm_branch, true);
248 else if (MO.isSymbol())
249 emitExternalSymbolAddress(MO.getSymbolName(), ARM::reloc_arm_branch);
250 else if (MO.isCPI()) {
251 const TargetInstrDesc &TID = MI.getDesc();
252 // For VFP load, the immediate offset is multiplied by 4.
253 unsigned Reloc = ((TID.TSFlags & ARMII::FormMask) == ARMII::VFPLdStFrm)
254 ? ARM::reloc_arm_vfp_cp_entry : ARM::reloc_arm_cp_entry;
255 emitConstPoolAddress(MO.getIndex(), Reloc);
256 } else if (MO.isJTI())
257 emitJumpTableAddress(MO.getIndex(), ARM::reloc_arm_relative);
259 emitMachineBasicBlock(MO.getMBB(), ARM::reloc_arm_branch);
269 /// emitGlobalAddress - Emit the specified address to the code stream.
271 template<class CodeEmitter>
272 void Emitter<CodeEmitter>::emitGlobalAddress(GlobalValue *GV, unsigned Reloc,
273 bool NeedStub, intptr_t ACPV) {
274 MCE.addRelocation(MachineRelocation::getGV(MCE.getCurrentPCOffset(), Reloc,
275 GV, ACPV, NeedStub));
278 /// emitExternalSymbolAddress - Arrange for the address of an external symbol to
279 /// be emitted to the current location in the function, and allow it to be PC
281 template<class CodeEmitter>
282 void Emitter<CodeEmitter>::emitExternalSymbolAddress(const char *ES,
284 MCE.addRelocation(MachineRelocation::getExtSym(MCE.getCurrentPCOffset(),
288 /// emitConstPoolAddress - Arrange for the address of an constant pool
289 /// to be emitted to the current location in the function, and allow it to be PC
291 template<class CodeEmitter>
292 void Emitter<CodeEmitter>::emitConstPoolAddress(unsigned CPI,
294 // Tell JIT emitter we'll resolve the address.
295 MCE.addRelocation(MachineRelocation::getConstPool(MCE.getCurrentPCOffset(),
296 Reloc, CPI, 0, true));
299 /// emitJumpTableAddress - Arrange for the address of a jump table to
300 /// be emitted to the current location in the function, and allow it to be PC
302 template<class CodeEmitter>
303 void Emitter<CodeEmitter>::emitJumpTableAddress(unsigned JTIndex,
305 MCE.addRelocation(MachineRelocation::getJumpTable(MCE.getCurrentPCOffset(),
306 Reloc, JTIndex, 0, true));
309 /// emitMachineBasicBlock - Emit the specified address basic block.
310 template<class CodeEmitter>
311 void Emitter<CodeEmitter>::emitMachineBasicBlock(MachineBasicBlock *BB,
312 unsigned Reloc, intptr_t JTBase) {
313 MCE.addRelocation(MachineRelocation::getBB(MCE.getCurrentPCOffset(),
317 template<class CodeEmitter>
318 void Emitter<CodeEmitter>::emitWordLE(unsigned Binary) {
319 DEBUG(errs() << " 0x";
320 errs().write_hex(Binary) << "\n");
321 MCE.emitWordLE(Binary);
324 template<class CodeEmitter>
325 void Emitter<CodeEmitter>::emitDWordLE(uint64_t Binary) {
326 DEBUG(errs() << " 0x";
327 errs().write_hex(Binary) << "\n");
328 MCE.emitDWordLE(Binary);
331 template<class CodeEmitter>
332 void Emitter<CodeEmitter>::emitInstruction(const MachineInstr &MI) {
333 DEBUG(errs() << "JIT: " << (void*)MCE.getCurrentPCValue() << ":\t" << MI);
335 MCE.processDebugLoc(MI.getDebugLoc());
337 NumEmitted++; // Keep track of the # of mi's emitted
338 switch (MI.getDesc().TSFlags & ARMII::FormMask) {
340 llvm_unreachable("Unhandled instruction encoding format!");
344 emitPseudoInstruction(MI);
347 case ARMII::DPSoRegFrm:
348 emitDataProcessingInstruction(MI);
352 emitLoadStoreInstruction(MI);
354 case ARMII::LdMiscFrm:
355 case ARMII::StMiscFrm:
356 emitMiscLoadStoreInstruction(MI);
358 case ARMII::LdStMulFrm:
359 emitLoadStoreMultipleInstruction(MI);
362 emitMulFrmInstruction(MI);
365 emitExtendInstruction(MI);
367 case ARMII::ArithMiscFrm:
368 emitMiscArithInstruction(MI);
371 emitBranchInstruction(MI);
373 case ARMII::BrMiscFrm:
374 emitMiscBranchInstruction(MI);
377 case ARMII::VFPUnaryFrm:
378 case ARMII::VFPBinaryFrm:
379 emitVFPArithInstruction(MI);
381 case ARMII::VFPConv1Frm:
382 case ARMII::VFPConv2Frm:
383 case ARMII::VFPConv3Frm:
384 case ARMII::VFPConv4Frm:
385 case ARMII::VFPConv5Frm:
386 emitVFPConversionInstruction(MI);
388 case ARMII::VFPLdStFrm:
389 emitVFPLoadStoreInstruction(MI);
391 case ARMII::VFPLdStMulFrm:
392 emitVFPLoadStoreMultipleInstruction(MI);
394 case ARMII::VFPMiscFrm:
395 emitMiscInstruction(MI);
400 template<class CodeEmitter>
401 void Emitter<CodeEmitter>::emitConstPoolInstruction(const MachineInstr &MI) {
402 unsigned CPI = MI.getOperand(0).getImm(); // CP instruction index.
403 unsigned CPIndex = MI.getOperand(1).getIndex(); // Actual cp entry index.
404 const MachineConstantPoolEntry &MCPE = (*MCPEs)[CPIndex];
406 // Remember the CONSTPOOL_ENTRY address for later relocation.
407 JTI->addConstantPoolEntryAddr(CPI, MCE.getCurrentPCValue());
409 // Emit constpool island entry. In most cases, the actual values will be
410 // resolved and relocated after code emission.
411 if (MCPE.isMachineConstantPoolEntry()) {
412 ARMConstantPoolValue *ACPV =
413 static_cast<ARMConstantPoolValue*>(MCPE.Val.MachineCPVal);
415 DEBUG(errs() << " ** ARM constant pool #" << CPI << " @ "
416 << (void*)MCE.getCurrentPCValue() << " " << *ACPV << '\n');
418 GlobalValue *GV = ACPV->getGV();
420 assert(!ACPV->isStub() && "Don't know how to deal this yet!");
421 if (ACPV->isNonLazyPointer())
422 MCE.addRelocation(MachineRelocation::getIndirectSymbol(
423 MCE.getCurrentPCOffset(), ARM::reloc_arm_machine_cp_entry, GV,
424 (intptr_t)ACPV, false));
426 emitGlobalAddress(GV, ARM::reloc_arm_machine_cp_entry,
427 ACPV->isStub() || isa<Function>(GV), (intptr_t)ACPV);
429 assert(!ACPV->isNonLazyPointer() && "Don't know how to deal this yet!");
430 emitExternalSymbolAddress(ACPV->getSymbol(), ARM::reloc_arm_absolute);
434 Constant *CV = MCPE.Val.ConstVal;
437 errs() << " ** Constant pool #" << CPI << " @ "
438 << (void*)MCE.getCurrentPCValue() << " ";
439 if (const Function *F = dyn_cast<Function>(CV))
440 errs() << F->getName();
446 if (GlobalValue *GV = dyn_cast<GlobalValue>(CV)) {
447 emitGlobalAddress(GV, ARM::reloc_arm_absolute, isa<Function>(GV));
449 } else if (const ConstantInt *CI = dyn_cast<ConstantInt>(CV)) {
450 uint32_t Val = *(uint32_t*)CI->getValue().getRawData();
452 } else if (const ConstantFP *CFP = dyn_cast<ConstantFP>(CV)) {
453 if (CFP->getType() == Type::getFloatTy(CFP->getContext()))
454 emitWordLE(CFP->getValueAPF().bitcastToAPInt().getZExtValue());
455 else if (CFP->getType() == Type::getDoubleTy(CFP->getContext()))
456 emitDWordLE(CFP->getValueAPF().bitcastToAPInt().getZExtValue());
458 llvm_unreachable("Unable to handle this constantpool entry!");
461 llvm_unreachable("Unable to handle this constantpool entry!");
466 template<class CodeEmitter>
467 void Emitter<CodeEmitter>::emitMOVi2piecesInstruction(const MachineInstr &MI) {
468 const MachineOperand &MO0 = MI.getOperand(0);
469 const MachineOperand &MO1 = MI.getOperand(1);
470 assert(MO1.isImm() && ARM_AM::getSOImmVal(MO1.isImm()) != -1 &&
471 "Not a valid so_imm value!");
472 unsigned V1 = ARM_AM::getSOImmTwoPartFirst(MO1.getImm());
473 unsigned V2 = ARM_AM::getSOImmTwoPartSecond(MO1.getImm());
475 // Emit the 'mov' instruction.
476 unsigned Binary = 0xd << 21; // mov: Insts{24-21} = 0b1101
478 // Set the conditional execution predicate.
479 Binary |= II->getPredicate(&MI) << ARMII::CondShift;
482 Binary |= getMachineOpValue(MI, MO0) << ARMII::RegRdShift;
485 // Set bit I(25) to identify this is the immediate form of <shifter_op>
486 Binary |= 1 << ARMII::I_BitShift;
487 Binary |= getMachineSoImmOpValue(V1);
490 // Now the 'orr' instruction.
491 Binary = 0xc << 21; // orr: Insts{24-21} = 0b1100
493 // Set the conditional execution predicate.
494 Binary |= II->getPredicate(&MI) << ARMII::CondShift;
497 Binary |= getMachineOpValue(MI, MO0) << ARMII::RegRdShift;
500 Binary |= getMachineOpValue(MI, MO0) << ARMII::RegRnShift;
503 // Set bit I(25) to identify this is the immediate form of <shifter_op>
504 Binary |= 1 << ARMII::I_BitShift;
505 Binary |= getMachineSoImmOpValue(V2);
509 template<class CodeEmitter>
510 void Emitter<CodeEmitter>::emitLEApcrelJTInstruction(const MachineInstr &MI) {
511 // It's basically add r, pc, (LJTI - $+8)
513 const TargetInstrDesc &TID = MI.getDesc();
515 // Emit the 'add' instruction.
516 unsigned Binary = 0x4 << 21; // add: Insts{24-31} = 0b0100
518 // Set the conditional execution predicate
519 Binary |= II->getPredicate(&MI) << ARMII::CondShift;
521 // Encode S bit if MI modifies CPSR.
522 Binary |= getAddrModeSBit(MI, TID);
525 Binary |= getMachineOpValue(MI, 0) << ARMII::RegRdShift;
527 // Encode Rn which is PC.
528 Binary |= ARMRegisterInfo::getRegisterNumbering(ARM::PC) << ARMII::RegRnShift;
530 // Encode the displacement.
531 Binary |= 1 << ARMII::I_BitShift;
532 emitJumpTableAddress(MI.getOperand(1).getIndex(), ARM::reloc_arm_jt_base);
537 template<class CodeEmitter>
538 void Emitter<CodeEmitter>::emitPseudoMoveInstruction(const MachineInstr &MI) {
539 unsigned Opcode = MI.getDesc().Opcode;
541 // Part of binary is determined by TableGn.
542 unsigned Binary = getBinaryCodeForInstr(MI);
544 // Set the conditional execution predicate
545 Binary |= II->getPredicate(&MI) << ARMII::CondShift;
547 // Encode S bit if MI modifies CPSR.
548 if (Opcode == ARM::MOVsrl_flag || Opcode == ARM::MOVsra_flag)
549 Binary |= 1 << ARMII::S_BitShift;
551 // Encode register def if there is one.
552 Binary |= getMachineOpValue(MI, 0) << ARMII::RegRdShift;
554 // Encode the shift operation.
561 case ARM::MOVsrl_flag:
563 Binary |= (0x2 << 4) | (1 << 7);
565 case ARM::MOVsra_flag:
567 Binary |= (0x4 << 4) | (1 << 7);
571 // Encode register Rm.
572 Binary |= getMachineOpValue(MI, 1);
577 template<class CodeEmitter>
578 void Emitter<CodeEmitter>::addPCLabel(unsigned LabelID) {
579 DEBUG(errs() << " ** LPC" << LabelID << " @ "
580 << (void*)MCE.getCurrentPCValue() << '\n');
581 JTI->addPCLabelAddr(LabelID, MCE.getCurrentPCValue());
584 template<class CodeEmitter>
585 void Emitter<CodeEmitter>::emitPseudoInstruction(const MachineInstr &MI) {
586 unsigned Opcode = MI.getDesc().Opcode;
589 llvm_unreachable("ARMCodeEmitter::emitPseudoInstruction");//FIXME:
590 case TargetInstrInfo::INLINEASM: {
591 // We allow inline assembler nodes with empty bodies - they can
592 // implicitly define registers, which is ok for JIT.
593 if (MI.getOperand(0).getSymbolName()[0]) {
594 llvm_report_error("JIT does not support inline asm!");
598 case TargetInstrInfo::DBG_LABEL:
599 case TargetInstrInfo::EH_LABEL:
600 MCE.emitLabel(MI.getOperand(0).getImm());
602 case TargetInstrInfo::IMPLICIT_DEF:
606 case ARM::CONSTPOOL_ENTRY:
607 emitConstPoolInstruction(MI);
610 // Remember of the address of the PC label for relocation later.
611 addPCLabel(MI.getOperand(2).getImm());
612 // PICADD is just an add instruction that implicitly read pc.
613 emitDataProcessingInstruction(MI, 0, ARM::PC);
620 // Remember of the address of the PC label for relocation later.
621 addPCLabel(MI.getOperand(2).getImm());
622 // These are just load / store instructions that implicitly read pc.
623 emitLoadStoreInstruction(MI, 0, ARM::PC);
630 // Remember of the address of the PC label for relocation later.
631 addPCLabel(MI.getOperand(2).getImm());
632 // These are just load / store instructions that implicitly read pc.
633 emitMiscLoadStoreInstruction(MI, ARM::PC);
636 case ARM::MOVi2pieces:
637 // Two instructions to materialize a constant.
638 emitMOVi2piecesInstruction(MI);
640 case ARM::LEApcrelJT:
641 // Materialize jumptable address.
642 emitLEApcrelJTInstruction(MI);
645 case ARM::MOVsrl_flag:
646 case ARM::MOVsra_flag:
647 emitPseudoMoveInstruction(MI);
652 template<class CodeEmitter>
653 unsigned Emitter<CodeEmitter>::getMachineSoRegOpValue(
654 const MachineInstr &MI,
655 const TargetInstrDesc &TID,
656 const MachineOperand &MO,
658 unsigned Binary = getMachineOpValue(MI, MO);
660 const MachineOperand &MO1 = MI.getOperand(OpIdx + 1);
661 const MachineOperand &MO2 = MI.getOperand(OpIdx + 2);
662 ARM_AM::ShiftOpc SOpc = ARM_AM::getSORegShOp(MO2.getImm());
664 // Encode the shift opcode.
666 unsigned Rs = MO1.getReg();
668 // Set shift operand (bit[7:4]).
673 // RRX - 0110 and bit[11:8] clear.
675 default: llvm_unreachable("Unknown shift opc!");
676 case ARM_AM::lsl: SBits = 0x1; break;
677 case ARM_AM::lsr: SBits = 0x3; break;
678 case ARM_AM::asr: SBits = 0x5; break;
679 case ARM_AM::ror: SBits = 0x7; break;
680 case ARM_AM::rrx: SBits = 0x6; break;
683 // Set shift operand (bit[6:4]).
689 default: llvm_unreachable("Unknown shift opc!");
690 case ARM_AM::lsl: SBits = 0x0; break;
691 case ARM_AM::lsr: SBits = 0x2; break;
692 case ARM_AM::asr: SBits = 0x4; break;
693 case ARM_AM::ror: SBits = 0x6; break;
696 Binary |= SBits << 4;
697 if (SOpc == ARM_AM::rrx)
700 // Encode the shift operation Rs or shift_imm (except rrx).
702 // Encode Rs bit[11:8].
703 assert(ARM_AM::getSORegOffset(MO2.getImm()) == 0);
705 (ARMRegisterInfo::getRegisterNumbering(Rs) << ARMII::RegRsShift);
708 // Encode shift_imm bit[11:7].
709 return Binary | ARM_AM::getSORegOffset(MO2.getImm()) << 7;
712 template<class CodeEmitter>
713 unsigned Emitter<CodeEmitter>::getMachineSoImmOpValue(unsigned SoImm) {
714 int SoImmVal = ARM_AM::getSOImmVal(SoImm);
715 assert(SoImmVal != -1 && "Not a valid so_imm value!");
717 // Encode rotate_imm.
718 unsigned Binary = (ARM_AM::getSOImmValRot((unsigned)SoImmVal) >> 1)
719 << ARMII::SoRotImmShift;
722 Binary |= ARM_AM::getSOImmValImm((unsigned)SoImmVal);
726 template<class CodeEmitter>
727 unsigned Emitter<CodeEmitter>::getAddrModeSBit(const MachineInstr &MI,
728 const TargetInstrDesc &TID) const {
729 for (unsigned i = MI.getNumOperands(), e = TID.getNumOperands(); i != e; --i){
730 const MachineOperand &MO = MI.getOperand(i-1);
731 if (MO.isReg() && MO.isDef() && MO.getReg() == ARM::CPSR)
732 return 1 << ARMII::S_BitShift;
737 template<class CodeEmitter>
738 void Emitter<CodeEmitter>::emitDataProcessingInstruction(
739 const MachineInstr &MI,
741 unsigned ImplicitRn) {
742 const TargetInstrDesc &TID = MI.getDesc();
744 if (TID.Opcode == ARM::BFC) {
745 llvm_report_error("ARMv6t2 JIT is not yet supported.");
748 // Part of binary is determined by TableGn.
749 unsigned Binary = getBinaryCodeForInstr(MI);
751 // Set the conditional execution predicate
752 Binary |= II->getPredicate(&MI) << ARMII::CondShift;
754 // Encode S bit if MI modifies CPSR.
755 Binary |= getAddrModeSBit(MI, TID);
757 // Encode register def if there is one.
758 unsigned NumDefs = TID.getNumDefs();
761 Binary |= getMachineOpValue(MI, OpIdx++) << ARMII::RegRdShift;
763 // Special handling for implicit use (e.g. PC).
764 Binary |= (ARMRegisterInfo::getRegisterNumbering(ImplicitRd)
765 << ARMII::RegRdShift);
767 // If this is a two-address operand, skip it. e.g. MOVCCr operand 1.
768 if (TID.getOperandConstraint(OpIdx, TOI::TIED_TO) != -1)
771 // Encode first non-shifter register operand if there is one.
772 bool isUnary = TID.TSFlags & ARMII::UnaryDP;
775 // Special handling for implicit use (e.g. PC).
776 Binary |= (ARMRegisterInfo::getRegisterNumbering(ImplicitRn)
777 << ARMII::RegRnShift);
779 Binary |= getMachineOpValue(MI, OpIdx) << ARMII::RegRnShift;
784 // Encode shifter operand.
785 const MachineOperand &MO = MI.getOperand(OpIdx);
786 if ((TID.TSFlags & ARMII::FormMask) == ARMII::DPSoRegFrm) {
788 emitWordLE(Binary | getMachineSoRegOpValue(MI, TID, MO, OpIdx));
793 // Encode register Rm.
794 emitWordLE(Binary | ARMRegisterInfo::getRegisterNumbering(MO.getReg()));
799 Binary |= getMachineSoImmOpValue((unsigned)MO.getImm());
804 template<class CodeEmitter>
805 void Emitter<CodeEmitter>::emitLoadStoreInstruction(
806 const MachineInstr &MI,
808 unsigned ImplicitRn) {
809 const TargetInstrDesc &TID = MI.getDesc();
810 unsigned Form = TID.TSFlags & ARMII::FormMask;
811 bool IsPrePost = (TID.TSFlags & ARMII::IndexModeMask) != 0;
813 // Part of binary is determined by TableGn.
814 unsigned Binary = getBinaryCodeForInstr(MI);
816 // Set the conditional execution predicate
817 Binary |= II->getPredicate(&MI) << ARMII::CondShift;
821 // Operand 0 of a pre- and post-indexed store is the address base
822 // writeback. Skip it.
823 bool Skipped = false;
824 if (IsPrePost && Form == ARMII::StFrm) {
831 // Special handling for implicit use (e.g. PC).
832 Binary |= (ARMRegisterInfo::getRegisterNumbering(ImplicitRd)
833 << ARMII::RegRdShift);
835 Binary |= getMachineOpValue(MI, OpIdx++) << ARMII::RegRdShift;
837 // Set second operand
839 // Special handling for implicit use (e.g. PC).
840 Binary |= (ARMRegisterInfo::getRegisterNumbering(ImplicitRn)
841 << ARMII::RegRnShift);
843 Binary |= getMachineOpValue(MI, OpIdx++) << ARMII::RegRnShift;
845 // If this is a two-address operand, skip it. e.g. LDR_PRE.
846 if (!Skipped && TID.getOperandConstraint(OpIdx, TOI::TIED_TO) != -1)
849 const MachineOperand &MO2 = MI.getOperand(OpIdx);
850 unsigned AM2Opc = (ImplicitRn == ARM::PC)
851 ? 0 : MI.getOperand(OpIdx+1).getImm();
853 // Set bit U(23) according to sign of immed value (positive or negative).
854 Binary |= ((ARM_AM::getAM2Op(AM2Opc) == ARM_AM::add ? 1 : 0) <<
856 if (!MO2.getReg()) { // is immediate
857 if (ARM_AM::getAM2Offset(AM2Opc))
858 // Set the value of offset_12 field
859 Binary |= ARM_AM::getAM2Offset(AM2Opc);
864 // Set bit I(25), because this is not in immediate enconding.
865 Binary |= 1 << ARMII::I_BitShift;
866 assert(TargetRegisterInfo::isPhysicalRegister(MO2.getReg()));
867 // Set bit[3:0] to the corresponding Rm register
868 Binary |= ARMRegisterInfo::getRegisterNumbering(MO2.getReg());
870 // If this instr is in scaled register offset/index instruction, set
871 // shift_immed(bit[11:7]) and shift(bit[6:5]) fields.
872 if (unsigned ShImm = ARM_AM::getAM2Offset(AM2Opc)) {
873 Binary |= getShiftOp(AM2Opc) << ARMII::ShiftImmShift; // shift
874 Binary |= ShImm << ARMII::ShiftShift; // shift_immed
880 template<class CodeEmitter>
881 void Emitter<CodeEmitter>::emitMiscLoadStoreInstruction(const MachineInstr &MI,
882 unsigned ImplicitRn) {
883 const TargetInstrDesc &TID = MI.getDesc();
884 unsigned Form = TID.TSFlags & ARMII::FormMask;
885 bool IsPrePost = (TID.TSFlags & ARMII::IndexModeMask) != 0;
887 // Part of binary is determined by TableGn.
888 unsigned Binary = getBinaryCodeForInstr(MI);
890 // Set the conditional execution predicate
891 Binary |= II->getPredicate(&MI) << ARMII::CondShift;
895 // Operand 0 of a pre- and post-indexed store is the address base
896 // writeback. Skip it.
897 bool Skipped = false;
898 if (IsPrePost && Form == ARMII::StMiscFrm) {
904 Binary |= getMachineOpValue(MI, OpIdx++) << ARMII::RegRdShift;
906 // Skip LDRD and STRD's second operand.
907 if (TID.Opcode == ARM::LDRD || TID.Opcode == ARM::STRD)
910 // Set second operand
912 // Special handling for implicit use (e.g. PC).
913 Binary |= (ARMRegisterInfo::getRegisterNumbering(ImplicitRn)
914 << ARMII::RegRnShift);
916 Binary |= getMachineOpValue(MI, OpIdx++) << ARMII::RegRnShift;
918 // If this is a two-address operand, skip it. e.g. LDRH_POST.
919 if (!Skipped && TID.getOperandConstraint(OpIdx, TOI::TIED_TO) != -1)
922 const MachineOperand &MO2 = MI.getOperand(OpIdx);
923 unsigned AM3Opc = (ImplicitRn == ARM::PC)
924 ? 0 : MI.getOperand(OpIdx+1).getImm();
926 // Set bit U(23) according to sign of immed value (positive or negative)
927 Binary |= ((ARM_AM::getAM3Op(AM3Opc) == ARM_AM::add ? 1 : 0) <<
930 // If this instr is in register offset/index encoding, set bit[3:0]
931 // to the corresponding Rm register.
933 Binary |= ARMRegisterInfo::getRegisterNumbering(MO2.getReg());
938 // This instr is in immediate offset/index encoding, set bit 22 to 1.
939 Binary |= 1 << ARMII::AM3_I_BitShift;
940 if (unsigned ImmOffs = ARM_AM::getAM3Offset(AM3Opc)) {
942 Binary |= (ImmOffs >> 4) << ARMII::ImmHiShift; // immedH
943 Binary |= (ImmOffs & 0xF); // immedL
949 static unsigned getAddrModeUPBits(unsigned Mode) {
952 // Set addressing mode by modifying bits U(23) and P(24)
953 // IA - Increment after - bit U = 1 and bit P = 0
954 // IB - Increment before - bit U = 1 and bit P = 1
955 // DA - Decrement after - bit U = 0 and bit P = 0
956 // DB - Decrement before - bit U = 0 and bit P = 1
958 default: llvm_unreachable("Unknown addressing sub-mode!");
959 case ARM_AM::da: break;
960 case ARM_AM::db: Binary |= 0x1 << ARMII::P_BitShift; break;
961 case ARM_AM::ia: Binary |= 0x1 << ARMII::U_BitShift; break;
962 case ARM_AM::ib: Binary |= 0x3 << ARMII::U_BitShift; break;
968 template<class CodeEmitter>
969 void Emitter<CodeEmitter>::emitLoadStoreMultipleInstruction(
970 const MachineInstr &MI) {
971 // Part of binary is determined by TableGn.
972 unsigned Binary = getBinaryCodeForInstr(MI);
974 // Set the conditional execution predicate
975 Binary |= II->getPredicate(&MI) << ARMII::CondShift;
977 // Set base address operand
978 Binary |= getMachineOpValue(MI, 0) << ARMII::RegRnShift;
980 // Set addressing mode by modifying bits U(23) and P(24)
981 const MachineOperand &MO = MI.getOperand(1);
982 Binary |= getAddrModeUPBits(ARM_AM::getAM4SubMode(MO.getImm()));
985 if (ARM_AM::getAM4WBFlag(MO.getImm()))
986 Binary |= 0x1 << ARMII::W_BitShift;
989 for (unsigned i = 4, e = MI.getNumOperands(); i != e; ++i) {
990 const MachineOperand &MO = MI.getOperand(i);
991 if (!MO.isReg() || MO.isImplicit())
993 unsigned RegNum = ARMRegisterInfo::getRegisterNumbering(MO.getReg());
994 assert(TargetRegisterInfo::isPhysicalRegister(MO.getReg()) &&
996 Binary |= 0x1 << RegNum;
1002 template<class CodeEmitter>
1003 void Emitter<CodeEmitter>::emitMulFrmInstruction(const MachineInstr &MI) {
1004 const TargetInstrDesc &TID = MI.getDesc();
1006 // Part of binary is determined by TableGn.
1007 unsigned Binary = getBinaryCodeForInstr(MI);
1009 // Set the conditional execution predicate
1010 Binary |= II->getPredicate(&MI) << ARMII::CondShift;
1012 // Encode S bit if MI modifies CPSR.
1013 Binary |= getAddrModeSBit(MI, TID);
1015 // 32x32->64bit operations have two destination registers. The number
1016 // of register definitions will tell us if that's what we're dealing with.
1018 if (TID.getNumDefs() == 2)
1019 Binary |= getMachineOpValue (MI, OpIdx++) << ARMII::RegRdLoShift;
1022 Binary |= getMachineOpValue(MI, OpIdx++) << ARMII::RegRdHiShift;
1025 Binary |= getMachineOpValue(MI, OpIdx++);
1028 Binary |= getMachineOpValue(MI, OpIdx++) << ARMII::RegRsShift;
1030 // Many multiple instructions (e.g. MLA) have three src operands. Encode
1031 // it as Rn (for multiply, that's in the same offset as RdLo.
1032 if (TID.getNumOperands() > OpIdx &&
1033 !TID.OpInfo[OpIdx].isPredicate() &&
1034 !TID.OpInfo[OpIdx].isOptionalDef())
1035 Binary |= getMachineOpValue(MI, OpIdx) << ARMII::RegRdLoShift;
1040 template<class CodeEmitter>
1041 void Emitter<CodeEmitter>::emitExtendInstruction(const MachineInstr &MI) {
1042 const TargetInstrDesc &TID = MI.getDesc();
1044 // Part of binary is determined by TableGn.
1045 unsigned Binary = getBinaryCodeForInstr(MI);
1047 // Set the conditional execution predicate
1048 Binary |= II->getPredicate(&MI) << ARMII::CondShift;
1053 Binary |= getMachineOpValue(MI, OpIdx++) << ARMII::RegRdShift;
1055 const MachineOperand &MO1 = MI.getOperand(OpIdx++);
1056 const MachineOperand &MO2 = MI.getOperand(OpIdx);
1058 // Two register operand form.
1060 Binary |= getMachineOpValue(MI, MO1) << ARMII::RegRnShift;
1063 Binary |= getMachineOpValue(MI, MO2);
1066 Binary |= getMachineOpValue(MI, MO1);
1069 // Encode rot imm (0, 8, 16, or 24) if it has a rotate immediate operand.
1070 if (MI.getOperand(OpIdx).isImm() &&
1071 !TID.OpInfo[OpIdx].isPredicate() &&
1072 !TID.OpInfo[OpIdx].isOptionalDef())
1073 Binary |= (getMachineOpValue(MI, OpIdx) / 8) << ARMII::ExtRotImmShift;
1078 template<class CodeEmitter>
1079 void Emitter<CodeEmitter>::emitMiscArithInstruction(const MachineInstr &MI) {
1080 const TargetInstrDesc &TID = MI.getDesc();
1082 // Part of binary is determined by TableGn.
1083 unsigned Binary = getBinaryCodeForInstr(MI);
1085 // Set the conditional execution predicate
1086 Binary |= II->getPredicate(&MI) << ARMII::CondShift;
1091 Binary |= getMachineOpValue(MI, OpIdx++) << ARMII::RegRdShift;
1093 const MachineOperand &MO = MI.getOperand(OpIdx++);
1094 if (OpIdx == TID.getNumOperands() ||
1095 TID.OpInfo[OpIdx].isPredicate() ||
1096 TID.OpInfo[OpIdx].isOptionalDef()) {
1097 // Encode Rm and it's done.
1098 Binary |= getMachineOpValue(MI, MO);
1104 Binary |= getMachineOpValue(MI, MO) << ARMII::RegRnShift;
1107 Binary |= getMachineOpValue(MI, OpIdx++);
1109 // Encode shift_imm.
1110 unsigned ShiftAmt = MI.getOperand(OpIdx).getImm();
1111 assert(ShiftAmt < 32 && "shift_imm range is 0 to 31!");
1112 Binary |= ShiftAmt << ARMII::ShiftShift;
1117 template<class CodeEmitter>
1118 void Emitter<CodeEmitter>::emitBranchInstruction(const MachineInstr &MI) {
1119 const TargetInstrDesc &TID = MI.getDesc();
1121 if (TID.Opcode == ARM::TPsoft) {
1122 llvm_unreachable("ARM::TPsoft FIXME"); // FIXME
1125 // Part of binary is determined by TableGn.
1126 unsigned Binary = getBinaryCodeForInstr(MI);
1128 // Set the conditional execution predicate
1129 Binary |= II->getPredicate(&MI) << ARMII::CondShift;
1131 // Set signed_immed_24 field
1132 Binary |= getMachineOpValue(MI, 0);
1137 template<class CodeEmitter>
1138 void Emitter<CodeEmitter>::emitInlineJumpTable(unsigned JTIndex) {
1139 // Remember the base address of the inline jump table.
1140 uintptr_t JTBase = MCE.getCurrentPCValue();
1141 JTI->addJumpTableBaseAddr(JTIndex, JTBase);
1142 DEBUG(errs() << " ** Jump Table #" << JTIndex << " @ " << (void*)JTBase
1145 // Now emit the jump table entries.
1146 const std::vector<MachineBasicBlock*> &MBBs = (*MJTEs)[JTIndex].MBBs;
1147 for (unsigned i = 0, e = MBBs.size(); i != e; ++i) {
1149 // DestBB address - JT base.
1150 emitMachineBasicBlock(MBBs[i], ARM::reloc_arm_pic_jt, JTBase);
1152 // Absolute DestBB address.
1153 emitMachineBasicBlock(MBBs[i], ARM::reloc_arm_absolute);
1158 template<class CodeEmitter>
1159 void Emitter<CodeEmitter>::emitMiscBranchInstruction(const MachineInstr &MI) {
1160 const TargetInstrDesc &TID = MI.getDesc();
1162 // Handle jump tables.
1163 if (TID.Opcode == ARM::BR_JTr || TID.Opcode == ARM::BR_JTadd) {
1164 // First emit a ldr pc, [] instruction.
1165 emitDataProcessingInstruction(MI, ARM::PC);
1167 // Then emit the inline jump table.
1169 (TID.Opcode == ARM::BR_JTr)
1170 ? MI.getOperand(1).getIndex() : MI.getOperand(2).getIndex();
1171 emitInlineJumpTable(JTIndex);
1173 } else if (TID.Opcode == ARM::BR_JTm) {
1174 // First emit a ldr pc, [] instruction.
1175 emitLoadStoreInstruction(MI, ARM::PC);
1177 // Then emit the inline jump table.
1178 emitInlineJumpTable(MI.getOperand(3).getIndex());
1182 // Part of binary is determined by TableGn.
1183 unsigned Binary = getBinaryCodeForInstr(MI);
1185 // Set the conditional execution predicate
1186 Binary |= II->getPredicate(&MI) << ARMII::CondShift;
1188 if (TID.Opcode == ARM::BX_RET)
1189 // The return register is LR.
1190 Binary |= ARMRegisterInfo::getRegisterNumbering(ARM::LR);
1192 // otherwise, set the return register
1193 Binary |= getMachineOpValue(MI, 0);
1198 static unsigned encodeVFPRd(const MachineInstr &MI, unsigned OpIdx) {
1199 unsigned RegD = MI.getOperand(OpIdx).getReg();
1200 unsigned Binary = 0;
1201 bool isSPVFP = false;
1202 RegD = ARMRegisterInfo::getRegisterNumbering(RegD, &isSPVFP);
1204 Binary |= RegD << ARMII::RegRdShift;
1206 Binary |= ((RegD & 0x1E) >> 1) << ARMII::RegRdShift;
1207 Binary |= (RegD & 0x01) << ARMII::D_BitShift;
1212 static unsigned encodeVFPRn(const MachineInstr &MI, unsigned OpIdx) {
1213 unsigned RegN = MI.getOperand(OpIdx).getReg();
1214 unsigned Binary = 0;
1215 bool isSPVFP = false;
1216 RegN = ARMRegisterInfo::getRegisterNumbering(RegN, &isSPVFP);
1218 Binary |= RegN << ARMII::RegRnShift;
1220 Binary |= ((RegN & 0x1E) >> 1) << ARMII::RegRnShift;
1221 Binary |= (RegN & 0x01) << ARMII::N_BitShift;
1226 static unsigned encodeVFPRm(const MachineInstr &MI, unsigned OpIdx) {
1227 unsigned RegM = MI.getOperand(OpIdx).getReg();
1228 unsigned Binary = 0;
1229 bool isSPVFP = false;
1230 RegM = ARMRegisterInfo::getRegisterNumbering(RegM, &isSPVFP);
1234 Binary |= ((RegM & 0x1E) >> 1);
1235 Binary |= (RegM & 0x01) << ARMII::M_BitShift;
1240 template<class CodeEmitter>
1241 void Emitter<CodeEmitter>::emitVFPArithInstruction(const MachineInstr &MI) {
1242 const TargetInstrDesc &TID = MI.getDesc();
1244 // Part of binary is determined by TableGn.
1245 unsigned Binary = getBinaryCodeForInstr(MI);
1247 // Set the conditional execution predicate
1248 Binary |= II->getPredicate(&MI) << ARMII::CondShift;
1251 assert((Binary & ARMII::D_BitShift) == 0 &&
1252 (Binary & ARMII::N_BitShift) == 0 &&
1253 (Binary & ARMII::M_BitShift) == 0 && "VFP encoding bug!");
1256 Binary |= encodeVFPRd(MI, OpIdx++);
1258 // If this is a two-address operand, skip it, e.g. FMACD.
1259 if (TID.getOperandConstraint(OpIdx, TOI::TIED_TO) != -1)
1263 if ((TID.TSFlags & ARMII::FormMask) == ARMII::VFPBinaryFrm)
1264 Binary |= encodeVFPRn(MI, OpIdx++);
1266 if (OpIdx == TID.getNumOperands() ||
1267 TID.OpInfo[OpIdx].isPredicate() ||
1268 TID.OpInfo[OpIdx].isOptionalDef()) {
1269 // FCMPEZD etc. has only one operand.
1275 Binary |= encodeVFPRm(MI, OpIdx);
1280 template<class CodeEmitter>
1281 void Emitter<CodeEmitter>::emitVFPConversionInstruction(
1282 const MachineInstr &MI) {
1283 const TargetInstrDesc &TID = MI.getDesc();
1284 unsigned Form = TID.TSFlags & ARMII::FormMask;
1286 // Part of binary is determined by TableGn.
1287 unsigned Binary = getBinaryCodeForInstr(MI);
1289 // Set the conditional execution predicate
1290 Binary |= II->getPredicate(&MI) << ARMII::CondShift;
1294 case ARMII::VFPConv1Frm:
1295 case ARMII::VFPConv2Frm:
1296 case ARMII::VFPConv3Frm:
1298 Binary |= encodeVFPRd(MI, 0);
1300 case ARMII::VFPConv4Frm:
1302 Binary |= encodeVFPRn(MI, 0);
1304 case ARMII::VFPConv5Frm:
1306 Binary |= encodeVFPRm(MI, 0);
1312 case ARMII::VFPConv1Frm:
1314 Binary |= encodeVFPRm(MI, 1);
1316 case ARMII::VFPConv2Frm:
1317 case ARMII::VFPConv3Frm:
1319 Binary |= encodeVFPRn(MI, 1);
1321 case ARMII::VFPConv4Frm:
1322 case ARMII::VFPConv5Frm:
1324 Binary |= encodeVFPRd(MI, 1);
1328 if (Form == ARMII::VFPConv5Frm)
1330 Binary |= encodeVFPRn(MI, 2);
1331 else if (Form == ARMII::VFPConv3Frm)
1333 Binary |= encodeVFPRm(MI, 2);
1338 template<class CodeEmitter>
1339 void Emitter<CodeEmitter>::emitVFPLoadStoreInstruction(const MachineInstr &MI) {
1340 // Part of binary is determined by TableGn.
1341 unsigned Binary = getBinaryCodeForInstr(MI);
1343 // Set the conditional execution predicate
1344 Binary |= II->getPredicate(&MI) << ARMII::CondShift;
1349 Binary |= encodeVFPRd(MI, OpIdx++);
1351 // Encode address base.
1352 const MachineOperand &Base = MI.getOperand(OpIdx++);
1353 Binary |= getMachineOpValue(MI, Base) << ARMII::RegRnShift;
1355 // If there is a non-zero immediate offset, encode it.
1357 const MachineOperand &Offset = MI.getOperand(OpIdx);
1358 if (unsigned ImmOffs = ARM_AM::getAM5Offset(Offset.getImm())) {
1359 if (ARM_AM::getAM5Op(Offset.getImm()) == ARM_AM::add)
1360 Binary |= 1 << ARMII::U_BitShift;
1367 // If immediate offset is omitted, default to +0.
1368 Binary |= 1 << ARMII::U_BitShift;
1373 template<class CodeEmitter>
1374 void Emitter<CodeEmitter>::emitVFPLoadStoreMultipleInstruction(
1375 const MachineInstr &MI) {
1376 // Part of binary is determined by TableGn.
1377 unsigned Binary = getBinaryCodeForInstr(MI);
1379 // Set the conditional execution predicate
1380 Binary |= II->getPredicate(&MI) << ARMII::CondShift;
1382 // Set base address operand
1383 Binary |= getMachineOpValue(MI, 0) << ARMII::RegRnShift;
1385 // Set addressing mode by modifying bits U(23) and P(24)
1386 const MachineOperand &MO = MI.getOperand(1);
1387 Binary |= getAddrModeUPBits(ARM_AM::getAM5SubMode(MO.getImm()));
1390 if (ARM_AM::getAM5WBFlag(MO.getImm()))
1391 Binary |= 0x1 << ARMII::W_BitShift;
1393 // First register is encoded in Dd.
1394 Binary |= encodeVFPRd(MI, 4);
1396 // Number of registers are encoded in offset field.
1397 unsigned NumRegs = 1;
1398 for (unsigned i = 5, e = MI.getNumOperands(); i != e; ++i) {
1399 const MachineOperand &MO = MI.getOperand(i);
1400 if (!MO.isReg() || MO.isImplicit())
1404 Binary |= NumRegs * 2;
1409 template<class CodeEmitter>
1410 void Emitter<CodeEmitter>::emitMiscInstruction(const MachineInstr &MI) {
1411 // Part of binary is determined by TableGn.
1412 unsigned Binary = getBinaryCodeForInstr(MI);
1414 // Set the conditional execution predicate
1415 Binary |= II->getPredicate(&MI) << ARMII::CondShift;
1420 #include "ARMGenCodeEmitter.inc"