aboutsummaryrefslogtreecommitdiff
path: root/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2005-01-12 18:37:47 +0000
committerChris Lattner <sabre@nondot.org>2005-01-12 18:37:47 +0000
commit5c884562279927757cbe0ae718ab18af730ddb35 (patch)
treea170151a711c72cee25361a688dc69551674e47b /lib/CodeGen/SelectionDAG/SelectionDAG.cpp
parentb18a2f816cc9d1351ca8e380a6db5c5ef981943e (diff)
New method
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@19517 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen/SelectionDAG/SelectionDAG.cpp')
-rw-r--r--lib/CodeGen/SelectionDAG/SelectionDAG.cpp33
1 files changed, 33 insertions, 0 deletions
diff --git a/lib/CodeGen/SelectionDAG/SelectionDAG.cpp b/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
index 1996880e4b..3f598fd8b3 100644
--- a/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
+++ b/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
@@ -833,6 +833,39 @@ SDOperand SelectionDAG::getNode(unsigned Opcode, 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) {
+ 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>>";