aboutsummaryrefslogtreecommitdiff
path: root/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp
diff options
context:
space:
mode:
authorDuncan Sands <baldrick@free.fr>2007-06-06 10:05:18 +0000
committerDuncan Sands <baldrick@free.fr>2007-06-06 10:05:18 +0000
commit9fac0b5ff24e733072bdde68c7f34590c1892922 (patch)
tree3eb1cce42712022d7ae50c3b04c06f28e9c974a5 /lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp
parent0bad514df1bd40b567c18714101c65408c5c1748 (diff)
Additional fix for PR1422: make sure the landing pad label is placed in the
correct machine basic block - do not rely on the eh.exception intrinsic being in the landing pad: the loop optimizers can move it out. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@37463 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp')
-rw-r--r--lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp41
1 files changed, 26 insertions, 15 deletions
diff --git a/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp b/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp
index 6b6834bffc..ac89b179e1 100644
--- a/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp
+++ b/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp
@@ -1337,12 +1337,10 @@ void SelectionDAGLowering::visitInvoke(InvokeInst &I) {
void SelectionDAGLowering::visitInvoke(InvokeInst &I, bool AsTerminator) {
// Retrieve successors.
MachineBasicBlock *Return = FuncInfo.MBBMap[I.getSuccessor(0)];
- MachineBasicBlock *LandingPad = FuncInfo.MBBMap[I.getSuccessor(1)];
-
+
if (!AsTerminator) {
- // Mark landing pad so that it doesn't get deleted in branch folding.
- LandingPad->setIsLandingPad();
-
+ MachineBasicBlock *LandingPad = FuncInfo.MBBMap[I.getSuccessor(1)];
+
LowerCallTo(I, I.getCalledValue()->getType(),
I.getCallingConv(),
false,
@@ -2577,16 +2575,10 @@ SelectionDAGLowering::visitIntrinsicCall(CallInst &I, unsigned Intrinsic) {
MachineModuleInfo *MMI = DAG.getMachineModuleInfo();
if (MMI) {
- // Add a label to mark the beginning of the landing pad. Deletion of the
- // landing pad can thus be detected via the MachineModuleInfo.
- unsigned LabelID = MMI->addLandingPad(CurMBB);
- DAG.setRoot(DAG.getNode(ISD::LABEL, MVT::Other, DAG.getEntryNode(),
- DAG.getConstant(LabelID, MVT::i32)));
-
// Mark exception register as live in.
unsigned Reg = TLI.getExceptionAddressRegister();
if (Reg) CurMBB->addLiveIn(Reg);
-
+
// Insert the EXCEPTIONADDR instruction.
SDVTList VTs = DAG.getVTList(TLI.getPointerTy(), MVT::Other);
SDOperand Ops[1];
@@ -2626,7 +2618,7 @@ SelectionDAGLowering::visitIntrinsicCall(CallInst &I, unsigned Intrinsic) {
MMI->addFilterTypeInfo(CurMBB, TyInfo);
else
MMI->addCatchTypeInfo(CurMBB, TyInfo);
-
+
// Mark exception selector register as live in.
unsigned Reg = TLI.getExceptionSelectorRegister();
if (Reg) CurMBB->addLiveIn(Reg);
@@ -2788,7 +2780,7 @@ void SelectionDAGLowering::LowerCallTo(Instruction &I,
Args.push_back(Entry);
}
- if (ExceptionHandling) {
+ if (ExceptionHandling && MMI) {
// Insert a label before the invoke call to mark the try range. This can be
// used to detect deletion of the invoke via the MachineModuleInfo.
BeginLabel = MMI->NextLabelID();
@@ -2805,7 +2797,7 @@ void SelectionDAGLowering::LowerCallTo(Instruction &I,
setValue(&I, Result.first);
DAG.setRoot(Result.second);
- if (ExceptionHandling) {
+ if (ExceptionHandling && MMI) {
// Insert a label at the end of the invoke call to mark the try range. This
// can be used to detect deletion of the invoke via the MachineModuleInfo.
EndLabel = MMI->NextLabelID();
@@ -4387,6 +4379,13 @@ bool SelectionDAGISel::runOnFunction(Function &Fn) {
FunctionLoweringInfo FuncInfo(TLI, Fn, MF);
for (Function::iterator I = Fn.begin(), E = Fn.end(); I != E; ++I)
+ if (InvokeInst *Invoke = dyn_cast<InvokeInst>(I->getTerminator())) {
+ // Mark landing pad.
+ MachineBasicBlock *LandingPad = FuncInfo.MBBMap[Invoke->getSuccessor(1)];
+ LandingPad->setIsLandingPad();
+ }
+
+ for (Function::iterator I = Fn.begin(), E = Fn.end(); I != E; ++I)
SelectBasicBlock(I, MF, FuncInfo);
// Add function live-ins to entry block live-in set.
@@ -4523,6 +4522,18 @@ void SelectionDAGISel::BuildSelectionDAG(SelectionDAG &DAG, BasicBlock *LLVMBB,
BB = FuncInfo.MBBMap[LLVMBB];
SDL.setCurrentBasicBlock(BB);
+ if (ExceptionHandling && BB->isLandingPad()) {
+ MachineModuleInfo *MMI = DAG.getMachineModuleInfo();
+
+ if (MMI) {
+ // Add a label to mark the beginning of the landing pad. Deletion of the
+ // landing pad can thus be detected via the MachineModuleInfo.
+ unsigned LabelID = MMI->addLandingPad(BB);
+ DAG.setRoot(DAG.getNode(ISD::LABEL, MVT::Other, DAG.getEntryNode(),
+ DAG.getConstant(LabelID, MVT::i32)));
+ }
+ }
+
// Lower all of the non-terminator instructions.
for (BasicBlock::iterator I = LLVMBB->begin(), E = --LLVMBB->end();
I != E; ++I)