Delete unnecessary elses.
[oota-llvm.git] / include / llvm / CodeGen / DAGISelHeader.h
index 783c567a527bd8cb218947957108002aede2e8e9..6c040f47f60a4df60e806bd8472b7b14c8067359 100644 (file)
@@ -31,9 +31,9 @@ SelectionDAG::allnodes_iterator ISelPosition;
 static bool IsChainCompatible(SDNode *Chain, SDNode *Op) {
   if (Chain->getOpcode() == ISD::EntryToken)
     return true;
-  else if (Chain->getOpcode() == ISD::TokenFactor)
+  if (Chain->getOpcode() == ISD::TokenFactor)
     return false;
-  else if (Chain->getNumOperands() > 0) {
+  if (Chain->getNumOperands() > 0) {
     SDValue C0 = Chain->getOperand(0);
     if (C0.getValueType() == MVT::Other)
       return C0.getNode() != Op && IsChainCompatible(C0.getNode(), Op);
@@ -45,12 +45,14 @@ static bool IsChainCompatible(SDNode *Chain, SDNode *Op) {
 /// instruciton selection graph.
 class VISIBILITY_HIDDEN ISelUpdater : public SelectionDAG::DAGUpdateListener {
   SelectionDAG::allnodes_iterator &ISelPosition;
-  bool HadDelete; // Indicate if any deletions were done.
 public:
   explicit ISelUpdater(SelectionDAG::allnodes_iterator &isp)
     : ISelPosition(isp) {}
   
-  /// NodeDeleted - remove node from the selection queue.
+  /// NodeDeleted - Handle nodes deleted from the graph. If the
+  /// node being deleted is the current ISelPosition node, update
+  /// ISelPosition.
+  ///
   virtual void NodeDeleted(SDNode *N, SDNode *E) {
     if (ISelPosition == SelectionDAG::allnodes_iterator(N))
       ++ISelPosition;
@@ -100,10 +102,17 @@ void SelectRoot(SelectionDAG &DAG) {
   HandleSDNode Dummy(CurDAG->getRoot());
   ISelPosition = next(SelectionDAG::allnodes_iterator(CurDAG->getRoot().getNode()));
 
-  // Select pending nodes from the instruction selection queue
-  // until no more nodes are left for selection.
+  // The AllNodes list is now topological-sorted. Visit the
+  // nodes by starting at the end of the list (the root of the
+  // graph) and preceding back toward the beginning (the entry
+  // node).
   while (ISelPosition != CurDAG->allnodes_begin()) {
     SDNode *Node = --ISelPosition;
+    // Skip dead nodes. DAGCombiner is expected to eliminate all dead nodes,
+    // but there are currently some corner cases that it misses. Also, this
+    // makes it theoretically possible to disable the DAGCombiner.
+    if (Node->use_empty())
+      continue;
 #if 0
     DAG.setSubgraphColor(Node, "red");
 #endif