}
Value::Value(const Type *ty, ValueTy vty, const std::string &name)
- : Name(name), Ty(checkType(ty), this) {
+ : Name(name), Ty(checkType(ty)) {
VTy = vty;
}
// a <badref>
//
if (Uses.begin() != Uses.end()) {
- std::cerr << "While deleting: " << Ty << "%" << Name << "\n";
+ std::cerr << "While deleting: " << *Ty << "%" << Name << "\n";
for (use_const_iterator I = Uses.begin(); I != Uses.end(); ++I)
std::cerr << "Use still stuck around after Def is destroyed:"
<< **I << "\n";
}
#endif
- assert(Uses.begin() == Uses.end());
+ assert(Uses.begin() == Uses.end() &&"Uses remain when a value is destroyed!");
// There should be no uses of this object anymore, remove it.
LeakDetector::removeGarbageObject(this);
}
}
-// refineAbstractType - This function is implemented because we use
-// potentially abstract types, and these types may be resolved to more
-// concrete types after we are constructed. For the value class, we simply
-// change Ty to point to the right type. :)
+// uncheckedReplaceAllUsesWith - This is exactly the same as replaceAllUsesWith,
+// except that it doesn't have all of the asserts. The asserts fail because we
+// are half-way done resolving types, which causes some types to exist as two
+// different Type*'s at the same time. This is a sledgehammer to work around
+// this problem.
//
-void Value::refineAbstractType(const DerivedType *OldTy, const Type *NewTy) {
- assert(Ty.get() == OldTy && "Can't refine anything but my type!");
- if (OldTy == NewTy && !OldTy->isAbstract())
- Ty.removeUserFromConcrete();
- Ty = NewTy;
+void Value::uncheckedReplaceAllUsesWith(Value *New) {
+ while (!Uses.empty()) {
+ User *Use = Uses.back();
+ // Must handle Constants specially, we cannot call replaceUsesOfWith on a
+ // constant!
+ if (Constant *C = dyn_cast<Constant>(Use)) {
+ C->replaceUsesOfWithOnConstant(this, New, true);
+ } else {
+ Use->replaceUsesOfWith(this, New);
+ }
+ }
}
+
void Value::killUse(User *U) {
- if (U == 0) return;
+ assert(U != 0 && "Null users are not allowed!");
unsigned i;
// Scan backwards through the uses list looking for the user. We do this