[llvm-commits] CVS: llvm/lib/VMCore/Value.cpp
Chris Lattner
lattner at cs.uiuc.edu
Wed Oct 9 18:14:01 PDT 2002
Changes in directory llvm/lib/VMCore:
Value.cpp updated: 1.29 -> 1.30
---
Log message:
- Make Value::replaceAllUsesWith work with constants correctly. This fixes
bug FuncResolve/2002-08-19-ResolveGlobalVars.ll and gzip looks better.
---
Diffs of the changes:
Index: llvm/lib/VMCore/Value.cpp
diff -u llvm/lib/VMCore/Value.cpp:1.29 llvm/lib/VMCore/Value.cpp:1.30
--- llvm/lib/VMCore/Value.cpp:1.29 Tue Oct 8 19:25:05 2002
+++ llvm/lib/VMCore/Value.cpp Wed Oct 9 18:12:59 2002
@@ -7,6 +7,7 @@
#include "llvm/InstrTypes.h"
#include "llvm/SymbolTable.h"
#include "llvm/DerivedTypes.h"
+#include "llvm/Constant.h"
#include "Support/LeakDetector.h"
#include <algorithm>
@@ -45,23 +46,23 @@
LeakDetector::removeGarbageObject(this);
}
-void Value::replaceAllUsesWith(Value *D) {
- assert(D && "Value::replaceAllUsesWith(<null>) is invalid!");
- assert(D != this && "V->replaceAllUsesWith(V) is NOT valid!");
- assert(D->getType() == getType() &&
+
+
+
+void Value::replaceAllUsesWith(Value *New) {
+ assert(New && "Value::replaceAllUsesWith(<null>) is invalid!");
+ assert(New != this && "this->replaceAllUsesWith(this) is NOT valid!");
+ assert(New->getType() == getType() &&
"replaceAllUses of value with new value of different type!");
while (!Uses.empty()) {
User *Use = Uses.back();
-#ifndef NDEBUG
- unsigned NumUses = Uses.size();
-#endif
- Use->replaceUsesOfWith(this, D);
-
-#ifndef NDEBUG // only in -g mode...
- if (Uses.size() == NumUses)
- std::cerr << "Use: " << *Use << "replace with: " << *D;
-#endif
- assert(Uses.size() != NumUses && "Didn't remove definition!");
+ // Must handle Constants specially, we cannot call replaceUsesOfWith on a
+ // constant!
+ if (Constant *C = dyn_cast<Constant>(Use)) {
+ C->replaceUsesOfWithOnConstant(this, New);
+ } else {
+ Use->replaceUsesOfWith(this, New);
+ }
}
}
@@ -105,6 +106,9 @@
void User::replaceUsesOfWith(Value *From, Value *To) {
if (From == To) return; // Duh what?
+ assert(!isa<Constant>(this) &&
+ "Cannot call User::replaceUsesofWith on a constant!");
+
for (unsigned i = 0, E = getNumOperands(); i != E; ++i)
if (getOperand(i) == From) { // Is This operand is pointing to oldval?
// The side effects of this setOperand call include linking to
@@ -113,5 +117,3 @@
setOperand(i, To); // Fix it now...
}
}
-
-
More information about the llvm-commits
mailing list