[llvm-commits] [llvm] r52067 - /llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp

Owen Anderson resistor at mac.com
Fri Jun 6 17:00:23 PDT 2008


Author: resistor
Date: Fri Jun  6 19:00:23 2008
New Revision: 52067

URL: http://llvm.org/viewvc/llvm-project?rev=52067&view=rev
Log:
Connect successors before creating the DAG node for the branch.  This has
no visible functionality change, but enables a future patch where node creation
will update the CFG if it decides to create an unconditional rather than a conditional branch.

Modified:
    llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp

Modified: llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp?rev=52067&r1=52066&r2=52067&view=diff

==============================================================================
--- llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp (original)
+++ llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp Fri Jun  6 19:00:23 2008
@@ -1381,13 +1381,13 @@
     NextBlock = BBI;
 
   if (I.isUnconditional()) {
+    // Update machine-CFG edges.
+    CurMBB->addSuccessor(Succ0MBB);
+    
     // If this is not a fall-through branch, emit the branch.
     if (Succ0MBB != NextBlock)
       DAG.setRoot(DAG.getNode(ISD::BR, MVT::Other, getControlRoot(),
                               DAG.getBasicBlock(Succ0MBB)));
-
-    // Update machine-CFG edges.
-    CurMBB->addSuccessor(Succ0MBB);
     return;
   }
 
@@ -1484,9 +1484,12 @@
       Cond = DAG.getSetCC(MVT::i1, SUB,
                           DAG.getConstant(High-Low, VT), ISD::SETULE);
     }
-    
   }
   
+  // Update successor info
+  CurMBB->addSuccessor(CB.TrueBB);
+  CurMBB->addSuccessor(CB.FalseBB);
+  
   // Set NextBlock to be the MBB immediately after the current one, if any.
   // This is used to avoid emitting unnecessary branches to the next block.
   MachineBasicBlock *NextBlock = 0;
@@ -1508,9 +1511,6 @@
   else
     DAG.setRoot(DAG.getNode(ISD::BR, MVT::Other, BrCond, 
                             DAG.getBasicBlock(CB.FalseBB)));
-  // Update successor info
-  CurMBB->addSuccessor(CB.TrueBB);
-  CurMBB->addSuccessor(CB.FalseBB);
 }
 
 /// visitJumpTable - Emit JumpTable node in the current MBB
@@ -1606,9 +1606,6 @@
   SDOperand CopyTo = DAG.getCopyToReg(getControlRoot(), SwitchReg, SwitchVal);
   B.Reg = SwitchReg;
 
-  SDOperand BrRange = DAG.getNode(ISD::BRCOND, MVT::Other, CopyTo, RangeCmp,
-                                  DAG.getBasicBlock(B.Default));
-
   // Set NextBlock to be the MBB immediately after the current one, if any.
   // This is used to avoid emitting unnecessary branches to the next block.
   MachineBasicBlock *NextBlock = 0;
@@ -1617,15 +1614,19 @@
     NextBlock = BBI;
 
   MachineBasicBlock* MBB = B.Cases[0].ThisBB;
+
+  CurMBB->addSuccessor(B.Default);
+  CurMBB->addSuccessor(MBB);
+
+  SDOperand BrRange = DAG.getNode(ISD::BRCOND, MVT::Other, CopyTo, RangeCmp,
+                                  DAG.getBasicBlock(B.Default));
+  
   if (MBB == NextBlock)
     DAG.setRoot(BrRange);
   else
     DAG.setRoot(DAG.getNode(ISD::BR, MVT::Other, CopyTo,
                             DAG.getBasicBlock(MBB)));
 
-  CurMBB->addSuccessor(B.Default);
-  CurMBB->addSuccessor(MBB);
-
   return;
 }
 
@@ -1643,6 +1644,10 @@
   SDOperand AndCmp = DAG.getSetCC(TLI.getSetCCResultType(AndOp), AndOp,
                                   DAG.getConstant(0, TLI.getPointerTy()),
                                   ISD::SETNE);
+
+  CurMBB->addSuccessor(B.TargetBB);
+  CurMBB->addSuccessor(NextMBB);
+  
   SDOperand BrAnd = DAG.getNode(ISD::BRCOND, MVT::Other, getControlRoot(),
                                 AndCmp, DAG.getBasicBlock(B.TargetBB));
 
@@ -1659,9 +1664,6 @@
     DAG.setRoot(DAG.getNode(ISD::BR, MVT::Other, BrAnd,
                             DAG.getBasicBlock(NextMBB)));
 
-  CurMBB->addSuccessor(B.TargetBB);
-  CurMBB->addSuccessor(NextMBB);
-
   return;
 }
 
@@ -1683,13 +1685,13 @@
       CopyValueToVirtualRegister(&I, VMI->second);
   }
 
-  // Drop into normal successor.
-  DAG.setRoot(DAG.getNode(ISD::BR, MVT::Other, getControlRoot(),
-                          DAG.getBasicBlock(Return)));
-
   // Update successor info
   CurMBB->addSuccessor(Return);
   CurMBB->addSuccessor(LandingPad);
+
+  // Drop into normal successor.
+  DAG.setRoot(DAG.getNode(ISD::BR, MVT::Other, getControlRoot(),
+                          DAG.getBasicBlock(Return)));
 }
 
 void SelectionDAGLowering::visitUnwind(UnwindInst &I) {
@@ -2178,11 +2180,11 @@
     // Update machine-CFG edges.
 
     // If this is not a fall-through branch, emit the branch.
+    CurMBB->addSuccessor(Default);
     if (Default != NextBlock)
       DAG.setRoot(DAG.getNode(ISD::BR, MVT::Other, getControlRoot(),
                               DAG.getBasicBlock(Default)));
-
-    CurMBB->addSuccessor(Default);
+    
     return;
   }
   





More information about the llvm-commits mailing list