From d429bcd4ac734540ebbc15a0ee37d154ae1daf73 Mon Sep 17 00:00:00 2001
From: Chris Lattner <sabre@nondot.org>
Date: Sun, 4 Feb 2007 02:49:29 +0000
Subject: [PATCH] move MorphNode to out of line and merge setNodeOperands into
 it.  There is no behavior or performance change here.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@33869 91177308-0d34-0410-b5e6-96231b3b80d8
---
 include/llvm/CodeGen/SelectionDAGNodes.h  | 33 +++-------------
 lib/CodeGen/SelectionDAG/SelectionDAG.cpp | 47 ++++++++++++++++-------
 2 files changed, 38 insertions(+), 42 deletions(-)

diff --git a/include/llvm/CodeGen/SelectionDAGNodes.h b/include/llvm/CodeGen/SelectionDAGNodes.h
index 5e4be98e809..7fe97be8068 100644
--- a/include/llvm/CodeGen/SelectionDAGNodes.h
+++ b/include/llvm/CodeGen/SelectionDAGNodes.h
@@ -967,22 +967,11 @@ protected:
     Prev = 0; Next = 0;
   }
 
-  /// MorphNodeTo - This clears the return value and operands list, and sets the
-  /// opcode of the node to the specified value.  This should only be used by
-  /// the SelectionDAG class.
-  void MorphNodeTo(unsigned Opc, SDVTList L) {
-    NodeType = Opc;
-    ValueList = L.VTs;
-    NumValues = L.NumVTs;
-    
-    // Clear the operands list, updating used nodes to remove this from their
-    // use list.
-    for (op_iterator I = op_begin(), E = op_end(); I != E; ++I)
-      I->Val->removeUser(this);
-    delete [] OperandList;
-    OperandList = 0;
-    NumOperands = 0;
-  }
+  /// MorphNodeTo - This frees the operands of the current node, resets the
+  /// opcode, types, and operands to the specified value.  This should only be
+  /// used by the SelectionDAG class.
+  void MorphNodeTo(unsigned Opc, SDVTList L,
+                   const SDOperand *Ops, unsigned NumOps);
   
   void setValueTypes(SDVTList L) {
     assert(NumValues == 0 && "Should not have values yet!");
@@ -990,18 +979,6 @@ protected:
     NumValues = L.NumVTs;
   }
   
-  void setOperands(const SDOperand *Ops, unsigned NumOps) {
-    assert(NumOperands == 0 && "Should not have operands yet!");
-    NumOperands = NumOps;
-    OperandList = new SDOperand[NumOperands];
-
-    for (unsigned i = 0, e = NumOps; i != e; ++i) {
-      OperandList[i] = Ops[i];
-      SDNode *N = OperandList[i].Val;
-      N->Uses.push_back(this);
-    }
-  }
-
   void addUser(SDNode *User) {
     Uses.push_back(User);
   }
diff --git a/lib/CodeGen/SelectionDAG/SelectionDAG.cpp b/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
index f790e6320c6..49394369b7f 100644
--- a/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
+++ b/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
@@ -2064,7 +2064,32 @@ UpdateNodeOperands(SDOperand InN, SDOperand *Ops, unsigned NumOps) {
 }
 
 
+/// MorphNodeTo - This frees the operands of the current node, resets the
+/// opcode, types, and operands to the specified value.  This should only be
+/// used by the SelectionDAG class.
+void SDNode::MorphNodeTo(unsigned Opc, SDVTList L,
+                         const SDOperand *Ops, unsigned NumOps) {
+  NodeType = Opc;
+  ValueList = L.VTs;
+  NumValues = L.NumVTs;
+  
+  // Clear the operands list, updating used nodes to remove this from their
+  // use list.
+  for (op_iterator I = op_begin(), E = op_end(); I != E; ++I)
+    I->Val->removeUser(this);
+  delete [] OperandList;
 
+  
+  // Assign the new operands.
+  NumOperands = NumOps;
+  OperandList = NumOperands ? new SDOperand[NumOperands] : 0;
+  
+  for (unsigned i = 0, e = NumOps; i != e; ++i) {
+    OperandList[i] = Ops[i];
+    SDNode *N = OperandList[i].Val;
+    N->Uses.push_back(this);
+  }
+}
 
 /// SelectNodeTo - These are used for target selectors to *mutate* the
 /// specified node to have the specified return type, Target opcode, and
