Provide two overloads of AnalyzeNewNode.

The first can update the SDNode in an SDValue
while the second is called with SDNode* and
returns a possibly updated SDNode*.

This patch has no intended functional impact,
but helps eliminating ugly temporary SDValues.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@55608 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/CodeGen/SelectionDAG/LegalizeTypes.cpp b/lib/CodeGen/SelectionDAG/LegalizeTypes.cpp
index d913ce6..640392f 100644
--- a/lib/CodeGen/SelectionDAG/LegalizeTypes.cpp
+++ b/lib/CodeGen/SelectionDAG/LegalizeTypes.cpp
@@ -221,11 +221,11 @@
 /// AnalyzeNewNode - The specified node is the root of a subtree of potentially
 /// new nodes.  Correct any processed operands (this may change the node) and
 /// calculate the NodeId.
-void DAGTypeLegalizer::AnalyzeNewNode(SDValue &Val) {
-  SDNode * const N(Val.getNode());
+/// Returns the potentially changed node.
+SDNode *DAGTypeLegalizer::AnalyzeNewNode(SDNode *N) {
   // If this was an existing node that is already done, we're done.
   if (N->getNodeId() != NewNode)
-    return;
+    return N;
 
   // Remove any stale map entries.
   ExpungeNode(N);
@@ -268,16 +268,26 @@
 
   // Some operands changed - update the node.
   if (!NewOps.empty())
-    Val.setNode(DAG.UpdateNodeOperands(SDValue(N, 0),
-				       &NewOps[0],
-				       NewOps.size()).getNode());
+    N = DAG.UpdateNodeOperands(SDValue(N, 0),
+                               &NewOps[0],
+                               NewOps.size()).getNode();
 
-  SDNode * const Nu(Val.getNode());
-  Nu->setNodeId(Nu->getNumOperands()-NumProcessed);
-  if (Nu->getNodeId() == ReadyToProcess)
-    Worklist.push_back(Nu);
+  N->setNodeId(N->getNumOperands()-NumProcessed);
+  if (N->getNodeId() == ReadyToProcess)
+    Worklist.push_back(N);
+  return N;
 }
 
+/// AnalyzeNewNode - call AnalyzeNewNode(SDNode *N)
+/// and update the node in SDValue if necessary.
+void DAGTypeLegalizer::AnalyzeNewNode(SDValue &Val) {
+  SDNode *N(Val.getNode());
+  SDNode *M(AnalyzeNewNode(N));
+  if (N != M)
+    Val.setNode(M);
+}
+
+
 namespace {
   /// NodeUpdateListener - This class is a DAGUpdateListener that listens for
   /// updates to nodes and recomputes their ready state.
@@ -338,9 +348,7 @@
   // If expansion produced new nodes, make sure they are properly marked.
   ExpungeNode(From);
 
-  SDValue ToNode(To, 0);
-  AnalyzeNewNode(ToNode); // Expunges To.
-  To = ToNode.getNode();
+  To = AnalyzeNewNode(To); // Expunges To.
 
   assert(From->getNumValues() == To->getNumValues() &&
          "Node results don't match");
diff --git a/lib/CodeGen/SelectionDAG/LegalizeTypes.h b/lib/CodeGen/SelectionDAG/LegalizeTypes.h
index 5780021..ae57409 100644
--- a/lib/CodeGen/SelectionDAG/LegalizeTypes.h
+++ b/lib/CodeGen/SelectionDAG/LegalizeTypes.h
@@ -157,9 +157,7 @@
   /// for the specified node, adding it to the worklist if ready.
   SDNode *ReanalyzeNode(SDNode *N) {
     N->setNodeId(NewNode);
-    SDValue V(N, 0);
-    AnalyzeNewNode(V); // FIXME: ignore the change?
-    return V.getNode();
+    return AnalyzeNewNode(N);
   }
 
   void NoteDeletion(SDNode *Old, SDNode *New) {
@@ -171,6 +169,7 @@
 
 private:
   void AnalyzeNewNode(SDValue &Val);
+  SDNode *AnalyzeNewNode(SDNode *N);
 
   void ReplaceValueWith(SDValue From, SDValue To);
   void ReplaceNodeWith(SDNode *From, SDNode *To);