From bb73468e2bfb21160266691e9cdc4c4ea4256b22 Mon Sep 17 00:00:00 2001 From: Bill Wendling Date: Wed, 5 Oct 2011 00:39:32 +0000 Subject: [PATCH] Look at the number of entries in the jump table and jump to a 'trap' block if the value exceeds that number. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@141143 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Target/ARM/ARMISelLowering.cpp | 64 +++++++++++++++++++++++------- 1 file changed, 50 insertions(+), 14 deletions(-) diff --git a/lib/Target/ARM/ARMISelLowering.cpp b/lib/Target/ARM/ARMISelLowering.cpp index e0c079afcda..c988c4aa0d2 100644 --- a/lib/Target/ARM/ARMISelLowering.cpp +++ b/lib/Target/ARM/ARMISelLowering.cpp @@ -5493,11 +5493,9 @@ EmitSjLjDispatchBlock(MachineInstr *MI, MachineBasicBlock *MBB) const { ARMFunctionInfo *AFI = MF->getInfo(); const Function *F = MF->getFunction(); MachineFrameInfo *MFI = MF->getFrameInfo(); - MachineBasicBlock *DispatchBB = MF->CreateMachineBasicBlock(); int FI = MFI->getFunctionContextIndex(); - MachineBasicBlock *Last = &MF->back(); - MF->insert(MF->end(), DispatchBB); - MF->RenumberBlocks(Last); + + MachineBasicBlock *DispatchBB = MF->CreateMachineBasicBlock(); // Shove the dispatch's address into the return slot in the function context. DispatchBB->setIsLandingPad(); @@ -5585,8 +5583,6 @@ EmitSjLjDispatchBlock(MachineInstr *MI, MachineBasicBlock *MBB) const { .addMemOperand(FIMMO)); } - MI->eraseFromParent(); // The instruction is gone now. - // Now get a mapping of the call site numbers to all of the landing pads // they're associated with. DenseMap > CallSiteNumToLPad; @@ -5617,10 +5613,8 @@ EmitSjLjDispatchBlock(MachineInstr *MI, MachineBasicBlock *MBB) const { for (unsigned I = 1; I <= MaxCSNum; ++I) { SmallVectorImpl &MBBList = CallSiteNumToLPad[I]; for (SmallVectorImpl::iterator - II = MBBList.begin(), IE = MBBList.end(); II != IE; ++II) { + II = MBBList.begin(), IE = MBBList.end(); II != IE; ++II) LPadList.push_back(*II); - DispatchBB->addSuccessor(*II); - } } MachineJumpTableInfo *JTI = @@ -5628,34 +5622,76 @@ EmitSjLjDispatchBlock(MachineInstr *MI, MachineBasicBlock *MBB) const { unsigned MJTI = JTI->createJumpTableIndex(LPadList); unsigned UId = AFI->createJumpTableUId(); - FIMMO = MF->getMachineMemOperand(MachinePointerInfo::getFixedStack(FI), - MachineMemOperand::MOLoad, 4, 4); + MachineBasicBlock *TrapBB = MF->CreateMachineBasicBlock(); + BuildMI(TrapBB, dl, TII->get(ARM::TRAP)); + DispatchBB->addSuccessor(TrapBB); + + MachineBasicBlock *DispContBB = MF->CreateMachineBasicBlock(); + DispatchBB->addSuccessor(DispContBB); unsigned NewVReg1 = MRI->createVirtualRegister(TRC); AddDefaultPred(BuildMI(DispatchBB, dl, TII->get(ARM::t2LDRi12), NewVReg1) .addFrameIndex(FI) .addImm(4) .addMemOperand(FIMMO)); + AddDefaultPred(BuildMI(DispatchBB, dl, TII->get(ARM::t2CMPri)) + .addReg(NewVReg1) + .addImm(LPadList.size())); + BuildMI(DispatchBB, dl, TII->get(ARM::t2Bcc)) + .addMBB(TrapBB) + .addImm(ARMCC::HI) + .addReg(ARM::CPSR); + +/* + %vreg11 = t2LDRi12 , 4, pred:14, pred:%noreg; mem:Volatile LD4[%sunkaddr131] rGPR:%vreg11 + t2CMPri %vreg11, 6, pred:14, pred:%noreg, %CPSR; rGPR:%vreg11 + t2Bcc , pred:8, pred:%CPSR +*/ + +/* + %vreg11 = t2LDRi12 , 4, pred:14, pred:%noreg; mem:Volatile LD4[%sunkaddr131] rGPR:%vreg11 + %vreg12 = t2LEApcrelJT , 0, pred:14, pred:%noreg; rGPR:%vreg12 + %vreg13 = t2ADDrs %vreg12, %vreg11, 18, pred:14, pred:%noreg, opt:%noreg; GPRnopc:%vreg13 rGPR:%vreg12,%vreg11 + t2BR_JT %vreg13, %vreg11, , 0; GPRnopc:%vreg13 rGPR:%vreg11 +*/ + + FIMMO = MF->getMachineMemOperand(MachinePointerInfo::getFixedStack(FI), + MachineMemOperand::MOLoad, 4, 4); unsigned NewVReg2 = MRI->createVirtualRegister(TRC); - AddDefaultPred(BuildMI(DispatchBB, dl, TII->get(ARM::t2LEApcrelJT), NewVReg2) + AddDefaultPred(BuildMI(DispContBB, dl, TII->get(ARM::t2LEApcrelJT), NewVReg2) .addJumpTableIndex(MJTI) .addImm(UId)); unsigned NewVReg3 = MRI->createVirtualRegister(TRC); AddDefaultCC( AddDefaultPred( - BuildMI(DispatchBB, dl, TII->get(ARM::t2ADDrs), NewVReg3) + BuildMI(DispContBB, dl, TII->get(ARM::t2ADDrs), NewVReg3) .addReg(NewVReg2, RegState::Kill) .addReg(NewVReg1) .addImm(18))); - BuildMI(DispatchBB, dl, TII->get(ARM::t2BR_JT)) + BuildMI(DispContBB, dl, TII->get(ARM::t2BR_JT)) .addReg(NewVReg3, RegState::Kill) .addReg(NewVReg1) .addJumpTableIndex(MJTI) .addImm(UId); + // Add the jump table entries as successors to the MBB. + for (std::vector::iterator + I = LPadList.begin(), E = LPadList.end(); I != E; ++I) + DispContBB->addSuccessor(*I); + + // Insert and renumber MBBs. + MachineBasicBlock *Last = &MF->back(); + MF->insert(MF->end(), DispatchBB); + MF->insert(MF->end(), DispContBB); + MF->insert(MF->end(), TrapBB); + MF->RenumberBlocks(Last); + + // The instruction is gone now. + MI->eraseFromParent(); + return MBB; }