-/// \brief Do initial placement of the jump tables. Because Thumb2's TBB and TBH
-/// instructions can be made more efficient if the jump table immediately
-/// follows the instruction, it's best to place them immediately next to their
-/// jumps to begin with. In almost all cases they'll never be moved from that
-/// position.
-void ARMConstantIslands::doInitialJumpTablePlacement(
- std::vector<MachineInstr *> &CPEMIs) {
- unsigned i = CPEntries.size();
- auto MJTI = MF->getJumpTableInfo();
- const std::vector<MachineJumpTableEntry> &JT = MJTI->getJumpTables();
-
- MachineBasicBlock *LastCorrectlyNumberedBB = nullptr;
- for (MachineBasicBlock &MBB : *MF) {
- auto MI = MBB.getLastNonDebugInstr();
-
- unsigned JTOpcode;
- switch (MI->getOpcode()) {
- default:
- continue;
- case ARM::BR_JTadd:
- case ARM::BR_JTr:
- case ARM::tBR_JTr:
- case ARM::BR_JTm:
- JTOpcode = ARM::JUMPTABLE_ADDRS;
- break;
- case ARM::t2BR_JT:
- JTOpcode = ARM::JUMPTABLE_INSTS;
- break;
- case ARM::t2TBB_JT:
- JTOpcode = ARM::JUMPTABLE_TBB;
- break;
- case ARM::t2TBH_JT:
- JTOpcode = ARM::JUMPTABLE_TBH;
- break;
- }
-
- unsigned NumOps = MI->getDesc().getNumOperands();
- MachineOperand JTOp =
- MI->getOperand(NumOps - (MI->isPredicable() ? 2 : 1));
- unsigned JTI = JTOp.getIndex();
- unsigned Size = JT[JTI].MBBs.size() * sizeof(uint32_t);
- MachineBasicBlock *JumpTableBB = MF->CreateMachineBasicBlock();
- MF->insert(std::next(MachineFunction::iterator(MBB)), JumpTableBB);
- MachineInstr *CPEMI = BuildMI(*JumpTableBB, JumpTableBB->begin(),
- DebugLoc(), TII->get(JTOpcode))
- .addImm(i++)
- .addJumpTableIndex(JTI)
- .addImm(Size);
- CPEMIs.push_back(CPEMI);
- CPEntries.emplace_back(1, CPEntry(CPEMI, JTI));
- JumpTableEntryIndices.insert(std::make_pair(JTI, CPEntries.size() - 1));
- if (!LastCorrectlyNumberedBB)
- LastCorrectlyNumberedBB = &MBB;
- }
-
- // If we did anything then we need to renumber the subsequent blocks.
- if (LastCorrectlyNumberedBB)
- MF->RenumberBlocks(LastCorrectlyNumberedBB);
-}
-