[llvm-commits] CVS: llvm/lib/VMCore/Value.cpp

Chris Lattner lattner at cs.uiuc.edu
Mon Jan 31 17:24:33 PST 2005



Changes in directory llvm/lib/VMCore:

Value.cpp updated: 1.51 -> 1.52
---
Log message:

Updates for new use list changes.


---
Diffs of the changes:  (+23 -6)

 Value.cpp |   29 +++++++++++++++++++++++------
 1 files changed, 23 insertions(+), 6 deletions(-)


Index: llvm/lib/VMCore/Value.cpp
diff -u llvm/lib/VMCore/Value.cpp:1.51 llvm/lib/VMCore/Value.cpp:1.52
--- llvm/lib/VMCore/Value.cpp:1.51	Fri Oct 15 18:08:50 2004
+++ llvm/lib/VMCore/Value.cpp	Mon Jan 31 19:24:21 2005
@@ -31,7 +31,7 @@
 }
 
 Value::Value(const Type *ty, unsigned scid, const std::string &name)
-  : SubclassID(scid), Ty(checkType(ty)), Name(name) {
+  : SubclassID(scid), Ty(checkType(ty)), UseList(0), Name(name) {
   if (!isa<Constant>(this) && !isa<BasicBlock>(this))
     assert((Ty->isFirstClassType() || Ty == Type::VoidTy || 
            isa<OpaqueType>(ty)) &&
@@ -48,19 +48,36 @@
   // still being referenced.  The value in question should be printed as 
   // a <badref>
   //
-  if (Uses.begin() != Uses.end()) {
+  if (use_begin() != use_end()) {
     std::cerr << "While deleting: " << *Ty << " %" << Name << "\n";
-    for (use_const_iterator I = Uses.begin(), E = Uses.end(); I != E; ++I)
+    for (use_iterator I = use_begin(), E = use_end(); I != E; ++I)
       std::cerr << "Use still stuck around after Def is destroyed:"
                 << **I << "\n";
   }
 #endif
-  assert(Uses.begin() == Uses.end() &&"Uses remain when a value is destroyed!");
+  assert(use_begin() == use_end() && "Uses remain when a value is destroyed!");
 
   // There should be no uses of this object anymore, remove it.
   LeakDetector::removeGarbageObject(this);
 }
 
+/// hasNUses - Return true if this Value has exactly N users.
+///
+bool Value::hasNUses(unsigned N) const {
+  use_const_iterator UI = use_begin(), E = use_end();
+
+  for (; N; --N, ++UI)
+    if (UI == E) return false;  // Too few.
+  return UI == E;
+}
+
+/// getNumUses - This method computes the number of uses of this Value.  This
+/// is a linear time operation.  Use hasOneUse or hasNUses to check for specific
+/// values.
+unsigned Value::getNumUses() const {
+  return (unsigned)std::distance(use_begin(), use_end());
+}
+
 
 // uncheckedReplaceAllUsesWith - This is exactly the same as replaceAllUsesWith,
 // except that it doesn't have all of the asserts.  The asserts fail because we
@@ -69,8 +86,8 @@
 // this problem.
 //
 void Value::uncheckedReplaceAllUsesWith(Value *New) {
-  while (!Uses.empty()) {
-    Use &U = Uses.back();
+  while (!use_empty()) {
+    Use &U = *UseList;
     // Must handle Constants specially, we cannot call replaceUsesOfWith on a
     // constant!
     if (Constant *C = dyn_cast<Constant>(U.getUser())) {






More information about the llvm-commits mailing list