X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=lib%2FVMCore%2FValue.cpp;h=60be53db5b6ad6fe9b3346a244dae97172c1eb79;hb=551ccae044b0ff658fe629dd67edd5ffe75d10e8;hp=fcf0b7a4c4a6d167a704e2448e8615b84d8863ff;hpb=31f8499e83dc4dccbb57ea7e76d1fd49b7010d0c;p=oota-llvm.git diff --git a/lib/VMCore/Value.cpp b/lib/VMCore/Value.cpp index fcf0b7a4c4a..60be53db5b6 100644 --- a/lib/VMCore/Value.cpp +++ b/lib/VMCore/Value.cpp @@ -15,8 +15,10 @@ #include "llvm/SymbolTable.h" #include "llvm/DerivedTypes.h" #include "llvm/Constant.h" -#include "Support/LeakDetector.h" +#include "llvm/GlobalValue.h" +#include "llvm/Support/LeakDetector.h" #include +#include using namespace llvm; //===----------------------------------------------------------------------===// @@ -28,9 +30,14 @@ static inline const Type *checkType(const Type *Ty) { return Ty; } -Value::Value(const Type *ty, ValueTy vty, const std::string &name) - : Name(name), Ty(checkType(ty)) { - VTy = vty; +Value::Value(const Type *ty, unsigned scid, const std::string &name) + : SubclassID(scid), Ty(checkType(ty)), Name(name) { + if (!isa(this) && !isa(this)) + assert((Ty->isFirstClassType() || Ty == Type::VoidTy || + isa(ty)) && + "Cannot create non-first-class values except for constants!"); + if (ty == Type::VoidTy) + assert(name.empty() && "Cannot have named void values!"); } Value::~Value() { @@ -67,7 +74,10 @@ void Value::uncheckedReplaceAllUsesWith(Value *New) { // Must handle Constants specially, we cannot call replaceUsesOfWith on a // constant! if (Constant *C = dyn_cast(U.getUser())) { - C->replaceUsesOfWithOnConstant(this, New, true); + if (!isa(C)) + C->replaceUsesOfWithOnConstant(this, New, true); + else + U.set(New); } else { U.set(New); } @@ -87,17 +97,13 @@ void Value::replaceAllUsesWith(Value *New) { // User Class //===----------------------------------------------------------------------===// -User::User(const Type *Ty, ValueTy vty, const std::string &name) - : Value(Ty, vty, name) { -} - // replaceUsesOfWith - Replaces all references to the "From" definition with // references to the "To" definition. // void User::replaceUsesOfWith(Value *From, Value *To) { if (From == To) return; // Duh what? - assert(!isa(this) && + assert(!isa(this) || isa(this) && "Cannot call User::replaceUsesofWith on a constant!"); for (unsigned i = 0, E = getNumOperands(); i != E; ++i) @@ -108,3 +114,4 @@ void User::replaceUsesOfWith(Value *From, Value *To) { setOperand(i, To); // Fix it now... } } +