[llvm-commits] CVS: llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp

Evan Cheng evan.cheng at apple.com
Wed Jun 27 11:45:55 PDT 2007



Changes in directory llvm/lib/CodeGen/SelectionDAG:

SelectionDAGISel.cpp updated: 1.470 -> 1.471
---
Log message:

Partial fix for PR1502: http://llvm.org/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.

---
Diffs of the changes:  (+34 -11)

 SelectionDAGISel.cpp |   45 ++++++++++++++++++++++++++++++++++-----------
 1 files changed, 34 insertions(+), 11 deletions(-)


Index: llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp
diff -u llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp:1.470 llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp:1.471
--- llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp:1.470	Wed Jun 27 09:34:07 2007
+++ llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp	Wed Jun 27 13:45:32 2007
@@ -2402,6 +2402,25 @@
     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
 /// we want to emit this as a call to a named external function, return the name
 /// otherwise lower it and return null.
@@ -2511,12 +2530,9 @@
   }
     
   case Intrinsic::eh_exception: {
-    MachineModuleInfo *MMI = DAG.getMachineModuleInfo();
-    
-    if (ExceptionHandling && MMI) {
-      // Mark exception register as live in.
-      unsigned Reg = TLI.getExceptionAddressRegister();
-      if (Reg) CurMBB->addLiveIn(Reg);
+    if (ExceptionHandling) {
+      if (!CurMBB->isLandingPad() && TLI.getExceptionAddressRegister())
+          propagateEHRegister(CurMBB, TLI.getExceptionAddressRegister());
 
       // Insert the EXCEPTIONADDR instruction.
       SDVTList VTs = DAG.getVTList(TLI.getPointerTy(), MVT::Other);
@@ -2538,14 +2554,13 @@
     if (ExceptionHandling && MMI) {
       if (CurMBB->isLandingPad())
         addCatchInfo(I, MMI, CurMBB);
+      else {
 #ifndef NDEBUG
-      else
         FuncInfo.CatchInfoLost.insert(&I);
 #endif
-
-      // Mark exception selector register as live in.
-      unsigned Reg = TLI.getExceptionSelectorRegister();
-      if (Reg) CurMBB->addLiveIn(Reg);
+        if (TLI.getExceptionSelectorRegister())
+          propagateEHRegister(CurMBB, TLI.getExceptionSelectorRegister());
+      }
 
       // Insert the EHSELECTION instruction.
       SDVTList VTs = DAG.getVTList(TLI.getPointerTy(), MVT::Other);
@@ -4482,6 +4497,14 @@
     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) 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
     // 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






More information about the llvm-commits mailing list