[llvm-commits] [llvm] r53377 - in /llvm/trunk: include/llvm/CodeGen/SelectionDAGNodes.h lib/CodeGen/SelectionDAG/SelectionDAG.cpp

Dan Gohman gohman at apple.com
Wed Jul 9 16:03:14 PDT 2008


Author: djg
Date: Wed Jul  9 18:03:14 2008
New Revision: 53377

URL: http://llvm.org/viewvc/llvm-project?rev=53377&view=rev
Log:
Simplify hasNUsesOfValue and hasAnyUsesOfValue even more. This
makes their special-case checks of use_size() less beneficial,
so remove them. This eliminates all but one use of use_size(),
which is in AssignTopologicalOrder, which uses it only once for
each node, and so can reasonably afford to recompute it, as
this allows the UsesSize field of SDNode to be removed
altogether.

Modified:
    llvm/trunk/include/llvm/CodeGen/SelectionDAGNodes.h
    llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAG.cpp

Modified: llvm/trunk/include/llvm/CodeGen/SelectionDAGNodes.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CodeGen/SelectionDAGNodes.h?rev=53377&r1=53376&r2=53377&view=diff

==============================================================================
--- llvm/trunk/include/llvm/CodeGen/SelectionDAGNodes.h (original)
+++ llvm/trunk/include/llvm/CodeGen/SelectionDAGNodes.h Wed Jul  9 18:03:14 2008
@@ -1048,9 +1048,6 @@
   /// NumOperands/NumValues - The number of entries in the Operand/Value list.
   unsigned short NumOperands, NumValues;
   
-  /// UsesSize - The size of the uses list.
-  unsigned UsesSize;
-
   /// Uses - List of uses for this SDNode.
   SDUse *Uses;
 
@@ -1075,9 +1072,11 @@
     return NodeType - ISD::BUILTIN_OP_END;
   }
 
-  size_t use_size() const { return UsesSize; }
+  size_t use_size() const { return std::distance(use_begin(), use_end()); }
   bool use_empty() const { return Uses == NULL; }
-  bool hasOneUse() const { return use_size() == 1; }
+  bool hasOneUse() const {
+    return !use_empty() && next(use_begin()) == use_end();
+  }
 
   /// getNodeId - Return the unique node id.
   ///
@@ -1249,7 +1248,7 @@
   }
 
   SDNode(unsigned Opc, SDVTList VTs, const SDOperand *Ops, unsigned NumOps)
-    : NodeType(Opc), NodeId(-1), UsesSize(0), Uses(NULL) {
+    : NodeType(Opc), NodeId(-1), Uses(NULL) {
     OperandsNeedDelete = true;
     NumOperands = NumOps;
     OperandList = NumOps ? new SDUse[NumOperands] : 0;
@@ -1258,7 +1257,6 @@
       OperandList[i] = Ops[i];
       OperandList[i].setUser(this);
       Ops[i].Val->addUse(OperandList[i]);
-      ++Ops[i].Val->UsesSize;
     }
     
     ValueList = VTs.VTs;
@@ -1266,7 +1264,7 @@
   }
 
   SDNode(unsigned Opc, SDVTList VTs, const SDUse *Ops, unsigned NumOps)
-    : NodeType(Opc), NodeId(-1), UsesSize(0), Uses(NULL) {
+    : NodeType(Opc), NodeId(-1), Uses(NULL) {
     OperandsNeedDelete = true;
     NumOperands = NumOps;
     OperandList = NumOps ? new SDUse[NumOperands] : 0;
@@ -1275,7 +1273,6 @@
       OperandList[i] = Ops[i];
       OperandList[i].setUser(this);
       Ops[i].getSDOperand().Val->addUse(OperandList[i]);
-      ++Ops[i].getSDOperand().Val->UsesSize;
     }
     
     ValueList = VTs.VTs;
@@ -1283,7 +1280,7 @@
   }
 
   SDNode(unsigned Opc, SDVTList VTs)
-    : NodeType(Opc), NodeId(-1), UsesSize(0), Uses(NULL) {
+    : NodeType(Opc), NodeId(-1), Uses(NULL) {
     OperandsNeedDelete = false;  // Operands set with InitOperands.
     NumOperands = 0;
     OperandList = 0;
@@ -1298,13 +1295,11 @@
     assert(OperandList == 0 && "Operands already set!");
     NumOperands = NumOps;
     OperandList = Ops;
-    UsesSize = 0;
     Uses = NULL;
     
     for (unsigned i = 0; i != NumOps; ++i) {
       OperandList[i].setUser(this);
       Ops[i].getVal()->addUse(OperandList[i]);
-      ++Ops[i].getVal()->UsesSize;
     }
   }
 
@@ -1323,14 +1318,12 @@
   void addUser(unsigned i, SDNode *User) {
     assert(User->OperandList[i].getUser() && "Node without parent");
     addUse(User->OperandList[i]);
-    ++UsesSize;
   }
 
   void removeUser(unsigned i, SDNode *User) {
     assert(User->OperandList[i].getUser() && "Node without parent");
     SDUse &Op = User->OperandList[i];
     Op.removeFromList();
-    --UsesSize;
   }
 };
 

Modified: llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAG.cpp?rev=53377&r1=53376&r2=53377&view=diff

==============================================================================
--- llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAG.cpp (original)
+++ llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAG.cpp Wed Jul  9 18:03:14 2008
@@ -3749,7 +3749,6 @@
     OperandList[i].setUser(this);
     SDNode *N = OperandList[i].getVal();
     N->addUser(i, this);
-    ++N->UsesSize;
     DeadNodeSet.erase(N);
   }
 
@@ -4394,16 +4393,9 @@
 bool SDNode::hasNUsesOfValue(unsigned NUses, unsigned Value) const {
   assert(Value < getNumValues() && "Bad value!");
 
-  // If there is only one value, this is easy.
-  if (getNumValues() == 1)
-    return use_size() == NUses;
-  if (use_size() < NUses) return false;
-
-  SDOperand TheValue(const_cast<SDNode *>(this), Value);
-
   // TODO: Only iterate over uses of a given value of the node
   for (SDNode::use_iterator UI = use_begin(), E = use_end(); UI != E; ++UI) {
-    if (*UI == TheValue) {
+    if (UI->getSDOperand().ResNo == Value) {
       if (NUses == 0)
         return false;
       --NUses;
@@ -4420,12 +4412,8 @@
 bool SDNode::hasAnyUseOfValue(unsigned Value) const {
   assert(Value < getNumValues() && "Bad value!");
 
-  if (use_empty()) return false;
-
-  SDOperand TheValue(const_cast<SDNode *>(this), Value);
-
   for (SDNode::use_iterator UI = use_begin(), E = use_end(); UI != E; ++UI)
-    if (UI->getSDOperand() == TheValue)
+    if (UI->getSDOperand().ResNo == Value)
       return true;
 
   return false;





More information about the llvm-commits mailing list