[llvm-commits] CVS: llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp

Chris Lattner lattner at cs.uiuc.edu
Wed Jan 12 10:38:00 PST 2005



Changes in directory llvm/lib/CodeGen/SelectionDAG:

SelectionDAG.cpp updated: 1.26 -> 1.27
---
Log message:

New method


---
Diffs of the changes:  (+33 -0)

Index: llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
diff -u llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp:1.26 llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp:1.27
--- llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp:1.26	Mon Jan 10 23:57:01 2005
+++ llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp	Wed Jan 12 12:37:47 2005
@@ -833,6 +833,39 @@
   }
 }
 
+/// 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) {
+  assert(Value < getNumValues() && "Bad value!");
+
+  // If there is only one value, this is easy.
+  if (getNumValues() == 1)
+    return use_size() == NUses;
+  if (Uses.size() < NUses) return false;
+
+  SDOperand TheValue(this, Value);
+
+  std::set<SDNode*> UsersHandled;
+
+  for (std::vector<SDNode*>::iterator UI = Uses.begin(), E = Uses.end();
+       UI != E; ++UI) {
+    SDNode *User = *UI;
+    if (User->getNumOperands() == 1 ||
+        UsersHandled.insert(User).second)     // First time we've seen this?
+      for (unsigned i = 0, e = User->getNumOperands(); i != e; ++i)
+        if (User->getOperand(i) == TheValue) {
+          if (NUses == 0)
+            return false;   // too many uses
+          --NUses;
+        }
+  }
+
+  // Found exactly the right number of uses?
+  return NUses == 0;
+}
+
+
 const char *SDNode::getOperationName() const {
   switch (getOpcode()) {
   default: return "<<Unknown>>";






More information about the llvm-commits mailing list