@@ -2085,7 +2110,7 @@ SDNode *SelectionDAG::SelectNodeTo(SDNode *N, unsigned TargetOpc,
    
   RemoveNodeFromCSEMaps(N);
   
-  N->MorphNodeTo(ISD::BUILTIN_OP_END+TargetOpc, VTs);
+  N->MorphNodeTo(ISD::BUILTIN_OP_END+TargetOpc, VTs, 0, 0);
 
   CSEMap.InsertNode(N, IP);
   return N;
@@ -2104,8 +2129,7 @@ SDNode *SelectionDAG::SelectNodeTo(SDNode *N, unsigned TargetOpc,
   RemoveNodeFromCSEMaps(N);
   SDOperand OperandList[] = { Op1 };
   
-  N->MorphNodeTo(ISD::BUILTIN_OP_END+TargetOpc, VTs);
-  N->setOperands(OperandList, 1);
+  N->MorphNodeTo(ISD::BUILTIN_OP_END+TargetOpc, VTs, OperandList, 1);
   CSEMap.InsertNode(N, IP);
   return N;
 }
@@ -2125,8 +2149,7 @@ SDNode *SelectionDAG::SelectNodeTo(SDNode *N, unsigned TargetOpc,
   
   SDOperand OperandList[] = { Op1, Op2 };
 
-  N->MorphNodeTo(ISD::BUILTIN_OP_END+TargetOpc, VTs);
-  N->setOperands(OperandList, 2);
+  N->MorphNodeTo(ISD::BUILTIN_OP_END+TargetOpc, VTs, OperandList, 2);
   
   CSEMap.InsertNode(N, IP);   // Memoize the new node.
   return N;
@@ -2146,8 +2169,7 @@ SDNode *SelectionDAG::SelectNodeTo(SDNode *N, unsigned TargetOpc,
   RemoveNodeFromCSEMaps(N);
   
   SDOperand OperandList[] = { Op1, Op2, Op3 };
-  N->MorphNodeTo(ISD::BUILTIN_OP_END+TargetOpc, VTs);
-  N->setOperands(OperandList, 3);
+  N->MorphNodeTo(ISD::BUILTIN_OP_END+TargetOpc, VTs, OperandList, 3);
 
   CSEMap.InsertNode(N, IP);   // Memoize the new node.
   return N;
@@ -2165,8 +2187,7 @@ SDNode *SelectionDAG::SelectNodeTo(SDNode *N, unsigned TargetOpc,
     return ON;
                                        
   RemoveNodeFromCSEMaps(N);
-  N->MorphNodeTo(ISD::BUILTIN_OP_END+TargetOpc, VTs);
-  N->setOperands(Ops, NumOps);
+  N->MorphNodeTo(ISD::BUILTIN_OP_END+TargetOpc, VTs, Ops, NumOps);
   
   CSEMap.InsertNode(N, IP);   // Memoize the new node.
   return N;
@@ -2185,8 +2206,7 @@ SDNode *SelectionDAG::SelectNodeTo(SDNode *N, unsigned TargetOpc,
   RemoveNodeFromCSEMaps(N);
 
   SDOperand OperandList[] = { Op1, Op2 };
-  N->MorphNodeTo(ISD::BUILTIN_OP_END+TargetOpc, VTs);
-  N->setOperands(OperandList, 2);
+  N->MorphNodeTo(ISD::BUILTIN_OP_END+TargetOpc, VTs, OperandList, 2);
   
   CSEMap.InsertNode(N, IP);   // Memoize the new node.
   return N;
@@ -2207,8 +2227,7 @@ SDNode *SelectionDAG::SelectNodeTo(SDNode *N, unsigned TargetOpc,
   RemoveNodeFromCSEMaps(N);
 
   SDOperand OperandList[] = { Op1, Op2, Op3 };
-  N->MorphNodeTo(ISD::BUILTIN_OP_END+TargetOpc, VTs);
-  N->setOperands(OperandList, 3);
+  N->MorphNodeTo(ISD::BUILTIN_OP_END+TargetOpc, VTs, OperandList, 3);
   
   CSEMap.InsertNode(N, IP);   // Memoize the new node.
   return N;
@@ -2542,7 +2561,7 @@ void StoreSDNode::ANCHOR() {}
 
 HandleSDNode::~HandleSDNode() {
   SDVTList VTs = { 0, 0 };
-  MorphNodeTo(ISD::HANDLENODE, VTs);  // Drops operand uses.
+  MorphNodeTo(ISD::HANDLENODE, VTs, 0, 0);  // Drops operand uses.
 }