diff options
author | Bill Wendling <isanbard@gmail.com> | 2011-10-05 00:39:32 +0000 |
---|---|---|
committer | Bill Wendling <isanbard@gmail.com> | 2011-10-05 00:39:32 +0000 |
commit | bb73468e2bfb21160266691e9cdc4c4ea4256b22 (patch) | |
tree | cc684eaa5fe0e6aa35bdf21f86ab13d54f170289 | |
parent | 845d2c0c776abce551d16f7b1b7dc1f4d4df1a27 (diff) |
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
-rw-r--r-- | lib/Target/ARM/ARMISelLowering.cpp | 64 |
1 files changed, 50 insertions, 14 deletions
diff --git a/lib/Target/ARM/ARMISelLowering.cpp b/lib/Target/ARM/ARMISelLowering.cpp index e0c079afcd..c988c4aa0d 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<ARMFunctionInfo>(); 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<unsigned, SmallVector<MachineBasicBlock*, 2> > CallSiteNumToLPad; @@ -5617,10 +5613,8 @@ EmitSjLjDispatchBlock(MachineInstr *MI, MachineBasicBlock *MBB) const { for (unsigned I = 1; I <= MaxCSNum; ++I) { SmallVectorImpl<MachineBasicBlock*> &MBBList = CallSiteNumToLPad[I]; for (SmallVectorImpl<MachineBasicBlock*>::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<def> = t2LDRi12 <fi#0>, 4, pred:14, pred:%noreg; mem:Volatile LD4[%sunkaddr131] rGPR:%vreg11 + t2CMPri %vreg11, 6, pred:14, pred:%noreg, %CPSR<imp-def>; rGPR:%vreg11 + t2Bcc <BB#33>, pred:8, pred:%CPSR +*/ + +/* + %vreg11<def> = t2LDRi12 <fi#0>, 4, pred:14, pred:%noreg; mem:Volatile LD4[%sunkaddr131] rGPR:%vreg11 + %vreg12<def> = t2LEApcrelJT <jt#0>, 0, pred:14, pred:%noreg; rGPR:%vreg12 + %vreg13<def> = t2ADDrs %vreg12<kill>, %vreg11, 18, pred:14, pred:%noreg, opt:%noreg; GPRnopc:%vreg13 rGPR:%vreg12,%vreg11 + t2BR_JT %vreg13<kill>, %vreg11, <jt#0>, 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<MachineBasicBlock*>::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; } |