Provide two overloads of AnalyzeNewNode.
authorGabor Greif <ggreif@gmail.com>
Mon, 1 Sep 2008 15:10:19 +0000 (15:10 +0000)
committerGabor Greif <ggreif@gmail.com>
Mon, 1 Sep 2008 15:10:19 +0000 (15:10 +0000)
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

lib/CodeGen/SelectionDAG/LegalizeTypes.cpp
lib/CodeGen/SelectionDAG/LegalizeTypes.h

index d913ce611cedcdec5fc8924d5fb734a1f1150e0f..640392f26cf14be513c475cf21b8f0a01b980d3b 100644 (file)
@@ -221,11 +221,11 @@ NodeDone:
 /// 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 @@ void DAGTypeLegalizer::AnalyzeNewNode(SDValue &Val) {
 
   // Some operands changed - update the node.
   if (!NewOps.empty())
-    Val.setNode(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 = DAG.UpdateNodeOperands(SDValue(N, 0),
+                               &NewOps[0],
+                               NewOps.size()).getNode();
+
+  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 @@ void DAGTypeLegalizer::ReplaceNodeWith(SDNode *From, SDNode *To) {
   // 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");
index 5780021f90a94921b1c8a3eecde87e2b8b58e4b2..ae57409d8fc8b34e14954f716144f7c8743eca96 100644 (file)
@@ -157,9 +157,7 @@ public:
   /// 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 @@ public:
 
 private:
   void AnalyzeNewNode(SDValue &Val);
+  SDNode *AnalyzeNewNode(SDNode *N);
 
   void ReplaceValueWith(SDValue From, SDValue To);
   void ReplaceNodeWith(SDNode *From, SDNode *To);