15 #define DEBUG_TYPE "jit"
43 STATISTIC(NumEmitted,
"Number of machine instructions emitted");
55 const std::vector<MachineConstantPoolEntry> *MCPEs;
56 const std::vector<MachineJumpTableEntry> *MJTEs;
70 TD(tm.getDataLayout()),
TM(tm),
71 MCE(mce), MCPEs(0), MJTEs(0),
72 IsPIC(
TM.getRelocationModel() == Reloc::
PIC_), IsThumb(
false) {}
81 virtual const char *getPassName()
const {
82 return "ARM Machine Code Emitter";
89 void emitWordLE(
unsigned Binary);
90 void emitDWordLE(uint64_t
Binary);
96 void addPCLabel(
unsigned LabelID);
103 unsigned getMachineSoImmOpValue(
unsigned SoImm);
108 unsigned ImplicitRd = 0,
109 unsigned ImplicitRn = 0);
112 unsigned ImplicitRd = 0,
113 unsigned ImplicitRn = 0);
116 unsigned ImplicitRn = 0);
130 void emitInlineJumpTable(
unsigned JTIndex);
152 unsigned getMachineOpValue(
const MachineInstr &
MI,
unsigned OpIdx)
const {
153 return getMachineOpValue(MI, MI.
getOperand(OpIdx));
164 unsigned NEONThumb2DataIPostEncoder(
const MachineInstr &MI,
unsigned Val)
166 unsigned NEONThumb2LoadStorePostEncoder(
const MachineInstr &MI,
unsigned Val)
168 unsigned NEONThumb2DupPostEncoder(
const MachineInstr &MI,
unsigned Val)
170 unsigned NEONThumb2V8PostEncoder(
const MachineInstr &MI,
unsigned Val)
172 unsigned VFPThumb2PostEncoder(
const MachineInstr&MI,
unsigned Val)
174 unsigned getAdrLabelOpValue(
const MachineInstr &MI,
unsigned Op)
176 unsigned getThumbAdrLabelOpValue(
const MachineInstr &MI,
unsigned Op)
178 unsigned getThumbBLTargetOpValue(
const MachineInstr &MI,
unsigned Op)
180 unsigned getThumbBLXTargetOpValue(
const MachineInstr &MI,
unsigned Op)
182 unsigned getThumbBRTargetOpValue(
const MachineInstr &MI,
unsigned Op)
184 unsigned getThumbBCCTargetOpValue(
const MachineInstr &MI,
unsigned Op)
186 unsigned getThumbCBTargetOpValue(
const MachineInstr &MI,
unsigned Op)
190 unsigned getUnconditionalBranchTargetOpValue(
const MachineInstr &MI,
191 unsigned Op)
const {
return 0; }
192 unsigned getARMBranchTargetOpValue(
const MachineInstr &MI,
unsigned Op)
194 unsigned getARMBLTargetOpValue(
const MachineInstr &MI,
unsigned Op)
196 unsigned getARMBLXTargetOpValue(
const MachineInstr &MI,
unsigned Op)
198 unsigned getCCOutOpValue(
const MachineInstr &MI,
unsigned Op)
200 unsigned getSOImmOpValue(
const MachineInstr &MI,
unsigned Op)
202 unsigned getT2SOImmOpValue(
const MachineInstr &MI,
unsigned Op)
204 unsigned getSORegRegOpValue(
const MachineInstr &MI,
unsigned Op)
206 unsigned getSORegImmOpValue(
const MachineInstr &MI,
unsigned Op)
208 unsigned getThumbAddrModeRegRegOpValue(
const MachineInstr &MI,
unsigned Op)
210 unsigned getT2AddrModeImm12OpValue(
const MachineInstr &MI,
unsigned Op)
212 unsigned getT2AddrModeImm8OpValue(
const MachineInstr &MI,
unsigned Op)
214 unsigned getT2Imm8s4OpValue(
const MachineInstr &MI,
unsigned Op)
216 unsigned getT2AddrModeImm8s4OpValue(
const MachineInstr &MI,
unsigned Op)
218 unsigned getT2AddrModeImm0_1020s4OpValue(
const MachineInstr &MI,
unsigned Op)
220 unsigned getT2AddrModeImm8OffsetOpValue(
const MachineInstr &MI,
unsigned Op)
222 unsigned getT2AddrModeImm12OffsetOpValue(
const MachineInstr &MI,
unsigned Op)
224 unsigned getT2AddrModeSORegOpValue(
const MachineInstr &MI,
unsigned Op)
226 unsigned getT2SORegOpValue(
const MachineInstr &MI,
unsigned Op)
228 unsigned getT2AdrLabelOpValue(
const MachineInstr &MI,
unsigned Op)
230 unsigned getAddrMode6AddressOpValue(
const MachineInstr &MI,
unsigned Op)
232 unsigned getAddrMode6OneLane32AddressOpValue(
const MachineInstr &MI,
235 unsigned getAddrMode6DupAddressOpValue(
const MachineInstr &MI,
unsigned Op)
237 unsigned getAddrMode6OffsetOpValue(
const MachineInstr &MI,
unsigned Op)
239 unsigned getBitfieldInvertedMaskOpValue(
const MachineInstr &MI,
240 unsigned Op)
const {
return 0; }
242 unsigned Op)
const {
return 0; }
243 uint32_t getLdStmModeOpValue(
const MachineInstr &MI,
unsigned OpIdx)
245 uint32_t getLdStSORegOpValue(
const MachineInstr &MI,
unsigned OpIdx)
248 unsigned getAddrModeImm12OpValue(
const MachineInstr &MI,
unsigned Op)
259 unsigned Reg = II->getRegisterInfo().getEncodingValue(MO.
getReg());
260 int32_t Imm12 = MO1.
getImm();
262 Binary = Imm12 & 0xfff;
265 Binary |= (Reg << 13);
269 unsigned getHiLo16ImmOpValue(
const MachineInstr &MI,
unsigned Op)
const {
273 uint32_t getAddrMode2OpValue(
const MachineInstr &MI,
unsigned OpIdx)
275 uint32_t getAddrMode2OffsetOpValue(
const MachineInstr &MI,
unsigned OpIdx)
277 uint32_t getPostIdxRegOpValue(
const MachineInstr &MI,
unsigned OpIdx)
279 uint32_t getAddrMode3OffsetOpValue(
const MachineInstr &MI,
unsigned OpIdx)
281 uint32_t getAddrMode3OpValue(
const MachineInstr &MI,
unsigned Op)
283 uint32_t getAddrModeThumbSPOpValue(
const MachineInstr &MI,
unsigned Op)
285 uint32_t getAddrModeSOpValue(
const MachineInstr &MI,
unsigned Op)
287 uint32_t getAddrModeISOpValue(
const MachineInstr &MI,
unsigned Op)
289 uint32_t getAddrModePCOpValue(
const MachineInstr &MI,
unsigned Op)
291 uint32_t getAddrMode5OpValue(
const MachineInstr &MI,
unsigned Op)
const {
301 unsigned Reg = II->getRegisterInfo().getEncodingValue(MO.
getReg());
302 int32_t Imm12 = MO1.
getImm();
305 if (Imm12 == INT32_MIN)
316 uint32_t Binary = Imm12 & 0xfff;
319 Binary |= (Reg << 13);
322 unsigned getNEONVcvtImm32OpValue(
const MachineInstr &MI,
unsigned Op)
325 unsigned getRegisterListOpValue(
const MachineInstr &MI,
unsigned Op)
328 unsigned getShiftRight8Imm(
const MachineInstr &MI,
unsigned Op)
330 unsigned getShiftRight16Imm(
const MachineInstr &MI,
unsigned Op)
332 unsigned getShiftRight32Imm(
const MachineInstr &MI,
unsigned Op)
334 unsigned getShiftRight64Imm(
const MachineInstr &MI,
unsigned Op)
345 unsigned getShiftOp(
unsigned Imm)
const ;
349 void emitGlobalAddress(
const GlobalValue *GV,
unsigned Reloc,
350 bool MayNeedFarStub,
bool Indirect,
352 void emitExternalSymbolAddress(
const char *ES,
unsigned Reloc)
const;
353 void emitConstPoolAddress(
unsigned CPI,
unsigned Reloc)
const;
354 void emitJumpTableAddress(
unsigned JTIndex,
unsigned Reloc)
const;
357 unsigned encodeVFPRd(
const MachineInstr &MI,
unsigned OpIdx)
const;
358 unsigned encodeVFPRn(
const MachineInstr &MI,
unsigned OpIdx)
const;
359 unsigned encodeVFPRm(
const MachineInstr &MI,
unsigned OpIdx)
const;
360 unsigned encodeNEONRd(
const MachineInstr &MI,
unsigned OpIdx)
const;
361 unsigned encodeNEONRn(
const MachineInstr &MI,
unsigned OpIdx)
const;
362 unsigned encodeNEONRm(
const MachineInstr &MI,
unsigned OpIdx)
const;
372 return new ARMCodeEmitter(TM, JCE);
380 "JIT relocation model must be set to static or default!");
392 JTI->Initialize(MF, IsPIC);
393 MMI = &getAnalysis<MachineModuleInfo>();
394 MCE.setModuleInfo(MMI);
399 MCE.startFunction(MF);
402 MCE.StartMachineBasicBlock(MBB);
407 }
while (MCE.finishFunction(MF));
414 unsigned ARMCodeEmitter::getShiftOp(
unsigned Imm)
const {
427 unsigned ARMCodeEmitter::getMovi32Value(
const MachineInstr &MI,
431 &&
"Relocation to this function should be for movt or movw");
434 return static_cast<unsigned>(MO.
getImm());
436 emitGlobalAddress(MO.
getGlobal(), Reloc,
true,
false);
440 emitMachineBasicBlock(MO.
getMBB(), Reloc);
452 unsigned ARMCodeEmitter::getMachineOpValue(
const MachineInstr &MI,
455 return II->getRegisterInfo().getEncodingValue(MO.
getReg());
457 return static_cast<unsigned>(MO.
getImm());
462 else if (MO.
isCPI()) {
467 emitConstPoolAddress(MO.
getIndex(), Reloc);
468 }
else if (MO.
isJTI())
479 void ARMCodeEmitter::emitGlobalAddress(
const GlobalValue *GV,
unsigned Reloc,
480 bool MayNeedFarStub,
bool Indirect,
485 ACPV, MayNeedFarStub)
489 MCE.addRelocation(MR);
495 void ARMCodeEmitter::
496 emitExternalSymbolAddress(
const char *ES,
unsigned Reloc)
const {
504 void ARMCodeEmitter::emitConstPoolAddress(
unsigned CPI,
unsigned Reloc)
const {
507 Reloc, CPI, 0,
true));
513 void ARMCodeEmitter::
514 emitJumpTableAddress(
unsigned JTIndex,
unsigned Reloc)
const {
516 Reloc, JTIndex, 0,
true));
527 void ARMCodeEmitter::emitWordLE(
unsigned Binary) {
530 MCE.emitWordLE(Binary);
533 void ARMCodeEmitter::emitDWordLE(uint64_t Binary) {
536 MCE.emitDWordLE(Binary);
539 void ARMCodeEmitter::emitInstruction(
const MachineInstr &MI) {
540 DEBUG(
errs() <<
"JIT: " << (
void*)MCE.getCurrentPCValue() <<
":\t" <<
MI);
552 emitLEApcrelJTInstruction(MI);
557 emitPseudoInstruction(MI);
561 emitDataProcessingInstruction(MI);
565 emitLoadStoreInstruction(MI);
569 emitMiscLoadStoreInstruction(MI);
572 emitLoadStoreMultipleInstruction(MI);
575 emitMulFrmInstruction(MI);
578 emitExtendInstruction(MI);
581 emitMiscArithInstruction(MI);
584 emitSaturateInstruction(MI);
587 emitBranchInstruction(MI);
590 emitMiscBranchInstruction(MI);
595 emitVFPArithInstruction(MI);
602 emitVFPConversionInstruction(MI);
605 emitVFPLoadStoreInstruction(MI);
608 emitVFPLoadStoreMultipleInstruction(MI);
614 emitNEONLaneInstruction(MI);
617 emitNEONDupInstruction(MI);
620 emitNEON1RegModImmInstruction(MI);
623 emitNEON2RegInstruction(MI);
626 emitNEON3RegInstruction(MI);
632 void ARMCodeEmitter::emitConstPoolInstruction(
const MachineInstr &MI) {
638 JTI->addConstantPoolEntryAddr(CPI, MCE.getCurrentPCValue());
646 DEBUG(
errs() <<
" ** ARM constant pool #" << CPI <<
" @ "
647 << (
void*)MCE.getCurrentPCValue() <<
" " << *ACPV <<
'\n');
649 assert(ACPV->
isGlobalValue() &&
"unsupported constant pool value");
650 const GlobalValue *GV = cast<ARMConstantPoolConstant>(ACPV)->getGV();
655 Subtarget->GVIsIndirectSymbol(GV, RelocM),
658 const char *Sym = cast<ARMConstantPoolSymbol>(ACPV)->getSymbol();
666 errs() <<
" ** Constant pool #" << CPI <<
" @ "
667 << (
void*)MCE.getCurrentPCValue() <<
" ";
668 if (
const Function *
F = dyn_cast<Function>(CV))
669 errs() <<
F->getName();
675 if (
const GlobalValue *GV = dyn_cast<GlobalValue>(CV)) {
678 }
else if (
const ConstantInt *CI = dyn_cast<ConstantInt>(CV)) {
679 uint32_t Val = uint32_t(*CI->getValue().getRawData());
681 }
else if (
const ConstantFP *CFP = dyn_cast<ConstantFP>(CV)) {
682 if (CFP->getType()->isFloatTy())
683 emitWordLE(CFP->getValueAPF().bitcastToAPInt().getZExtValue());
684 else if (CFP->getType()->isDoubleTy())
685 emitDWordLE(CFP->getValueAPF().bitcastToAPInt().getZExtValue());
695 void ARMCodeEmitter::emitMOVi32immInstruction(
const MachineInstr &MI) {
700 unsigned Binary = 0x30 << 20;
711 Binary |= Lo16 & 0xFFF;
712 Binary |= ((Lo16 >> 12) & 0xF) << 16;
726 Binary |= Hi16 & 0xFFF;
727 Binary |= ((Hi16 >> 12) & 0xF) << 16;
731 void ARMCodeEmitter::emitMOVi2piecesInstruction(
const MachineInstr &MI) {
735 "Not a valid so_imm value!");
740 unsigned Binary = 0xd << 21;
751 Binary |= getMachineSoImmOpValue(V1);
769 Binary |= getMachineSoImmOpValue(V2);
773 void ARMCodeEmitter::emitLEApcrelJTInstruction(
const MachineInstr &MI) {
779 unsigned Binary = 0x4 << 21;
785 Binary |= getAddrModeSBit(MI, MCID);
800 void ARMCodeEmitter::emitPseudoMoveInstruction(
const MachineInstr &MI) {
804 unsigned Binary = getBinaryCodeForInstr(MI);
810 if (Opcode == ARM::MOVsrl_flag || Opcode == ARM::MOVsra_flag)
823 case ARM::MOVsrl_flag:
825 Binary |= (0x2 << 4) | (1 << 7);
827 case ARM::MOVsra_flag:
829 Binary |= (0x4 << 4) | (1 << 7);
834 Binary |= getMachineOpValue(MI, 1);
839 void ARMCodeEmitter::addPCLabel(
unsigned LabelID) {
840 DEBUG(
errs() <<
" ** LPC" << LabelID <<
" @ "
841 << (
void*)MCE.getCurrentPCValue() <<
'\n');
842 JTI->addPCLabelAddr(LabelID, MCE.getCurrentPCValue());
845 void ARMCodeEmitter::emitPseudoInstruction(
const MachineInstr &MI) {
851 case ARM::BMOVPCRX_CALL: {
853 unsigned Binary = 0x01a0e00f;
858 emitMiscBranchInstruction(MI);
877 case ARM::CONSTPOOL_ENTRY:
878 emitConstPoolInstruction(MI);
884 emitDataProcessingInstruction(MI, 0, ARM::PC);
894 emitLoadStoreInstruction(MI, 0, ARM::PC);
904 emitMiscLoadStoreInstruction(MI, ARM::PC);
910 if (Subtarget->hasV6T2Ops())
911 emitMOVi32immInstruction(MI);
913 emitMOVi2piecesInstruction(MI);
916 case ARM::LEApcrelJT:
918 emitLEApcrelJTInstruction(MI);
921 case ARM::MOVsrl_flag:
922 case ARM::MOVsra_flag:
923 emitPseudoMoveInstruction(MI);
928 unsigned ARMCodeEmitter::getMachineSoRegOpValue(
const MachineInstr &MI,
932 unsigned Binary = getMachineOpValue(MI, MO);
940 unsigned Rs = MO1.
getReg();
970 Binary |= SBits << 4;
978 return Binary | (II->getRegisterInfo().getEncodingValue(Rs) <<
ARMII::RegRsShift);
985 unsigned ARMCodeEmitter::getMachineSoImmOpValue(
unsigned SoImm) {
987 assert(SoImmVal != -1 &&
"Not a valid so_imm value!");
998 unsigned ARMCodeEmitter::getAddrModeSBit(
const MachineInstr &MI,
1008 void ARMCodeEmitter::emitDataProcessingInstruction(
const MachineInstr &MI,
1009 unsigned ImplicitRd,
1010 unsigned ImplicitRn) {
1014 unsigned Binary = getBinaryCodeForInstr(MI);
1020 Binary |= getAddrModeSBit(MI, MCID);
1027 else if (ImplicitRd)
1029 Binary |= (II->getRegisterInfo().getEncodingValue(ImplicitRd) <<
ARMII::RegRdShift);
1031 if (MCID.
Opcode == ARM::MOVi16) {
1033 unsigned Lo16 = getMovi32Value(MI, MI.
getOperand(OpIdx),
1036 Binary |= Lo16 & 0xFFF;
1037 Binary |= ((Lo16 >> 12) & 0xF) << 16;
1040 }
else if(MCID.
Opcode == ARM::MOVTi16) {
1041 unsigned Hi16 = (getMovi32Value(MI, MI.
getOperand(OpIdx),
1043 Binary |= Hi16 & 0xFFF;
1044 Binary |= ((Hi16 >> 12) & 0xF) << 16;
1052 Binary |= (msb & 0x1F) << 16;
1053 Binary |= (lsb & 0x1F) << 7;
1058 Binary |= getMachineOpValue(MI, OpIdx++);
1064 Binary |= (widthm1 & 0x1F) << 16;
1065 Binary |= (lsb & 0x1F) << 7;
1079 Binary |= (II->getRegisterInfo().getEncodingValue(ImplicitRn) <<
ARMII::RegRnShift);
1090 emitWordLE(Binary | getMachineSoRegOpValue(MI, MCID, MO, OpIdx));
1096 emitWordLE(Binary | II->getRegisterInfo().getEncodingValue(MO.
getReg()));
1101 Binary |= getMachineSoImmOpValue((
unsigned)MO.
getImm());
1106 void ARMCodeEmitter::emitLoadStoreInstruction(
const MachineInstr &MI,
1107 unsigned ImplicitRd,
1108 unsigned ImplicitRn) {
1114 unsigned Binary = getBinaryCodeForInstr(MI);
1130 bool Skipped =
false;
1139 Binary |= (II->getRegisterInfo().getEncodingValue(ImplicitRd) <<
ARMII::RegRdShift);
1146 Binary |= (II->getRegisterInfo().getEncodingValue(ImplicitRn) <<
ARMII::RegRnShift);
1155 unsigned AM2Opc = (ImplicitRn == ARM::PC)
1173 Binary |= II->getRegisterInfo().getEncodingValue(MO2.
getReg());
1185 void ARMCodeEmitter::emitMiscLoadStoreInstruction(
const MachineInstr &MI,
1186 unsigned ImplicitRn) {
1192 unsigned Binary = getBinaryCodeForInstr(MI);
1201 bool Skipped =
false;
1211 if (MCID.
Opcode == ARM::LDRD || MCID.
Opcode == ARM::STRD)
1217 Binary |= (II->getRegisterInfo().getEncodingValue(ImplicitRn) <<
ARMII::RegRnShift);
1226 unsigned AM3Opc = (ImplicitRn == ARM::PC)
1236 Binary |= II->getRegisterInfo().getEncodingValue(MO2.
getReg());
1246 Binary |= (ImmOffs & 0xF);
1253 unsigned Binary = 0;
1271 void ARMCodeEmitter::emitLoadStoreMultipleInstruction(
const MachineInstr &MI) {
1276 unsigned Binary = getBinaryCodeForInstr(MI);
1298 for (
unsigned i = OpIdx+2, e = MI.
getNumOperands(); i != e; ++i) {
1302 unsigned RegNum = II->getRegisterInfo().getEncodingValue(MO.
getReg());
1305 Binary |= 0x1 << RegNum;
1311 void ARMCodeEmitter::emitMulFrmInstruction(
const MachineInstr &MI) {
1315 unsigned Binary = getBinaryCodeForInstr(MI);
1321 Binary |= getAddrModeSBit(MI, MCID);
1333 Binary |= getMachineOpValue(MI, OpIdx++);
1348 void ARMCodeEmitter::emitExtendInstruction(
const MachineInstr &MI) {
1352 unsigned Binary = getBinaryCodeForInstr(MI);
1370 Binary |= getMachineOpValue(MI, MO2);
1373 Binary |= getMachineOpValue(MI, MO1);
1385 void ARMCodeEmitter::emitMiscArithInstruction(
const MachineInstr &MI) {
1389 unsigned Binary = getBinaryCodeForInstr(MI);
1395 if (MCID.
Opcode == ARM::PKHBT || MCID.
Opcode == ARM::PKHTB) {
1410 Binary |= getMachineOpValue(MI, MO);
1419 Binary |= getMachineOpValue(MI, OpIdx++);
1423 if (MCID.
Opcode == ARM::PKHTB) {
1424 assert(ShiftAmt != 0 &&
"PKHTB shift_imm is 0!");
1428 assert(ShiftAmt < 32 &&
"shift_imm range is 0 to 31!");
1434 void ARMCodeEmitter::emitSaturateInstruction(
const MachineInstr &MI) {
1438 unsigned Binary = getBinaryCodeForInstr(MI);
1448 if (MCID.
Opcode == ARM::SSAT || MCID.
Opcode == ARM::SSAT16)
1450 assert((Pos < 16 || (Pos < 32 &&
1451 MCID.
Opcode != ARM::SSAT16 &&
1452 MCID.
Opcode != ARM::USAT16)) &&
1453 "saturate bit position out of range");
1454 Binary |= Pos << 16;
1457 Binary |= getMachineOpValue(MI, 2);
1468 assert(ShiftAmt < 32 &&
"shift_imm range is 0 to 31!");
1475 void ARMCodeEmitter::emitBranchInstruction(
const MachineInstr &MI) {
1478 if (MCID.
Opcode == ARM::TPsoft) {
1483 unsigned Binary = getBinaryCodeForInstr(MI);
1489 Binary |= getMachineOpValue(MI, 0);
1494 void ARMCodeEmitter::emitInlineJumpTable(
unsigned JTIndex) {
1496 uintptr_t JTBase = MCE.getCurrentPCValue();
1497 JTI->addJumpTableBaseAddr(JTIndex, JTBase);
1498 DEBUG(
errs() <<
" ** Jump Table #" << JTIndex <<
" @ " << (
void*)JTBase
1502 const std::vector<MachineBasicBlock*> &MBBs = (*MJTEs)[JTIndex].MBBs;
1503 for (
unsigned i = 0, e = MBBs.size(); i != e; ++i) {
1514 void ARMCodeEmitter::emitMiscBranchInstruction(
const MachineInstr &MI) {
1518 if (MCID.
Opcode == ARM::BR_JTr || MCID.
Opcode == ARM::BR_JTadd) {
1520 emitDataProcessingInstruction(MI, ARM::PC);
1524 (MCID.
Opcode == ARM::BR_JTr)
1526 emitInlineJumpTable(JTIndex);
1528 }
else if (MCID.
Opcode == ARM::BR_JTm) {
1530 emitLoadStoreInstruction(MI, ARM::PC);
1538 unsigned Binary = getBinaryCodeForInstr(MI);
1543 if (MCID.
Opcode == ARM::BX_RET || MCID.
Opcode == ARM::MOVPCLR)
1545 Binary |= II->getRegisterInfo().getEncodingValue(ARM::LR);
1548 Binary |= getMachineOpValue(MI, 0);
1553 unsigned ARMCodeEmitter::encodeVFPRd(
const MachineInstr &MI,
1554 unsigned OpIdx)
const {
1556 unsigned Binary = 0;
1557 bool isSPVFP = ARM::SPRRegClass.contains(RegD);
1558 RegD = II->getRegisterInfo().getEncodingValue(RegD);
1568 unsigned ARMCodeEmitter::encodeVFPRn(
const MachineInstr &MI,
1569 unsigned OpIdx)
const {
1571 unsigned Binary = 0;
1572 bool isSPVFP = ARM::SPRRegClass.contains(RegN);
1573 RegN = II->getRegisterInfo().getEncodingValue(RegN);
1583 unsigned ARMCodeEmitter::encodeVFPRm(
const MachineInstr &MI,
1584 unsigned OpIdx)
const {
1586 unsigned Binary = 0;
1587 bool isSPVFP = ARM::SPRRegClass.contains(RegM);
1588 RegM = II->getRegisterInfo().getEncodingValue(RegM);
1592 Binary |= ((RegM & 0x1E) >> 1);
1598 void ARMCodeEmitter::emitVFPArithInstruction(
const MachineInstr &MI) {
1602 unsigned Binary = getBinaryCodeForInstr(MI);
1613 Binary |= encodeVFPRd(MI, OpIdx++);
1621 Binary |= encodeVFPRn(MI, OpIdx++);
1632 Binary |= encodeVFPRm(MI, OpIdx);
1637 void ARMCodeEmitter::emitVFPConversionInstruction(
const MachineInstr &MI) {
1642 unsigned Binary = getBinaryCodeForInstr(MI);
1653 Binary |= encodeVFPRd(MI, 0);
1657 Binary |= encodeVFPRn(MI, 0);
1661 Binary |= encodeVFPRm(MI, 0);
1669 Binary |= encodeVFPRm(MI, 1);
1674 Binary |= encodeVFPRn(MI, 1);
1679 Binary |= encodeVFPRd(MI, 1);
1685 Binary |= encodeVFPRn(MI, 2);
1688 Binary |= encodeVFPRm(MI, 2);
1693 void ARMCodeEmitter::emitVFPLoadStoreInstruction(
const MachineInstr &MI) {
1695 unsigned Binary = getBinaryCodeForInstr(MI);
1703 Binary |= encodeVFPRd(MI, OpIdx++);
1728 ARMCodeEmitter::emitVFPLoadStoreMultipleInstruction(
const MachineInstr &MI) {
1733 unsigned Binary = getBinaryCodeForInstr(MI);
1755 Binary |= encodeVFPRd(MI, OpIdx+2);
1758 unsigned NumRegs = 1;
1759 for (
unsigned i = OpIdx+3, e = MI.
getNumOperands(); i != e; ++i) {
1768 Binary |= NumRegs * 2;
1775 unsigned ARMCodeEmitter::encodeNEONRd(
const MachineInstr &MI,
1776 unsigned OpIdx)
const {
1778 unsigned Binary = 0;
1779 RegD = II->getRegisterInfo().getEncodingValue(RegD);
1785 unsigned ARMCodeEmitter::encodeNEONRn(
const MachineInstr &MI,
1786 unsigned OpIdx)
const {
1788 unsigned Binary = 0;
1789 RegN = II->getRegisterInfo().getEncodingValue(RegN);
1795 unsigned ARMCodeEmitter::encodeNEONRm(
const MachineInstr &MI,
1796 unsigned OpIdx)
const {
1798 unsigned Binary = 0;
1799 RegM = II->getRegisterInfo().getEncodingValue(RegM);
1800 Binary |= (RegM & 0xf);
1808 assert((Binary & 0xfe000000) == 0xf2000000 &&
1809 "not an ARM NEON data-processing instruction");
1810 unsigned UBit = (Binary >> 24) & 1;
1811 return 0xef000000 | (UBit << 28) | (Binary & 0xffffff);
1814 void ARMCodeEmitter::emitNEONLaneInstruction(
const MachineInstr &MI) {
1815 unsigned Binary = getBinaryCodeForInstr(MI);
1817 unsigned RegTOpIdx, RegNOpIdx, LnOpIdx;
1833 RegT = II->getRegisterInfo().getEncodingValue(RegT);
1835 Binary |= encodeNEONRn(MI, RegNOpIdx);
1838 if ((Binary & (1 << 22)) != 0)
1840 else if ((Binary & (1 << 5)) != 0)
1846 unsigned Opc1 = Lane >> 2;
1847 unsigned Opc2 = Lane & 3;
1848 assert((Opc1 & 3) == 0 &&
"out-of-range lane number operand");
1849 Binary |= (Opc1 << 21);
1850 Binary |= (Opc2 << 5);
1855 void ARMCodeEmitter::emitNEONDupInstruction(
const MachineInstr &MI) {
1856 unsigned Binary = getBinaryCodeForInstr(MI);
1862 RegT = II->getRegisterInfo().getEncodingValue(RegT);
1864 Binary |= encodeNEONRn(MI, 0);
1868 void ARMCodeEmitter::emitNEON1RegModImmInstruction(
const MachineInstr &MI) {
1869 unsigned Binary = getBinaryCodeForInstr(MI);
1871 Binary |= encodeNEONRd(MI, 0);
1874 unsigned Op = (Imm >> 12) & 1;
1875 unsigned Cmode = (Imm >> 8) & 0xf;
1876 unsigned I = (Imm >> 7) & 1;
1877 unsigned Imm3 = (Imm >> 4) & 0x7;
1878 unsigned Imm4 = Imm & 0xf;
1879 Binary |= (I << 24) | (Imm3 << 16) | (Cmode << 8) | (Op << 5) | Imm4;
1885 void ARMCodeEmitter::emitNEON2RegInstruction(
const MachineInstr &MI) {
1887 unsigned Binary = getBinaryCodeForInstr(MI);
1890 Binary |= encodeNEONRd(MI, OpIdx++);
1893 Binary |= encodeNEONRm(MI, OpIdx);
1900 void ARMCodeEmitter::emitNEON3RegInstruction(
const MachineInstr &MI) {
1902 unsigned Binary = getBinaryCodeForInstr(MI);
1905 Binary |= encodeNEONRd(MI, OpIdx++);
1908 Binary |= encodeNEONRn(MI, OpIdx++);
1911 Binary |= encodeNEONRm(MI, OpIdx);
1918 #include "ARMGenCodeEmitter.inc"
MachineConstantPoolValue * MachineCPVal
AMSubMode getLoadStoreMultipleSubMode(int Opcode)
const GlobalValue * getGlobal() const
static unsigned char getAM3Offset(unsigned AM3Opc)
Reloc::Model getRelocationModel() const
MachineBasicBlock * getMBB() const
STATISTIC(NumEmitted,"Number of machine instructions emitted")
unsigned getNumDefs() const
Return the number of MachineOperands that are register definitions. Register definitions always occur...
const MCInstrDesc & getDesc() const
const char * getSymbolName() const
LLVM_ATTRIBUTE_NORETURN void report_fatal_error(const char *reason, bool gen_crash_diag=true)
bool isGlobalValue() const
const std::vector< MachineJumpTableEntry > & getJumpTables() const
bool isJTI() const
isJTI - Tests if this is a MO_JumpTableIndex operand.
AnalysisUsage & addRequired()
bool isImm() const
isImm - Tests if this is a MO_Immediate operand.
#define llvm_unreachable(msg)
bool isReg() const
isReg - Tests if this is a MO_Register operand.
static MachineRelocation getIndirectSymbol(uintptr_t offset, unsigned RelocationType, GlobalValue *GV, intptr_t cst=0, bool MayNeedFarStub=0, bool GOTrelative=0)
static AMSubMode getAM4SubMode(unsigned Mode)
enable_if_c< std::numeric_limits< T >::is_integer &&!std::numeric_limits< T >::is_signed, std::size_t >::type countLeadingZeros(T Val, ZeroBehavior ZB=ZB_Width)
Count number of 0's from the most significant bit to the least stopping at the first 1...
ID
LLVM Calling Convention Representation.
static uint32_t getBranchTargetOpValue(const MCInst &MI, unsigned OpIdx, unsigned FixupKind, SmallVectorImpl< MCFixup > &Fixups)
unsigned getNumOperands() const
bool isCPI() const
isCPI - Tests if this is a MO_ConstantPoolIndex operand.
bool isGlobal() const
isGlobal - Tests if this is a MO_GlobalAddress operand.
FunctionPass * createARMJITCodeEmitterPass(ARMBaseTargetMachine &TM, JITCodeEmitter &JCE)
enable_if_c< std::numeric_limits< T >::is_integer &&!std::numeric_limits< T >::is_signed, std::size_t >::type countTrailingZeros(T Val, ZeroBehavior ZB=ZB_Width)
Count number of 0's from the least significant bit to the most stopping at the first 1...
raw_ostream & write_hex(unsigned long long N)
write_hex - Output N in hexadecimal, without any prefix or padding.
const MachineJumpTableInfo * getJumpTableInfo() const
An entry in a MachineConstantPool.
static MachineRelocation getBB(uintptr_t offset, unsigned RelocationType, MachineBasicBlock *MBB, intptr_t cst=0)
bool isMachineConstantPoolEntry() const
const Constant * ConstVal
static unsigned getSOImmValRot(unsigned Imm)
bundle_iterator< MachineInstr, instr_iterator > iterator
static unsigned convertNEONDataProcToThumb(unsigned Binary)
bool isOptionalDef() const
LLVM Constant Representation.
static unsigned char getAM5Offset(unsigned AM5Opc)
static unsigned getSOImmTwoPartSecond(unsigned V)
const MachineOperand & getOperand(unsigned i) const
static unsigned getSOImmValImm(unsigned Imm)
bool isSymbol() const
isSymbol - Tests if this is a MO_ExternalSymbol operand.
static unsigned getAddrModeUPBits(unsigned Mode)
MachineConstantPool * getConstantPool()
union llvm::MachineConstantPoolEntry::@29 Val
The constant itself.
virtual TargetJITInfo * getJITInfo()
int getOperandConstraint(unsigned OpNum, MCOI::OperandConstraint Constraint) const
Returns the value of the specific constraint if it is set. Returns -1 if it is not set...
static AddrOpc getAM2Op(unsigned AM2Opc)
virtual const TargetInstrInfo * getInstrInfo() const
Class for constant integers.
static unsigned getAM2Offset(unsigned AM2Opc)
bool isMBB() const
isMBB - Tests if this is a MO_MachineBasicBlock operand.
static bool isSOImmTwoPartVal(unsigned V)
static AddrOpc getAM3Op(unsigned AM3Opc)
static int getSOImmVal(unsigned Arg)
static bool isPhysicalRegister(unsigned Reg)
virtual void getAnalysisUsage(AnalysisUsage &AU) const
IMPLICIT_DEF - This is the MachineInstr-level equivalent of undef.
virtual const DataLayout * getDataLayout() const
MCSymbol * getMCSymbol() const
const TargetMachine & getTarget() const
static AddrOpc getAM5Op(unsigned AM5Opc)
static MachineRelocation getJumpTable(uintptr_t offset, unsigned RelocationType, unsigned JTI, intptr_t cst=0, bool letTargetResolve=false)
unsigned getReg() const
getReg - Returns the register number.
static MachineRelocation getConstPool(uintptr_t offset, unsigned RelocationType, unsigned CPI, intptr_t cst=0, bool letTargetResolve=false)
static ShiftOpc getAM2ShiftOpc(unsigned AM2Opc)
static unsigned getSORegOffset(unsigned Op)
unsigned getNumOperands() const
Return the number of declared MachineOperands for this MachineInstruction. Note that variadic (isVari...
const MCOperandInfo * OpInfo
BasicBlockListType::iterator iterator
const std::vector< MachineConstantPoolEntry > & getConstants() const
StringRef getName() const
static unsigned getSOImmTwoPartFirst(unsigned V)
static MachineRelocation getExtSym(uintptr_t offset, unsigned RelocationType, const char *ES, intptr_t cst=0, bool GOTrelative=0, bool NeedStub=true)
INITIALIZE_PASS(GlobalMerge,"global-merge","Global Merge", false, false) bool GlobalMerge const DataLayout * TD
DebugLoc getDebugLoc() const
static ShiftOpc getSORegShOp(unsigned Op)