Partial fix for PR1502: If a EH register is needed in a successor of landing pad, add it as livein to all the blocks in the paths between the landing pad and the specified block.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@37763 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Evan Cheng 2007-06-27 18:45:32 +00:00
parent 68cb52e468
commit e47c333a12

View File

@ -2402,6 +2402,25 @@ static void addCatchInfo(CallInst &I, MachineModuleInfo *MMI,
MMI->addCatchTypeInfo(MBB, TyInfo); MMI->addCatchTypeInfo(MBB, TyInfo);
} }
/// propagateEHRegister - The specified EH register is required in a successor
/// of the EH landing pad. Propagate it (by adding it to livein) to all the
/// blocks in the paths between the landing pad and the specified block.
static void propagateEHRegister(MachineBasicBlock *MBB, unsigned EHReg,
SmallPtrSet<MachineBasicBlock*, 8> Visited) {
if (MBB->isLandingPad() || !Visited.insert(MBB))
return;
MBB->addLiveIn(EHReg);
for (MachineBasicBlock::pred_iterator PI = MBB->pred_begin(),
E = MBB->pred_end(); PI != E; ++PI)
propagateEHRegister(*PI, EHReg, Visited);
}
static void propagateEHRegister(MachineBasicBlock *MBB, unsigned EHReg) {
SmallPtrSet<MachineBasicBlock*, 8> Visited;
propagateEHRegister(MBB, EHReg, Visited);
}
/// visitIntrinsicCall - Lower the call to the specified intrinsic function. If /// visitIntrinsicCall - Lower the call to the specified intrinsic function. If
/// we want to emit this as a call to a named external function, return the name /// we want to emit this as a call to a named external function, return the name
/// otherwise lower it and return null. /// otherwise lower it and return null.
@ -2511,12 +2530,9 @@ SelectionDAGLowering::visitIntrinsicCall(CallInst &I, unsigned Intrinsic) {
} }
case Intrinsic::eh_exception: { case Intrinsic::eh_exception: {
MachineModuleInfo *MMI = DAG.getMachineModuleInfo(); if (ExceptionHandling) {
if (!CurMBB->isLandingPad() && TLI.getExceptionAddressRegister())
if (ExceptionHandling && MMI) { propagateEHRegister(CurMBB, TLI.getExceptionAddressRegister());
// Mark exception register as live in.
unsigned Reg = TLI.getExceptionAddressRegister();
if (Reg) CurMBB->addLiveIn(Reg);
// Insert the EXCEPTIONADDR instruction. // Insert the EXCEPTIONADDR instruction.
SDVTList VTs = DAG.getVTList(TLI.getPointerTy(), MVT::Other); SDVTList VTs = DAG.getVTList(TLI.getPointerTy(), MVT::Other);
@ -2538,14 +2554,13 @@ SelectionDAGLowering::visitIntrinsicCall(CallInst &I, unsigned Intrinsic) {
if (ExceptionHandling && MMI) { if (ExceptionHandling && MMI) {
if (CurMBB->isLandingPad()) if (CurMBB->isLandingPad())
addCatchInfo(I, MMI, CurMBB); addCatchInfo(I, MMI, CurMBB);
else {
#ifndef NDEBUG #ifndef NDEBUG
else
FuncInfo.CatchInfoLost.insert(&I); FuncInfo.CatchInfoLost.insert(&I);
#endif #endif
if (TLI.getExceptionSelectorRegister())
// Mark exception selector register as live in. propagateEHRegister(CurMBB, TLI.getExceptionSelectorRegister());
unsigned Reg = TLI.getExceptionSelectorRegister(); }
if (Reg) CurMBB->addLiveIn(Reg);
// Insert the EHSELECTION instruction. // Insert the EHSELECTION instruction.
SDVTList VTs = DAG.getVTList(TLI.getPointerTy(), MVT::Other); SDVTList VTs = DAG.getVTList(TLI.getPointerTy(), MVT::Other);
@ -4482,6 +4497,14 @@ void SelectionDAGISel::BuildSelectionDAG(SelectionDAG &DAG, BasicBlock *LLVMBB,
DAG.setRoot(DAG.getNode(ISD::LABEL, MVT::Other, DAG.getEntryNode(), DAG.setRoot(DAG.getNode(ISD::LABEL, MVT::Other, DAG.getEntryNode(),
DAG.getConstant(LabelID, MVT::i32))); DAG.getConstant(LabelID, MVT::i32)));
// Mark exception register as live in.
unsigned Reg = TLI.getExceptionAddressRegister();
if (Reg) BB->addLiveIn(Reg);
// Mark exception selector register as live in.
Reg = TLI.getExceptionSelectorRegister();
if (Reg) BB->addLiveIn(Reg);
// FIXME: Hack around an exception handling flaw (PR1508): the personality // FIXME: Hack around an exception handling flaw (PR1508): the personality
// function and list of typeids logically belong to the invoke (or, if you // function and list of typeids logically belong to the invoke (or, if you
// like, the basic block containing the invoke), and need to be associated // like, the basic block containing the invoke), and need to be associated