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/JITCodeEmitter.h"
28 #include "llvm/CodeGen/MachineConstantPool.h"
29 #include "llvm/CodeGen/MachineFunctionPass.h"
30 #include "llvm/CodeGen/MachineInstr.h"
31 #include "llvm/CodeGen/MachineJumpTableInfo.h"
32 #include "llvm/CodeGen/MachineModuleInfo.h"
33 #include "llvm/CodeGen/Passes.h"
34 #include "llvm/ADT/Statistic.h"
35 #include "llvm/Support/Debug.h"
36 #include "llvm/Support/ErrorHandling.h"
37 #include "llvm/Support/raw_ostream.h"
43 STATISTIC(NumEmitted, "Number of machine instructions emitted");
47 class ARMCodeEmitter : public MachineFunctionPass {
49 const ARMInstrInfo *II;
51 const ARMSubtarget *Subtarget;
54 MachineModuleInfo *MMI;
55 const std::vector<MachineConstantPoolEntry> *MCPEs;
56 const std::vector<MachineJumpTableEntry> *MJTEs;
59 void getAnalysisUsage(AnalysisUsage &AU) const {
60 AU.addRequired<MachineModuleInfo>();
61 MachineFunctionPass::getAnalysisUsage(AU);
66 ARMCodeEmitter(TargetMachine &tm, JITCodeEmitter &mce)
67 : MachineFunctionPass(&ID), JTI(0), II((ARMInstrInfo*)tm.getInstrInfo()),
68 TD(tm.getTargetData()), TM(tm),
69 MCE(mce), MCPEs(0), MJTEs(0),
70 IsPIC(TM.getRelocationModel() == Reloc::PIC_) {}
72 /// getBinaryCodeForInstr - This function, generated by the
73 /// CodeEmitterGenerator using TableGen, produces the binary encoding for
74 /// machine instructions.
75 unsigned getBinaryCodeForInstr(const MachineInstr &MI);
77 bool runOnMachineFunction(MachineFunction &MF);
79 virtual const char *getPassName() const {
80 return "ARM Machine Code Emitter";
83 void emitInstruction(const MachineInstr &MI);
87 void emitWordLE(unsigned Binary);
88 void emitDWordLE(uint64_t Binary);
89 void emitConstPoolInstruction(const MachineInstr &MI);
90 void emitMOVi2piecesInstruction(const MachineInstr &MI);
91 void emitLEApcrelJTInstruction(const MachineInstr &MI);
92 void emitPseudoMoveInstruction(const MachineInstr &MI);
93 void addPCLabel(unsigned LabelID);
94 void emitPseudoInstruction(const MachineInstr &MI);
95 unsigned getMachineSoRegOpValue(const MachineInstr &MI,
96 const TargetInstrDesc &TID,
97 const MachineOperand &MO,
100 unsigned getMachineSoImmOpValue(unsigned SoImm);
102 unsigned getAddrModeSBit(const MachineInstr &MI,
103 const TargetInstrDesc &TID) const;
105 void emitDataProcessingInstruction(const MachineInstr &MI,
106 unsigned ImplicitRd = 0,
107 unsigned ImplicitRn = 0);
109 void emitLoadStoreInstruction(const MachineInstr &MI,
110 unsigned ImplicitRd = 0,
111 unsigned ImplicitRn = 0);
113 void emitMiscLoadStoreInstruction(const MachineInstr &MI,
114 unsigned ImplicitRn = 0);
116 void emitLoadStoreMultipleInstruction(const MachineInstr &MI);
118 void emitMulFrmInstruction(const MachineInstr &MI);
120 void emitExtendInstruction(const MachineInstr &MI);
122 void emitMiscArithInstruction(const MachineInstr &MI);
124 void emitBranchInstruction(const MachineInstr &MI);
126 void emitInlineJumpTable(unsigned JTIndex);
128 void emitMiscBranchInstruction(const MachineInstr &MI);
130 void emitVFPArithInstruction(const MachineInstr &MI);
132 void emitVFPConversionInstruction(const MachineInstr &MI);
134 void emitVFPLoadStoreInstruction(const MachineInstr &MI);
136 void emitVFPLoadStoreMultipleInstruction(const MachineInstr &MI);
138 void emitMiscInstruction(const MachineInstr &MI);
140 /// getMachineOpValue - Return binary encoding of operand. If the machine
141 /// operand requires relocation, record the relocation and return zero.
142 unsigned getMachineOpValue(const MachineInstr &MI,const MachineOperand &MO);
143 unsigned getMachineOpValue(const MachineInstr &MI, unsigned OpIdx) {
144 return getMachineOpValue(MI, MI.getOperand(OpIdx));
147 /// getShiftOp - Return the shift opcode (bit[6:5]) of the immediate value.
149 unsigned getShiftOp(unsigned Imm) const ;
151 /// Routines that handle operands which add machine relocations which are
152 /// fixed up by the relocation stage.
153 void emitGlobalAddress(GlobalValue *GV, unsigned Reloc,
154 bool MayNeedFarStub, bool Indirect,
156 void emitExternalSymbolAddress(const char *ES, unsigned Reloc);
157 void emitConstPoolAddress(unsigned CPI, unsigned Reloc);
158 void emitJumpTableAddress(unsigned JTIndex, unsigned Reloc);
159 void emitMachineBasicBlock(MachineBasicBlock *BB, unsigned Reloc,
160 intptr_t JTBase = 0);
164 char ARMCodeEmitter::ID = 0;
166 /// createARMJITCodeEmitterPass - Return a pass that emits the collected ARM
167 /// code to the specified MCE object.
168 FunctionPass *llvm::createARMJITCodeEmitterPass(ARMBaseTargetMachine &TM,
169 JITCodeEmitter &JCE) {
170 return new ARMCodeEmitter(TM, JCE);
173 bool ARMCodeEmitter::runOnMachineFunction(MachineFunction &MF) {
174 assert((MF.getTarget().getRelocationModel() != Reloc::Default ||
175 MF.getTarget().getRelocationModel() != Reloc::Static) &&
176 "JIT relocation model must be set to static or default!");
177 JTI = ((ARMTargetMachine&)MF.getTarget()).getJITInfo();
178 II = ((ARMTargetMachine&)MF.getTarget()).getInstrInfo();
179 TD = ((ARMTargetMachine&)MF.getTarget()).getTargetData();
180 Subtarget = &TM.getSubtarget<ARMSubtarget>();
181 MCPEs = &MF.getConstantPool()->getConstants();
183 if (MF.getJumpTableInfo()) MJTEs = &MF.getJumpTableInfo()->getJumpTables();
184 IsPIC = TM.getRelocationModel() == Reloc::PIC_;
185 JTI->Initialize(MF, IsPIC);
186 MMI = &getAnalysis<MachineModuleInfo>();
187 MCE.setModuleInfo(MMI);
190 DEBUG(errs() << "JITTing function '"
191 << MF.getFunction()->getName() << "'\n");
192 MCE.startFunction(MF);
193 for (MachineFunction::iterator MBB = MF.begin(), E = MF.end();
195 MCE.StartMachineBasicBlock(MBB);
196 for (MachineBasicBlock::const_iterator I = MBB->begin(), E = MBB->end();
200 } while (MCE.finishFunction(MF));
205 /// getShiftOp - Return the shift opcode (bit[6:5]) of the immediate value.
207 unsigned ARMCodeEmitter::getShiftOp(unsigned Imm) const {
208 switch (ARM_AM::getAM2ShiftOpc(Imm)) {
209 default: llvm_unreachable("Unknown shift opc!");
210 case ARM_AM::asr: return 2;
211 case ARM_AM::lsl: return 0;
212 case ARM_AM::lsr: return 1;
214 case ARM_AM::rrx: return 3;
219 /// getMachineOpValue - Return binary encoding of operand. If the machine
220 /// operand requires relocation, record the relocation and return zero.
221 unsigned ARMCodeEmitter::getMachineOpValue(const MachineInstr &MI,
222 const MachineOperand &MO) {
224 return ARMRegisterInfo::getRegisterNumbering(MO.getReg());
226 return static_cast<unsigned>(MO.getImm());
227 else if (MO.isGlobal())
228 emitGlobalAddress(MO.getGlobal(), ARM::reloc_arm_branch, true, false);
229 else if (MO.isSymbol())
230 emitExternalSymbolAddress(MO.getSymbolName(), ARM::reloc_arm_branch);
231 else if (MO.isCPI()) {
232 const TargetInstrDesc &TID = MI.getDesc();
233 // For VFP load, the immediate offset is multiplied by 4.
234 unsigned Reloc = ((TID.TSFlags & ARMII::FormMask) == ARMII::VFPLdStFrm)
235 ? ARM::reloc_arm_vfp_cp_entry : ARM::reloc_arm_cp_entry;
236 emitConstPoolAddress(MO.getIndex(), Reloc);
237 } else if (MO.isJTI())
238 emitJumpTableAddress(MO.getIndex(), ARM::reloc_arm_relative);
240 emitMachineBasicBlock(MO.getMBB(), ARM::reloc_arm_branch);
250 /// emitGlobalAddress - Emit the specified address to the code stream.
252 void ARMCodeEmitter::emitGlobalAddress(GlobalValue *GV, unsigned Reloc,
253 bool MayNeedFarStub, bool Indirect,
255 MachineRelocation MR = Indirect
256 ? MachineRelocation::getIndirectSymbol(MCE.getCurrentPCOffset(), Reloc,
257 GV, ACPV, MayNeedFarStub)
258 : MachineRelocation::getGV(MCE.getCurrentPCOffset(), Reloc,
259 GV, ACPV, MayNeedFarStub);
260 MCE.addRelocation(MR);
263 /// emitExternalSymbolAddress - Arrange for the address of an external symbol to
264 /// be emitted to the current location in the function, and allow it to be PC
266 void ARMCodeEmitter::emitExternalSymbolAddress(const char *ES, unsigned Reloc) {
267 MCE.addRelocation(MachineRelocation::getExtSym(MCE.getCurrentPCOffset(),
271 /// emitConstPoolAddress - Arrange for the address of an constant pool
272 /// to be emitted to the current location in the function, and allow it to be PC
274 void ARMCodeEmitter::emitConstPoolAddress(unsigned CPI, unsigned Reloc) {
275 // Tell JIT emitter we'll resolve the address.
276 MCE.addRelocation(MachineRelocation::getConstPool(MCE.getCurrentPCOffset(),
277 Reloc, CPI, 0, true));
280 /// emitJumpTableAddress - Arrange for the address of a jump table to
281 /// be emitted to the current location in the function, and allow it to be PC
283 void ARMCodeEmitter::emitJumpTableAddress(unsigned JTIndex, unsigned Reloc) {
284 MCE.addRelocation(MachineRelocation::getJumpTable(MCE.getCurrentPCOffset(),
285 Reloc, JTIndex, 0, true));
288 /// emitMachineBasicBlock - Emit the specified address basic block.
289 void ARMCodeEmitter::emitMachineBasicBlock(MachineBasicBlock *BB,
290 unsigned Reloc, intptr_t JTBase) {
291 MCE.addRelocation(MachineRelocation::getBB(MCE.getCurrentPCOffset(),
295 void ARMCodeEmitter::emitWordLE(unsigned Binary) {
296 DEBUG(errs() << " 0x";
297 errs().write_hex(Binary) << "\n");
298 MCE.emitWordLE(Binary);
301 void ARMCodeEmitter::emitDWordLE(uint64_t Binary) {
302 DEBUG(errs() << " 0x";
303 errs().write_hex(Binary) << "\n");
304 MCE.emitDWordLE(Binary);
307 void ARMCodeEmitter::emitInstruction(const MachineInstr &MI) {
308 DEBUG(errs() << "JIT: " << (void*)MCE.getCurrentPCValue() << ":\t" << MI);
310 MCE.processDebugLoc(MI.getDebugLoc(), true);
312 NumEmitted++; // Keep track of the # of mi's emitted
313 switch (MI.getDesc().TSFlags & ARMII::FormMask) {
315 llvm_unreachable("Unhandled instruction encoding format!");
319 emitPseudoInstruction(MI);
322 case ARMII::DPSoRegFrm:
323 emitDataProcessingInstruction(MI);
327 emitLoadStoreInstruction(MI);
329 case ARMII::LdMiscFrm:
330 case ARMII::StMiscFrm:
331 emitMiscLoadStoreInstruction(MI);
333 case ARMII::LdStMulFrm:
334 emitLoadStoreMultipleInstruction(MI);
337 emitMulFrmInstruction(MI);
340 emitExtendInstruction(MI);
342 case ARMII::ArithMiscFrm:
343 emitMiscArithInstruction(MI);
346 emitBranchInstruction(MI);
348 case ARMII::BrMiscFrm:
349 emitMiscBranchInstruction(MI);
352 case ARMII::VFPUnaryFrm:
353 case ARMII::VFPBinaryFrm:
354 emitVFPArithInstruction(MI);
356 case ARMII::VFPConv1Frm:
357 case ARMII::VFPConv2Frm:
358 case ARMII::VFPConv3Frm:
359 case ARMII::VFPConv4Frm:
360 case ARMII::VFPConv5Frm:
361 emitVFPConversionInstruction(MI);
363 case ARMII::VFPLdStFrm:
364 emitVFPLoadStoreInstruction(MI);
366 case ARMII::VFPLdStMulFrm:
367 emitVFPLoadStoreMultipleInstruction(MI);
369 case ARMII::VFPMiscFrm:
370 emitMiscInstruction(MI);
373 MCE.processDebugLoc(MI.getDebugLoc(), false);
376 void ARMCodeEmitter::emitConstPoolInstruction(const MachineInstr &MI) {
377 unsigned CPI = MI.getOperand(0).getImm(); // CP instruction index.
378 unsigned CPIndex = MI.getOperand(1).getIndex(); // Actual cp entry index.
379 const MachineConstantPoolEntry &MCPE = (*MCPEs)[CPIndex];
381 // Remember the CONSTPOOL_ENTRY address for later relocation.
382 JTI->addConstantPoolEntryAddr(CPI, MCE.getCurrentPCValue());
384 // Emit constpool island entry. In most cases, the actual values will be
385 // resolved and relocated after code emission.
386 if (MCPE.isMachineConstantPoolEntry()) {
387 ARMConstantPoolValue *ACPV =
388 static_cast<ARMConstantPoolValue*>(MCPE.Val.MachineCPVal);
390 DEBUG(errs() << " ** ARM constant pool #" << CPI << " @ "
391 << (void*)MCE.getCurrentPCValue() << " " << *ACPV << '\n');
393 assert(ACPV->isGlobalValue() && "unsupported constant pool value");
394 GlobalValue *GV = ACPV->getGV();
396 Reloc::Model RelocM = TM.getRelocationModel();
397 emitGlobalAddress(GV, ARM::reloc_arm_machine_cp_entry,
399 Subtarget->GVIsIndirectSymbol(GV, RelocM),
402 emitExternalSymbolAddress(ACPV->getSymbol(), ARM::reloc_arm_absolute);
406 Constant *CV = MCPE.Val.ConstVal;
409 errs() << " ** Constant pool #" << CPI << " @ "
410 << (void*)MCE.getCurrentPCValue() << " ";
411 if (const Function *F = dyn_cast<Function>(CV))
412 errs() << F->getName();
418 if (GlobalValue *GV = dyn_cast<GlobalValue>(CV)) {
419 emitGlobalAddress(GV, ARM::reloc_arm_absolute, isa<Function>(GV), false);
421 } else if (const ConstantInt *CI = dyn_cast<ConstantInt>(CV)) {
422 uint32_t Val = *(uint32_t*)CI->getValue().getRawData();
424 } else if (const ConstantFP *CFP = dyn_cast<ConstantFP>(CV)) {
425 if (CFP->getType()->isFloatTy())
426 emitWordLE(CFP->getValueAPF().bitcastToAPInt().getZExtValue());
427 else if (CFP->getType()->isDoubleTy())
428 emitDWordLE(CFP->getValueAPF().bitcastToAPInt().getZExtValue());
430 llvm_unreachable("Unable to handle this constantpool entry!");
433 llvm_unreachable("Unable to handle this constantpool entry!");
438 void ARMCodeEmitter::emitMOVi2piecesInstruction(const MachineInstr &MI) {
439 const MachineOperand &MO0 = MI.getOperand(0);
440 const MachineOperand &MO1 = MI.getOperand(1);
441 assert(MO1.isImm() && ARM_AM::isSOImmTwoPartVal(MO1.getImm()) &&
442 "Not a valid so_imm value!");
443 unsigned V1 = ARM_AM::getSOImmTwoPartFirst(MO1.getImm());
444 unsigned V2 = ARM_AM::getSOImmTwoPartSecond(MO1.getImm());
446 // Emit the 'mov' instruction.
447 unsigned Binary = 0xd << 21; // mov: Insts{24-21} = 0b1101
449 // Set the conditional execution predicate.
450 Binary |= II->getPredicate(&MI) << ARMII::CondShift;
453 Binary |= getMachineOpValue(MI, MO0) << ARMII::RegRdShift;
456 // Set bit I(25) to identify this is the immediate form of <shifter_op>
457 Binary |= 1 << ARMII::I_BitShift;
458 Binary |= getMachineSoImmOpValue(V1);
461 // Now the 'orr' instruction.
462 Binary = 0xc << 21; // orr: Insts{24-21} = 0b1100
464 // Set the conditional execution predicate.
465 Binary |= II->getPredicate(&MI) << ARMII::CondShift;
468 Binary |= getMachineOpValue(MI, MO0) << ARMII::RegRdShift;
471 Binary |= getMachineOpValue(MI, MO0) << ARMII::RegRnShift;
474 // Set bit I(25) to identify this is the immediate form of <shifter_op>
475 Binary |= 1 << ARMII::I_BitShift;
476 Binary |= getMachineSoImmOpValue(V2);
480 void ARMCodeEmitter::emitLEApcrelJTInstruction(const MachineInstr &MI) {
481 // It's basically add r, pc, (LJTI - $+8)
483 const TargetInstrDesc &TID = MI.getDesc();
485 // Emit the 'add' instruction.
486 unsigned Binary = 0x4 << 21; // add: Insts{24-31} = 0b0100
488 // Set the conditional execution predicate
489 Binary |= II->getPredicate(&MI) << ARMII::CondShift;
491 // Encode S bit if MI modifies CPSR.
492 Binary |= getAddrModeSBit(MI, TID);
495 Binary |= getMachineOpValue(MI, 0) << ARMII::RegRdShift;
497 // Encode Rn which is PC.
498 Binary |= ARMRegisterInfo::getRegisterNumbering(ARM::PC) << ARMII::RegRnShift;
500 // Encode the displacement.
501 Binary |= 1 << ARMII::I_BitShift;
502 emitJumpTableAddress(MI.getOperand(1).getIndex(), ARM::reloc_arm_jt_base);
507 void ARMCodeEmitter::emitPseudoMoveInstruction(const MachineInstr &MI) {
508 unsigned Opcode = MI.getDesc().Opcode;
510 // Part of binary is determined by TableGn.
511 unsigned Binary = getBinaryCodeForInstr(MI);
513 // Set the conditional execution predicate
514 Binary |= II->getPredicate(&MI) << ARMII::CondShift;
516 // Encode S bit if MI modifies CPSR.
517 if (Opcode == ARM::MOVsrl_flag || Opcode == ARM::MOVsra_flag)
518 Binary |= 1 << ARMII::S_BitShift;
520 // Encode register def if there is one.
521 Binary |= getMachineOpValue(MI, 0) << ARMII::RegRdShift;
523 // Encode the shift operation.
530 case ARM::MOVsrl_flag:
532 Binary |= (0x2 << 4) | (1 << 7);
534 case ARM::MOVsra_flag:
536 Binary |= (0x4 << 4) | (1 << 7);
540 // Encode register Rm.
541 Binary |= getMachineOpValue(MI, 1);
546 void ARMCodeEmitter::addPCLabel(unsigned LabelID) {
547 DEBUG(errs() << " ** LPC" << LabelID << " @ "
548 << (void*)MCE.getCurrentPCValue() << '\n');
549 JTI->addPCLabelAddr(LabelID, MCE.getCurrentPCValue());
552 void ARMCodeEmitter::emitPseudoInstruction(const MachineInstr &MI) {
553 unsigned Opcode = MI.getDesc().Opcode;
556 llvm_unreachable("ARMCodeEmitter::emitPseudoInstruction");
557 // FIXME: Add support for MOVimm32.
558 case TargetOpcode::INLINEASM: {
559 // We allow inline assembler nodes with empty bodies - they can
560 // implicitly define registers, which is ok for JIT.
561 if (MI.getOperand(0).getSymbolName()[0]) {
562 llvm_report_error("JIT does not support inline asm!");
566 case TargetOpcode::DBG_LABEL:
567 MCE.emitLabel(MMI->getLabelSym(MI.getOperand(0).getImm()));
569 case TargetOpcode::EH_LABEL:
570 MCE.emitLabel(MI.getOperand(0).getMCSymbol());
572 case TargetOpcode::IMPLICIT_DEF:
573 case TargetOpcode::KILL:
576 case ARM::CONSTPOOL_ENTRY:
577 emitConstPoolInstruction(MI);
580 // Remember of the address of the PC label for relocation later.
581 addPCLabel(MI.getOperand(2).getImm());
582 // PICADD is just an add instruction that implicitly read pc.
583 emitDataProcessingInstruction(MI, 0, ARM::PC);
590 // Remember of the address of the PC label for relocation later.
591 addPCLabel(MI.getOperand(2).getImm());
592 // These are just load / store instructions that implicitly read pc.
593 emitLoadStoreInstruction(MI, 0, ARM::PC);
600 // Remember of the address of the PC label for relocation later.
601 addPCLabel(MI.getOperand(2).getImm());
602 // These are just load / store instructions that implicitly read pc.
603 emitMiscLoadStoreInstruction(MI, ARM::PC);
606 case ARM::MOVi2pieces:
607 // Two instructions to materialize a constant.
608 emitMOVi2piecesInstruction(MI);
610 case ARM::LEApcrelJT:
611 // Materialize jumptable address.
612 emitLEApcrelJTInstruction(MI);
615 case ARM::MOVsrl_flag:
616 case ARM::MOVsra_flag:
617 emitPseudoMoveInstruction(MI);
622 unsigned ARMCodeEmitter::getMachineSoRegOpValue(
623 const MachineInstr &MI,
624 const TargetInstrDesc &TID,
625 const MachineOperand &MO,
627 unsigned Binary = getMachineOpValue(MI, MO);
629 const MachineOperand &MO1 = MI.getOperand(OpIdx + 1);
630 const MachineOperand &MO2 = MI.getOperand(OpIdx + 2);
631 ARM_AM::ShiftOpc SOpc = ARM_AM::getSORegShOp(MO2.getImm());
633 // Encode the shift opcode.
635 unsigned Rs = MO1.getReg();
637 // Set shift operand (bit[7:4]).
642 // RRX - 0110 and bit[11:8] clear.
644 default: llvm_unreachable("Unknown shift opc!");
645 case ARM_AM::lsl: SBits = 0x1; break;
646 case ARM_AM::lsr: SBits = 0x3; break;
647 case ARM_AM::asr: SBits = 0x5; break;
648 case ARM_AM::ror: SBits = 0x7; break;
649 case ARM_AM::rrx: SBits = 0x6; break;
652 // Set shift operand (bit[6:4]).
658 default: llvm_unreachable("Unknown shift opc!");
659 case ARM_AM::lsl: SBits = 0x0; break;
660 case ARM_AM::lsr: SBits = 0x2; break;
661 case ARM_AM::asr: SBits = 0x4; break;
662 case ARM_AM::ror: SBits = 0x6; break;
665 Binary |= SBits << 4;
666 if (SOpc == ARM_AM::rrx)
669 // Encode the shift operation Rs or shift_imm (except rrx).
671 // Encode Rs bit[11:8].
672 assert(ARM_AM::getSORegOffset(MO2.getImm()) == 0);
674 (ARMRegisterInfo::getRegisterNumbering(Rs) << ARMII::RegRsShift);
677 // Encode shift_imm bit[11:7].
678 return Binary | ARM_AM::getSORegOffset(MO2.getImm()) << 7;
681 unsigned ARMCodeEmitter::getMachineSoImmOpValue(unsigned SoImm) {
682 int SoImmVal = ARM_AM::getSOImmVal(SoImm);
683 assert(SoImmVal != -1 && "Not a valid so_imm value!");
685 // Encode rotate_imm.
686 unsigned Binary = (ARM_AM::getSOImmValRot((unsigned)SoImmVal) >> 1)
687 << ARMII::SoRotImmShift;
690 Binary |= ARM_AM::getSOImmValImm((unsigned)SoImmVal);
694 unsigned ARMCodeEmitter::getAddrModeSBit(const MachineInstr &MI,
695 const TargetInstrDesc &TID) const {
696 for (unsigned i = MI.getNumOperands(), e = TID.getNumOperands(); i != e; --i){
697 const MachineOperand &MO = MI.getOperand(i-1);
698 if (MO.isReg() && MO.isDef() && MO.getReg() == ARM::CPSR)
699 return 1 << ARMII::S_BitShift;
704 void ARMCodeEmitter::emitDataProcessingInstruction(
705 const MachineInstr &MI,
707 unsigned ImplicitRn) {
708 const TargetInstrDesc &TID = MI.getDesc();
710 if (TID.Opcode == ARM::BFC) {
711 llvm_report_error("ARMv6t2 JIT is not yet supported.");
714 // Part of binary is determined by TableGn.
715 unsigned Binary = getBinaryCodeForInstr(MI);
717 // Set the conditional execution predicate
718 Binary |= II->getPredicate(&MI) << ARMII::CondShift;
720 // Encode S bit if MI modifies CPSR.
721 Binary |= getAddrModeSBit(MI, TID);
723 // Encode register def if there is one.
724 unsigned NumDefs = TID.getNumDefs();
727 Binary |= getMachineOpValue(MI, OpIdx++) << ARMII::RegRdShift;
729 // Special handling for implicit use (e.g. PC).
730 Binary |= (ARMRegisterInfo::getRegisterNumbering(ImplicitRd)
731 << ARMII::RegRdShift);
733 // If this is a two-address operand, skip it. e.g. MOVCCr operand 1.
734 if (TID.getOperandConstraint(OpIdx, TOI::TIED_TO) != -1)
737 // Encode first non-shifter register operand if there is one.
738 bool isUnary = TID.TSFlags & ARMII::UnaryDP;
741 // Special handling for implicit use (e.g. PC).
742 Binary |= (ARMRegisterInfo::getRegisterNumbering(ImplicitRn)
743 << ARMII::RegRnShift);
745 Binary |= getMachineOpValue(MI, OpIdx) << ARMII::RegRnShift;
750 // Encode shifter operand.
751 const MachineOperand &MO = MI.getOperand(OpIdx);
752 if ((TID.TSFlags & ARMII::FormMask) == ARMII::DPSoRegFrm) {
754 emitWordLE(Binary | getMachineSoRegOpValue(MI, TID, MO, OpIdx));
759 // Encode register Rm.
760 emitWordLE(Binary | ARMRegisterInfo::getRegisterNumbering(MO.getReg()));
765 Binary |= getMachineSoImmOpValue((unsigned)MO.getImm());
770 void ARMCodeEmitter::emitLoadStoreInstruction(
771 const MachineInstr &MI,
773 unsigned ImplicitRn) {
774 const TargetInstrDesc &TID = MI.getDesc();
775 unsigned Form = TID.TSFlags & ARMII::FormMask;
776 bool IsPrePost = (TID.TSFlags & ARMII::IndexModeMask) != 0;
778 // Part of binary is determined by TableGn.
779 unsigned Binary = getBinaryCodeForInstr(MI);
781 // Set the conditional execution predicate
782 Binary |= II->getPredicate(&MI) << ARMII::CondShift;
786 // Operand 0 of a pre- and post-indexed store is the address base
787 // writeback. Skip it.
788 bool Skipped = false;
789 if (IsPrePost && Form == ARMII::StFrm) {
796 // Special handling for implicit use (e.g. PC).
797 Binary |= (ARMRegisterInfo::getRegisterNumbering(ImplicitRd)
798 << ARMII::RegRdShift);
800 Binary |= getMachineOpValue(MI, OpIdx++) << ARMII::RegRdShift;
802 // Set second operand
804 // Special handling for implicit use (e.g. PC).
805 Binary |= (ARMRegisterInfo::getRegisterNumbering(ImplicitRn)
806 << ARMII::RegRnShift);
808 Binary |= getMachineOpValue(MI, OpIdx++) << ARMII::RegRnShift;
810 // If this is a two-address operand, skip it. e.g. LDR_PRE.
811 if (!Skipped && TID.getOperandConstraint(OpIdx, TOI::TIED_TO) != -1)
814 const MachineOperand &MO2 = MI.getOperand(OpIdx);
815 unsigned AM2Opc = (ImplicitRn == ARM::PC)
816 ? 0 : MI.getOperand(OpIdx+1).getImm();
818 // Set bit U(23) according to sign of immed value (positive or negative).
819 Binary |= ((ARM_AM::getAM2Op(AM2Opc) == ARM_AM::add ? 1 : 0) <<
821 if (!MO2.getReg()) { // is immediate
822 if (ARM_AM::getAM2Offset(AM2Opc))
823 // Set the value of offset_12 field
824 Binary |= ARM_AM::getAM2Offset(AM2Opc);
829 // Set bit I(25), because this is not in immediate enconding.
830 Binary |= 1 << ARMII::I_BitShift;
831 assert(TargetRegisterInfo::isPhysicalRegister(MO2.getReg()));
832 // Set bit[3:0] to the corresponding Rm register
833 Binary |= ARMRegisterInfo::getRegisterNumbering(MO2.getReg());
835 // If this instr is in scaled register offset/index instruction, set
836 // shift_immed(bit[11:7]) and shift(bit[6:5]) fields.
837 if (unsigned ShImm = ARM_AM::getAM2Offset(AM2Opc)) {
838 Binary |= getShiftOp(AM2Opc) << ARMII::ShiftImmShift; // shift
839 Binary |= ShImm << ARMII::ShiftShift; // shift_immed
845 void ARMCodeEmitter::emitMiscLoadStoreInstruction(const MachineInstr &MI,
846 unsigned ImplicitRn) {
847 const TargetInstrDesc &TID = MI.getDesc();
848 unsigned Form = TID.TSFlags & ARMII::FormMask;
849 bool IsPrePost = (TID.TSFlags & ARMII::IndexModeMask) != 0;
851 // Part of binary is determined by TableGn.
852 unsigned Binary = getBinaryCodeForInstr(MI);
854 // Set the conditional execution predicate
855 Binary |= II->getPredicate(&MI) << ARMII::CondShift;
859 // Operand 0 of a pre- and post-indexed store is the address base
860 // writeback. Skip it.
861 bool Skipped = false;
862 if (IsPrePost && Form == ARMII::StMiscFrm) {
868 Binary |= getMachineOpValue(MI, OpIdx++) << ARMII::RegRdShift;
870 // Skip LDRD and STRD's second operand.
871 if (TID.Opcode == ARM::LDRD || TID.Opcode == ARM::STRD)
874 // Set second operand
876 // Special handling for implicit use (e.g. PC).
877 Binary |= (ARMRegisterInfo::getRegisterNumbering(ImplicitRn)
878 << ARMII::RegRnShift);
880 Binary |= getMachineOpValue(MI, OpIdx++) << ARMII::RegRnShift;
882 // If this is a two-address operand, skip it. e.g. LDRH_POST.
883 if (!Skipped && TID.getOperandConstraint(OpIdx, TOI::TIED_TO) != -1)
886 const MachineOperand &MO2 = MI.getOperand(OpIdx);
887 unsigned AM3Opc = (ImplicitRn == ARM::PC)
888 ? 0 : MI.getOperand(OpIdx+1).getImm();
890 // Set bit U(23) according to sign of immed value (positive or negative)
891 Binary |= ((ARM_AM::getAM3Op(AM3Opc) == ARM_AM::add ? 1 : 0) <<
894 // If this instr is in register offset/index encoding, set bit[3:0]
895 // to the corresponding Rm register.
897 Binary |= ARMRegisterInfo::getRegisterNumbering(MO2.getReg());
902 // This instr is in immediate offset/index encoding, set bit 22 to 1.
903 Binary |= 1 << ARMII::AM3_I_BitShift;
904 if (unsigned ImmOffs = ARM_AM::getAM3Offset(AM3Opc)) {
906 Binary |= (ImmOffs >> 4) << ARMII::ImmHiShift; // immedH
907 Binary |= (ImmOffs & 0xF); // immedL
913 static unsigned getAddrModeUPBits(unsigned Mode) {
916 // Set addressing mode by modifying bits U(23) and P(24)
917 // IA - Increment after - bit U = 1 and bit P = 0
918 // IB - Increment before - bit U = 1 and bit P = 1
919 // DA - Decrement after - bit U = 0 and bit P = 0
920 // DB - Decrement before - bit U = 0 and bit P = 1
922 default: llvm_unreachable("Unknown addressing sub-mode!");
923 case ARM_AM::da: break;
924 case ARM_AM::db: Binary |= 0x1 << ARMII::P_BitShift; break;
925 case ARM_AM::ia: Binary |= 0x1 << ARMII::U_BitShift; break;
926 case ARM_AM::ib: Binary |= 0x3 << ARMII::U_BitShift; break;
932 void ARMCodeEmitter::emitLoadStoreMultipleInstruction(const MachineInstr &MI) {
933 const TargetInstrDesc &TID = MI.getDesc();
934 bool IsUpdating = (TID.TSFlags & ARMII::IndexModeMask) != 0;
936 // Part of binary is determined by TableGn.
937 unsigned Binary = getBinaryCodeForInstr(MI);
939 // Set the conditional execution predicate
940 Binary |= II->getPredicate(&MI) << ARMII::CondShift;
942 // Skip operand 0 of an instruction with base register update.
947 // Set base address operand
948 Binary |= getMachineOpValue(MI, OpIdx++) << ARMII::RegRnShift;
950 // Set addressing mode by modifying bits U(23) and P(24)
951 const MachineOperand &MO = MI.getOperand(OpIdx++);
952 Binary |= getAddrModeUPBits(ARM_AM::getAM4SubMode(MO.getImm()));
955 if (ARM_AM::getAM4WBFlag(MO.getImm()))
956 Binary |= 0x1 << ARMII::W_BitShift;
959 for (unsigned i = OpIdx+2, e = MI.getNumOperands(); i != e; ++i) {
960 const MachineOperand &MO = MI.getOperand(i);
961 if (!MO.isReg() || MO.isImplicit())
963 unsigned RegNum = ARMRegisterInfo::getRegisterNumbering(MO.getReg());
964 assert(TargetRegisterInfo::isPhysicalRegister(MO.getReg()) &&
966 Binary |= 0x1 << RegNum;
972 void ARMCodeEmitter::emitMulFrmInstruction(const MachineInstr &MI) {
973 const TargetInstrDesc &TID = MI.getDesc();
975 // Part of binary is determined by TableGn.
976 unsigned Binary = getBinaryCodeForInstr(MI);
978 // Set the conditional execution predicate
979 Binary |= II->getPredicate(&MI) << ARMII::CondShift;
981 // Encode S bit if MI modifies CPSR.
982 Binary |= getAddrModeSBit(MI, TID);
984 // 32x32->64bit operations have two destination registers. The number
985 // of register definitions will tell us if that's what we're dealing with.
987 if (TID.getNumDefs() == 2)
988 Binary |= getMachineOpValue (MI, OpIdx++) << ARMII::RegRdLoShift;
991 Binary |= getMachineOpValue(MI, OpIdx++) << ARMII::RegRdHiShift;
994 Binary |= getMachineOpValue(MI, OpIdx++);
997 Binary |= getMachineOpValue(MI, OpIdx++) << ARMII::RegRsShift;
999 // Many multiple instructions (e.g. MLA) have three src operands. Encode
1000 // it as Rn (for multiply, that's in the same offset as RdLo.
1001 if (TID.getNumOperands() > OpIdx &&
1002 !TID.OpInfo[OpIdx].isPredicate() &&
1003 !TID.OpInfo[OpIdx].isOptionalDef())
1004 Binary |= getMachineOpValue(MI, OpIdx) << ARMII::RegRdLoShift;
1009 void ARMCodeEmitter::emitExtendInstruction(const MachineInstr &MI) {
1010 const TargetInstrDesc &TID = MI.getDesc();
1012 // Part of binary is determined by TableGn.
1013 unsigned Binary = getBinaryCodeForInstr(MI);
1015 // Set the conditional execution predicate
1016 Binary |= II->getPredicate(&MI) << ARMII::CondShift;
1021 Binary |= getMachineOpValue(MI, OpIdx++) << ARMII::RegRdShift;
1023 const MachineOperand &MO1 = MI.getOperand(OpIdx++);
1024 const MachineOperand &MO2 = MI.getOperand(OpIdx);
1026 // Two register operand form.
1028 Binary |= getMachineOpValue(MI, MO1) << ARMII::RegRnShift;
1031 Binary |= getMachineOpValue(MI, MO2);
1034 Binary |= getMachineOpValue(MI, MO1);
1037 // Encode rot imm (0, 8, 16, or 24) if it has a rotate immediate operand.
1038 if (MI.getOperand(OpIdx).isImm() &&
1039 !TID.OpInfo[OpIdx].isPredicate() &&
1040 !TID.OpInfo[OpIdx].isOptionalDef())
1041 Binary |= (getMachineOpValue(MI, OpIdx) / 8) << ARMII::ExtRotImmShift;
1046 void ARMCodeEmitter::emitMiscArithInstruction(const MachineInstr &MI) {
1047 const TargetInstrDesc &TID = MI.getDesc();
1049 // Part of binary is determined by TableGn.
1050 unsigned Binary = getBinaryCodeForInstr(MI);
1052 // Set the conditional execution predicate
1053 Binary |= II->getPredicate(&MI) << ARMII::CondShift;
1058 Binary |= getMachineOpValue(MI, OpIdx++) << ARMII::RegRdShift;
1060 const MachineOperand &MO = MI.getOperand(OpIdx++);
1061 if (OpIdx == TID.getNumOperands() ||
1062 TID.OpInfo[OpIdx].isPredicate() ||
1063 TID.OpInfo[OpIdx].isOptionalDef()) {
1064 // Encode Rm and it's done.
1065 Binary |= getMachineOpValue(MI, MO);
1071 Binary |= getMachineOpValue(MI, MO) << ARMII::RegRnShift;
1074 Binary |= getMachineOpValue(MI, OpIdx++);
1076 // Encode shift_imm.
1077 unsigned ShiftAmt = MI.getOperand(OpIdx).getImm();
1078 assert(ShiftAmt < 32 && "shift_imm range is 0 to 31!");
1079 Binary |= ShiftAmt << ARMII::ShiftShift;
1084 void ARMCodeEmitter::emitBranchInstruction(const MachineInstr &MI) {
1085 const TargetInstrDesc &TID = MI.getDesc();
1087 if (TID.Opcode == ARM::TPsoft) {
1088 llvm_unreachable("ARM::TPsoft FIXME"); // FIXME
1091 // Part of binary is determined by TableGn.
1092 unsigned Binary = getBinaryCodeForInstr(MI);
1094 // Set the conditional execution predicate
1095 Binary |= II->getPredicate(&MI) << ARMII::CondShift;
1097 // Set signed_immed_24 field
1098 Binary |= getMachineOpValue(MI, 0);
1103 void ARMCodeEmitter::emitInlineJumpTable(unsigned JTIndex) {
1104 // Remember the base address of the inline jump table.
1105 uintptr_t JTBase = MCE.getCurrentPCValue();
1106 JTI->addJumpTableBaseAddr(JTIndex, JTBase);
1107 DEBUG(errs() << " ** Jump Table #" << JTIndex << " @ " << (void*)JTBase
1110 // Now emit the jump table entries.
1111 const std::vector<MachineBasicBlock*> &MBBs = (*MJTEs)[JTIndex].MBBs;
1112 for (unsigned i = 0, e = MBBs.size(); i != e; ++i) {
1114 // DestBB address - JT base.
1115 emitMachineBasicBlock(MBBs[i], ARM::reloc_arm_pic_jt, JTBase);
1117 // Absolute DestBB address.
1118 emitMachineBasicBlock(MBBs[i], ARM::reloc_arm_absolute);
1123 void ARMCodeEmitter::emitMiscBranchInstruction(const MachineInstr &MI) {
1124 const TargetInstrDesc &TID = MI.getDesc();
1126 // Handle jump tables.
1127 if (TID.Opcode == ARM::BR_JTr || TID.Opcode == ARM::BR_JTadd) {
1128 // First emit a ldr pc, [] instruction.
1129 emitDataProcessingInstruction(MI, ARM::PC);
1131 // Then emit the inline jump table.
1133 (TID.Opcode == ARM::BR_JTr)
1134 ? MI.getOperand(1).getIndex() : MI.getOperand(2).getIndex();
1135 emitInlineJumpTable(JTIndex);
1137 } else if (TID.Opcode == ARM::BR_JTm) {
1138 // First emit a ldr pc, [] instruction.
1139 emitLoadStoreInstruction(MI, ARM::PC);
1141 // Then emit the inline jump table.
1142 emitInlineJumpTable(MI.getOperand(3).getIndex());
1146 // Part of binary is determined by TableGn.
1147 unsigned Binary = getBinaryCodeForInstr(MI);
1149 // Set the conditional execution predicate
1150 Binary |= II->getPredicate(&MI) << ARMII::CondShift;
1152 if (TID.Opcode == ARM::BX_RET || TID.Opcode == ARM::MOVPCLR)
1153 // The return register is LR.
1154 Binary |= ARMRegisterInfo::getRegisterNumbering(ARM::LR);
1156 // otherwise, set the return register
1157 Binary |= getMachineOpValue(MI, 0);
1162 static unsigned encodeVFPRd(const MachineInstr &MI, unsigned OpIdx) {
1163 unsigned RegD = MI.getOperand(OpIdx).getReg();
1164 unsigned Binary = 0;
1165 bool isSPVFP = false;
1166 RegD = ARMRegisterInfo::getRegisterNumbering(RegD, &isSPVFP);
1168 Binary |= RegD << ARMII::RegRdShift;
1170 Binary |= ((RegD & 0x1E) >> 1) << ARMII::RegRdShift;
1171 Binary |= (RegD & 0x01) << ARMII::D_BitShift;
1176 static unsigned encodeVFPRn(const MachineInstr &MI, unsigned OpIdx) {
1177 unsigned RegN = MI.getOperand(OpIdx).getReg();
1178 unsigned Binary = 0;
1179 bool isSPVFP = false;
1180 RegN = ARMRegisterInfo::getRegisterNumbering(RegN, &isSPVFP);
1182 Binary |= RegN << ARMII::RegRnShift;
1184 Binary |= ((RegN & 0x1E) >> 1) << ARMII::RegRnShift;
1185 Binary |= (RegN & 0x01) << ARMII::N_BitShift;
1190 static unsigned encodeVFPRm(const MachineInstr &MI, unsigned OpIdx) {
1191 unsigned RegM = MI.getOperand(OpIdx).getReg();
1192 unsigned Binary = 0;
1193 bool isSPVFP = false;
1194 RegM = ARMRegisterInfo::getRegisterNumbering(RegM, &isSPVFP);
1198 Binary |= ((RegM & 0x1E) >> 1);
1199 Binary |= (RegM & 0x01) << ARMII::M_BitShift;
1204 void ARMCodeEmitter::emitVFPArithInstruction(const MachineInstr &MI) {
1205 const TargetInstrDesc &TID = MI.getDesc();
1207 // Part of binary is determined by TableGn.
1208 unsigned Binary = getBinaryCodeForInstr(MI);
1210 // Set the conditional execution predicate
1211 Binary |= II->getPredicate(&MI) << ARMII::CondShift;
1214 assert((Binary & ARMII::D_BitShift) == 0 &&
1215 (Binary & ARMII::N_BitShift) == 0 &&
1216 (Binary & ARMII::M_BitShift) == 0 && "VFP encoding bug!");
1219 Binary |= encodeVFPRd(MI, OpIdx++);
1221 // If this is a two-address operand, skip it, e.g. FMACD.
1222 if (TID.getOperandConstraint(OpIdx, TOI::TIED_TO) != -1)
1226 if ((TID.TSFlags & ARMII::FormMask) == ARMII::VFPBinaryFrm)
1227 Binary |= encodeVFPRn(MI, OpIdx++);
1229 if (OpIdx == TID.getNumOperands() ||
1230 TID.OpInfo[OpIdx].isPredicate() ||
1231 TID.OpInfo[OpIdx].isOptionalDef()) {
1232 // FCMPEZD etc. has only one operand.
1238 Binary |= encodeVFPRm(MI, OpIdx);
1243 void ARMCodeEmitter::emitVFPConversionInstruction(
1244 const MachineInstr &MI) {
1245 const TargetInstrDesc &TID = MI.getDesc();
1246 unsigned Form = TID.TSFlags & ARMII::FormMask;
1248 // Part of binary is determined by TableGn.
1249 unsigned Binary = getBinaryCodeForInstr(MI);
1251 // Set the conditional execution predicate
1252 Binary |= II->getPredicate(&MI) << ARMII::CondShift;
1256 case ARMII::VFPConv1Frm:
1257 case ARMII::VFPConv2Frm:
1258 case ARMII::VFPConv3Frm:
1260 Binary |= encodeVFPRd(MI, 0);
1262 case ARMII::VFPConv4Frm:
1264 Binary |= encodeVFPRn(MI, 0);
1266 case ARMII::VFPConv5Frm:
1268 Binary |= encodeVFPRm(MI, 0);
1274 case ARMII::VFPConv1Frm:
1276 Binary |= encodeVFPRm(MI, 1);
1278 case ARMII::VFPConv2Frm:
1279 case ARMII::VFPConv3Frm:
1281 Binary |= encodeVFPRn(MI, 1);
1283 case ARMII::VFPConv4Frm:
1284 case ARMII::VFPConv5Frm:
1286 Binary |= encodeVFPRd(MI, 1);
1290 if (Form == ARMII::VFPConv5Frm)
1292 Binary |= encodeVFPRn(MI, 2);
1293 else if (Form == ARMII::VFPConv3Frm)
1295 Binary |= encodeVFPRm(MI, 2);
1300 void ARMCodeEmitter::emitVFPLoadStoreInstruction(const MachineInstr &MI) {
1301 // Part of binary is determined by TableGn.
1302 unsigned Binary = getBinaryCodeForInstr(MI);
1304 // Set the conditional execution predicate
1305 Binary |= II->getPredicate(&MI) << ARMII::CondShift;
1310 Binary |= encodeVFPRd(MI, OpIdx++);
1312 // Encode address base.
1313 const MachineOperand &Base = MI.getOperand(OpIdx++);
1314 Binary |= getMachineOpValue(MI, Base) << ARMII::RegRnShift;
1316 // If there is a non-zero immediate offset, encode it.
1318 const MachineOperand &Offset = MI.getOperand(OpIdx);
1319 if (unsigned ImmOffs = ARM_AM::getAM5Offset(Offset.getImm())) {
1320 if (ARM_AM::getAM5Op(Offset.getImm()) == ARM_AM::add)
1321 Binary |= 1 << ARMII::U_BitShift;
1328 // If immediate offset is omitted, default to +0.
1329 Binary |= 1 << ARMII::U_BitShift;
1334 void ARMCodeEmitter::emitVFPLoadStoreMultipleInstruction(
1335 const MachineInstr &MI) {
1336 const TargetInstrDesc &TID = MI.getDesc();
1337 bool IsUpdating = (TID.TSFlags & ARMII::IndexModeMask) != 0;
1339 // Part of binary is determined by TableGn.
1340 unsigned Binary = getBinaryCodeForInstr(MI);
1342 // Set the conditional execution predicate
1343 Binary |= II->getPredicate(&MI) << ARMII::CondShift;
1345 // Skip operand 0 of an instruction with base register update.
1350 // Set base address operand
1351 Binary |= getMachineOpValue(MI, OpIdx++) << ARMII::RegRnShift;
1353 // Set addressing mode by modifying bits U(23) and P(24)
1354 const MachineOperand &MO = MI.getOperand(OpIdx++);
1355 Binary |= getAddrModeUPBits(ARM_AM::getAM5SubMode(MO.getImm()));
1358 if (ARM_AM::getAM5WBFlag(MO.getImm()))
1359 Binary |= 0x1 << ARMII::W_BitShift;
1361 // First register is encoded in Dd.
1362 Binary |= encodeVFPRd(MI, OpIdx+2);
1364 // Number of registers are encoded in offset field.
1365 unsigned NumRegs = 1;
1366 for (unsigned i = OpIdx+3, e = MI.getNumOperands(); i != e; ++i) {
1367 const MachineOperand &MO = MI.getOperand(i);
1368 if (!MO.isReg() || MO.isImplicit())
1372 Binary |= NumRegs * 2;
1377 void ARMCodeEmitter::emitMiscInstruction(const MachineInstr &MI) {
1378 // Part of binary is determined by TableGn.
1379 unsigned Binary = getBinaryCodeForInstr(MI);
1381 // Set the conditional execution predicate
1382 Binary |= II->getPredicate(&MI) << ARMII::CondShift;
1387 #include "ARMGenCodeEmitter.inc"