llvm.org GIT mirror llvm / 04f15b4
* Set the low bit of the return address when we are in thumb mode. * Some code cleanup. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@141317 91177308-0d34-0410-b5e6-96231b3b80d8 Bill Wendling 8 years ago
1 changed file(s) with 104 addition(s) and 87 deletion(s). Raw diff Collapse all Expand all
55115511 const TargetRegisterClass *TRC =
55125512 isThumb ? ARM::tGPRRegisterClass : ARM::GPRRegisterClass;
55135513
5514 // Get a mapping of the call site numbers to all of the landing pads they're
5515 // associated with.
5516 DenseMap > CallSiteNumToLPad;
5517 unsigned MaxCSNum = 0;
5518 MachineModuleInfo &MMI = MF->getMMI();
5519 for (MachineFunction::iterator BB = MF->begin(), E = MF->end(); BB != E; ++BB) {
5520 if (!BB->isLandingPad()) continue;
5521
5522 // FIXME: We should assert that the EH_LABEL is the first MI in the landing
5523 // pad.
5524 for (MachineBasicBlock::iterator
5525 II = BB->begin(), IE = BB->end(); II != IE; ++II) {
5526 if (!II->isEHLabel()) continue;
5527
5528 MCSymbol *Sym = II->getOperand(0).getMCSymbol();
5529 if (!MMI.hasCallSiteLandingPad(Sym)) continue;
5530
5531 SmallVectorImpl &CallSiteIdxs = MMI.getCallSiteLandingPad(Sym);
5532 for (SmallVectorImpl::iterator
5533 CSI = CallSiteIdxs.begin(), CSE = CallSiteIdxs.end();
5534 CSI != CSE; ++CSI) {
5535 CallSiteNumToLPad[*CSI].push_back(BB);
5536 MaxCSNum = std::max(MaxCSNum, *CSI);
5537 }
5538 break;
5539 }
5540 }
5541
5542 // Get an ordered list of the machine basic blocks for the jump table.
5543 std::vector LPadList;
5544 LPadList.reserve(CallSiteNumToLPad.size());
5545 for (unsigned I = 1; I <= MaxCSNum; ++I) {
5546 SmallVectorImpl &MBBList = CallSiteNumToLPad[I];
5547 for (SmallVectorImpl::iterator
5548 II = MBBList.begin(), IE = MBBList.end(); II != IE; ++II)
5549 LPadList.push_back(*II);
5550 }
5551
5552 assert(!LPadList.empty() &&
5553 "No landing pad destinations for the dispatch jump table!");
5554
5555 // Create the jump table and associated information.
5556 MachineJumpTableInfo *JTI =
5557 MF->getOrCreateJumpTableInfo(MachineJumpTableInfo::EK_Inline);
5558 unsigned MJTI = JTI->createJumpTableIndex(LPadList);
5559 unsigned UId = AFI->createJumpTableUId();
5560
5561 // Create the MBBs for the dispatch code.
5562 MachineBasicBlock *TrapBB = MF->CreateMachineBasicBlock();
5563 BuildMI(TrapBB, dl, TII->get(ARM::TRAP));
5564 DispatchBB->addSuccessor(TrapBB);
5565
5566 MachineBasicBlock *DispContBB = MF->CreateMachineBasicBlock();
5567 DispatchBB->addSuccessor(DispContBB);
5568
5569 // Insert and renumber MBBs.
5570 MachineBasicBlock *Last = &MF->back();
5571 MF->insert(MF->end(), DispatchBB);
5572 MF->insert(MF->end(), DispContBB);
5573 MF->insert(MF->end(), TrapBB);
5574 MF->RenumberBlocks(Last);
5575
5576 // Grab constant pool and fixed stack memory operands.
55145577 MachineMemOperand *CPMMO =
55155578 MF->getMachineMemOperand(MachinePointerInfo::getConstantPool(),
55165579 MachineMemOperand::MOLoad, 4, 4);
55225585 // Load the address of the dispatch MBB into the jump buffer.
55235586 if (isThumb2) {
55245587 // Incoming value: jbuf
5525 // ldr.n r1, LCPI1_4
5526 // add r1, pc
5527 // str r5, [$jbuf, #+4] ; &jbuf[1]
5588 // ldr.n r5, LCPI1_1
5589 // orr r5, r5, #1
5590 // add r5, pc
5591 // str r5, [$jbuf, #+4] ; &jbuf[1]
55285592 unsigned NewVReg1 = MRI->createVirtualRegister(TRC);
55295593 AddDefaultPred(BuildMI(*MBB, MI, dl, TII->get(ARM::t2LDRpci), NewVReg1)
5594 .addConstantPoolIndex(CPI)
5595 .addMemOperand(CPMMO));
5596 // Set the low bit because of thumb mode.
5597 unsigned NewVReg2 = MRI->createVirtualRegister(TRC);
5598 AddDefaultCC(
5599 AddDefaultPred(BuildMI(*MBB, MI, dl, TII->get(ARM::t2ORRri), NewVReg2)
5600 .addReg(NewVReg1, RegState::Kill)
5601 .addImm(0x01)));
5602 unsigned NewVReg3 = MRI->createVirtualRegister(TRC);
5603 BuildMI(*MBB, MI, dl, TII->get(ARM::tPICADD), NewVReg3)
5604 .addReg(NewVReg2, RegState::Kill)
5605 .addImm(PCLabelId);
5606 AddDefaultPred(BuildMI(*MBB, MI, dl, TII->get(ARM::t2STRi12))
5607 .addReg(NewVReg3, RegState::Kill)
5608 .addFrameIndex(FI)
5609 .addImm(36) // &jbuf[1] :: pc
5610 .addMemOperand(FIMMO));
5611 } else if (isThumb) {
5612 // Incoming value: jbuf
5613 // ldr.n r1, LCPI1_4
5614 // add r1, pc
5615 // orr r1, r1, #1
5616 // add r2, $jbuf, #+4 ; &jbuf[1]
5617 // str r1, [r2]
5618 unsigned NewVReg1 = MRI->createVirtualRegister(TRC);
5619 AddDefaultPred(BuildMI(*MBB, MI, dl, TII->get(ARM::tLDRpci), NewVReg1)
55305620 .addConstantPoolIndex(CPI)
55315621 .addMemOperand(CPMMO));
55325622 unsigned NewVReg2 = MRI->createVirtualRegister(TRC);
55335623 BuildMI(*MBB, MI, dl, TII->get(ARM::tPICADD), NewVReg2)
55345624 .addReg(NewVReg1, RegState::Kill)
55355625 .addImm(PCLabelId);
5536 AddDefaultPred(BuildMI(*MBB, MI, dl, TII->get(ARM::t2STRi12))
5537 .addReg(NewVReg2, RegState::Kill)
5538 .addFrameIndex(FI)
5539 .addImm(36) // &jbuf[1] :: pc
5540 .addMemOperand(FIMMO));
5541 } else if (isThumb) {
5542 // Incoming value: jbuf
5543 // ldr.n r1, LCPI1_4
5544 // add r1, pc
5545 // add r2, $jbuf, #+4 ; &jbuf[1]
5546 // str r1, [r2]
5547 unsigned NewVReg1 = MRI->createVirtualRegister(TRC);
5548 AddDefaultPred(BuildMI(*MBB, MI, dl, TII->get(ARM::tLDRpci), NewVReg1)
5549 .addConstantPoolIndex(CPI)
5550 .addMemOperand(CPMMO));
5551 unsigned NewVReg2 = MRI->createVirtualRegister(TRC);
5552 BuildMI(*MBB, MI, dl, TII->get(ARM::tPICADD), NewVReg2)
5553 .addReg(NewVReg1)
5554 .addImm(PCLabelId);
5626 // Set the low bit because of thumb mode.
55555627 unsigned NewVReg3 = MRI->createVirtualRegister(TRC);
5556 AddDefaultPred(BuildMI(*MBB, MI, dl, TII->get(ARM::tADDrSPi), NewVReg3)
5628 AddDefaultCC(
5629 AddDefaultPred(BuildMI(*MBB, MI, dl, TII->get(ARM::t2ORRri), NewVReg3)
5630 .addReg(NewVReg2, RegState::Kill)
5631 .addImm(0x01)));
5632 unsigned NewVReg4 = MRI->createVirtualRegister(TRC);
5633 AddDefaultPred(BuildMI(*MBB, MI, dl, TII->get(ARM::tADDrSPi), NewVReg4)
55575634 .addFrameIndex(FI)
55585635 .addImm(36)); // &jbuf[1] :: pc
55595636 AddDefaultPred(BuildMI(*MBB, MI, dl, TII->get(ARM::tSTRi))
5560 .addReg(NewVReg2, RegState::Kill)
55615637 .addReg(NewVReg3, RegState::Kill)
5638 .addReg(NewVReg4, RegState::Kill)
55625639 .addImm(0)
55635640 .addMemOperand(FIMMO));
55645641 } else {
55655642 // Incoming value: jbuf
5566 // ldr r1, LCPI1_1
5567 // add r1, pc, r1
5568 // str r1, [$jbuf, #+4] ; &jbuf[1]
5643 // ldr r1, LCPI1_1
5644 // add r1, pc, r1
5645 // str r1, [$jbuf, #+4] ; &jbuf[1]
55695646 unsigned NewVReg1 = MRI->createVirtualRegister(TRC);
55705647 AddDefaultPred(BuildMI(*MBB, MI, dl, TII->get(ARM::LDRi12), NewVReg1)
55715648 .addConstantPoolIndex(CPI)
55815658 .addImm(36) // &jbuf[1] :: pc
55825659 .addMemOperand(FIMMO));
55835660 }
5584
5585 // Now get a mapping of the call site numbers to all of the landing pads
5586 // they're associated with.
5587 DenseMap > CallSiteNumToLPad;
5588 unsigned MaxCSNum = 0;
5589 MachineModuleInfo &MMI = MF->getMMI();
5590 for (MachineFunction::iterator BB = MF->begin(), E = MF->end(); BB != E; ++BB) {
5591 if (!BB->isLandingPad()) continue;
5592
5593 // FIXME: We should assert that the EH_LABEL is the first MI in the landing
5594 // pad.
5595 for (MachineBasicBlock::iterator
5596 II = BB->begin(), IE = BB->end(); II != IE; ++II) {
5597 if (!II->isEHLabel()) continue;
5598
5599 MCSymbol *Sym = II->getOperand(0).getMCSymbol();
5600 if (!MMI.hasCallSiteLandingPad(Sym)) continue;
5601
5602 SmallVectorImpl &CallSiteIdxs = MMI.getCallSiteLandingPad(Sym);
5603 for (SmallVectorImpl::iterator
5604 CSI = CallSiteIdxs.begin(), CSE = CallSiteIdxs.end();
5605 CSI != CSE; ++CSI) {
5606 CallSiteNumToLPad[*CSI].push_back(BB);
5607 MaxCSNum = std::max(MaxCSNum, *CSI);
5608 }
5609 break;
5610 }
5611 }
5612
5613 // Get an ordered list of the machine basic blocks for the jump table.
5614 std::vector LPadList;
5615 LPadList.reserve(CallSiteNumToLPad.size());
5616 for (unsigned I = 1; I <= MaxCSNum; ++I) {
5617 SmallVectorImpl &MBBList = CallSiteNumToLPad[I];
5618 for (SmallVectorImpl::iterator
5619 II = MBBList.begin(), IE = MBBList.end(); II != IE; ++II)
5620 LPadList.push_back(*II);
5621 }
5622
5623 assert(!LPadList.empty() &&
5624 "No landing pad destinations for the dispatch jump table!");
5625
5626 MachineJumpTableInfo *JTI =
5627 MF->getOrCreateJumpTableInfo(MachineJumpTableInfo::EK_Inline);
5628 unsigned MJTI = JTI->createJumpTableIndex(LPadList);
5629 unsigned UId = AFI->createJumpTableUId();
5630
5631 MachineBasicBlock *TrapBB = MF->CreateMachineBasicBlock();
5632 BuildMI(TrapBB, dl, TII->get(ARM::TRAP));
5633 DispatchBB->addSuccessor(TrapBB);
5634
5635 MachineBasicBlock *DispContBB = MF->CreateMachineBasicBlock();
5636 DispatchBB->addSuccessor(DispContBB);
5637
5638 // Insert and renumber MBBs.
5639 MachineBasicBlock *Last = &MF->back();
5640 MF->insert(MF->end(), DispatchBB);
5641 MF->insert(MF->end(), DispContBB);
5642 MF->insert(MF->end(), TrapBB);
5643 MF->RenumberBlocks(Last);
56445661
56455662 FIMMO = MF->getMachineMemOperand(MachinePointerInfo::getFixedStack(FI),
56465663 MachineMemOperand::MOLoad, 4, 4);