Change to use GetAddressOfSymbol instead of dlsym.
[oota-llvm.git] / lib / VMCore / Value.cpp
index 6cb0b09f5202972f01b8e00d6a542505e0e596fe..95670f398262776d75501397a60bfac4a3b901de 100644 (file)
@@ -21,7 +21,7 @@ static inline const Type *checkType(const Type *Ty) {
 }
 
 Value::Value(const Type *ty, ValueTy vty, const std::string &name)
-  : Name(name), Ty(checkType(ty), this) {
+  : Name(name), Ty(checkType(ty)) {
   VTy = vty;
 }
 
@@ -34,7 +34,7 @@ Value::~Value() {
   // 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";
@@ -66,20 +66,28 @@ void Value::replaceAllUsesWith(Value *New) {
   }
 }
 
-// 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