Generalize one of the SelectionDAG::ReplaceAllUsesWith overloads
authorDan Gohman <gohman@apple.com>
Wed, 15 Apr 2009 20:06:30 +0000 (20:06 +0000)
committerDan Gohman <gohman@apple.com>
Wed, 15 Apr 2009 20:06:30 +0000 (20:06 +0000)
to support replacing a node with another that has a superset of
the result types. Use this instead of calling
ReplaceAllUsesOfValueWith for each value.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@69209 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/CodeGen/DAGISelHeader.h
include/llvm/CodeGen/SelectionDAG.h
lib/CodeGen/SelectionDAG/LegalizeDAG.cpp
lib/CodeGen/SelectionDAG/SelectionDAG.cpp

index 6c040f47f60a4df60e806bd8472b7b14c8067359..b2acbc174559c7a4eca81fcf080ef11818988b9f 100644 (file)
@@ -80,15 +80,8 @@ void ReplaceUses(const SDValue *F, const SDValue *T,
 /// ReplaceUses - replace all uses of the old node F with the use
 /// of the new node T.
 void ReplaceUses(SDNode *F, SDNode *T) DISABLE_INLINE {
-  unsigned FNumVals = F->getNumValues();
-  unsigned TNumVals = T->getNumValues();
   ISelUpdater ISU(ISelPosition);
-  if (FNumVals != TNumVals) {
-    for (unsigned i = 0, e = std::min(FNumVals, TNumVals); i < e; ++i)
-     CurDAG->ReplaceAllUsesOfValueWith(SDValue(F, i), SDValue(T, i), &ISU);
-  } else {
-    CurDAG->ReplaceAllUsesWith(F, T, &ISU);
-  }
+  CurDAG->ReplaceAllUsesWith(F, T, &ISU);
 }
 
 /// SelectRoot - Top level entry to DAG instruction selector.
index 7be3cfc0032567d4e65da68d3527614cb20f263d..9ae92f388e17f24d82df8edde3f3ccf897c8a103 100644 (file)
@@ -693,7 +693,8 @@ public:
   /// ReplaceAllUsesWith - Modify anything using 'From' to use 'To' instead.
   /// This can cause recursive merging of nodes in the DAG.  Use the first
   /// version if 'From' is known to have a single result, use the second
-  /// if you have two nodes with identical results, use the third otherwise.
+  /// if you have two nodes with identical results (or if 'To' has a superset
+  /// of the results of 'From'), use the third otherwise.
   ///
   /// These methods all take an optional UpdateListener, which (if not null) is
   /// informed about nodes that are deleted and modified due to recursive
index 55a52b600a79ed07288eab321905f2cab468184c..5932aebf5cad58a5ddbd207e3eb95d59e080aa06 100644 (file)
@@ -4420,8 +4420,7 @@ SDValue SelectionDAGLegalize::LegalizeOp(SDValue Op) {
                            DAG.getVTList(&ValueVTs[0], 2),
                            &Ops[0], 2);
       SDNode *RNode = Result.getNode();
-      DAG.ReplaceAllUsesOfValueWith(SDValue(Node, 0), SDValue(RNode, 0));
-      DAG.ReplaceAllUsesOfValueWith(SDValue(Node, 1), SDValue(RNode, 1));
+      DAG.ReplaceAllUsesWith(Node, RNode);
       break;
     }
     }
@@ -4456,8 +4455,7 @@ SDValue SelectionDAGLegalize::LegalizeOp(SDValue Op) {
                            DAG.getVTList(&ValueVTs[0], 2),
                            &Ops[0], 2);
       SDNode *RNode = Result.getNode();
-      DAG.ReplaceAllUsesOfValueWith(SDValue(Node, 0), SDValue(RNode, 0));
-      DAG.ReplaceAllUsesOfValueWith(SDValue(Node, 1), SDValue(RNode, 1));
+      DAG.ReplaceAllUsesWith(Node, RNode);
       break;
     }
     }
index 022b961331a1451521ae1362b55fac56b4868f88..4b8591eb856f93b41188dd5ebc9337239d426db9 100644 (file)
@@ -4500,14 +4500,17 @@ void SelectionDAG::ReplaceAllUsesWith(SDValue FromN, SDValue To,
 /// ReplaceAllUsesWith - Modify anything using 'From' to use 'To' instead.
 /// This can cause recursive merging of nodes in the DAG.
 ///
-/// This version assumes From/To have matching types and numbers of result
-/// values.
+/// This version assumes that for each value of From, there is a
+/// corresponding value in To in the same position with the same type.
 ///
 void SelectionDAG::ReplaceAllUsesWith(SDNode *From, SDNode *To,
                                       DAGUpdateListener *UpdateListener) {
-  assert(From->getVTList().VTs == To->getVTList().VTs &&
-         From->getNumValues() == To->getNumValues() &&
-         "Cannot use this version of ReplaceAllUsesWith!");
+#ifndef NDEBUG
+  for (unsigned i = 0, e = From->getNumValues(); i != e; ++i)
+    assert((!From->hasAnyUseOfValue(i) ||
+            From->getValueType(i) == To->getValueType(i)) &&
+           "Cannot use this version of ReplaceAllUsesWith!");
+#endif
 
   // Handle the trivial case.
   if (From == To)