* Added SDNode::isOnlyUse().
authorEvan Cheng <evan.cheng@apple.com>
Sun, 5 Feb 2006 06:29:23 +0000 (06:29 +0000)
committerEvan Cheng <evan.cheng@apple.com>
Sun, 5 Feb 2006 06:29:23 +0000 (06:29 +0000)
* Fix hasNUsesOfValue(), it should be const.

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

include/llvm/CodeGen/SelectionDAGNodes.h
lib/CodeGen/SelectionDAG/SelectionDAG.cpp

index 0b850e617b16830155d665b29bed5cbcd08fcbca..1e8f8d8f2dc9ed51652177e1225483b25046f648 100644 (file)
@@ -619,7 +619,10 @@ public:
   /// hasNUsesOfValue - Return true if there are exactly NUSES uses of the
   /// indicated value.  This method ignores uses of other values defined by this
   /// operation.
-  bool hasNUsesOfValue(unsigned NUses, unsigned Value);
+  bool hasNUsesOfValue(unsigned NUses, unsigned Value) const;
+
+  // isOnlyUse - Return true if this node is the only use of N.
+  bool isOnlyUse(SDNode *N) const;
 
   /// getNumOperands - Return the number of values used by this operation.
   ///
index a8cd865c61ecf08aa9dcedf07141c6dfa162c084..8c08378cfdd8ca2577e637d85480b1b0489d806a 100644 (file)
@@ -2177,7 +2177,7 @@ MVT::ValueType *SDNode::getValueTypeList(MVT::ValueType VT) {
 /// hasNUsesOfValue - Return true if there are exactly NUSES uses of the
 /// indicated value.  This method ignores uses of other values defined by this
 /// operation.
-bool SDNode::hasNUsesOfValue(unsigned NUses, unsigned Value) {
+bool SDNode::hasNUsesOfValue(unsigned NUses, unsigned Value) const {
   assert(Value < getNumValues() && "Bad value!");
 
   // If there is only one value, this is easy.
@@ -2185,11 +2185,11 @@ bool SDNode::hasNUsesOfValue(unsigned NUses, unsigned Value) {
     return use_size() == NUses;
   if (Uses.size() < NUses) return false;
 
-  SDOperand TheValue(this, Value);
+  SDOperand TheValue(const_cast<SDNode *>(this), Value);
 
   std::set<SDNode*> UsersHandled;
 
-  for (std::vector<SDNode*>::iterator UI = Uses.begin(), E = Uses.end();
+  for (std::vector<SDNode*>::const_iterator UI = Uses.begin(), E = Uses.end();
        UI != E; ++UI) {
     SDNode *User = *UI;
     if (User->getNumOperands() == 1 ||
@@ -2207,6 +2207,21 @@ bool SDNode::hasNUsesOfValue(unsigned NUses, unsigned Value) {
 }
 
 
+// isOnlyUse - Return true if this node is the only use of N.
+bool SDNode::isOnlyUse(SDNode *N) const {
+  bool Seen = false;
+  for (SDNode::use_iterator I = N->use_begin(), E = N->use_end(); I != E; ++I) {
+    SDNode *User = *I;
+    if (User == this)
+      Seen = true;
+    else
+      return false;
+  }
+
+  return Seen;
+}
+
+
 const char *SDNode::getOperationName(const SelectionDAG *G) const {
   switch (getOpcode()) {
   default: