X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=lib%2FVMCore%2FValue.cpp;h=2cdd55217cc4133c1af6495513b7c0073e4db3aa;hb=55a961f075db29a254d3173b105e9930c5400f66;hp=66fcaf38fba3cc1b9a0f9ac386f6a1d77990009a;hpb=016de81177ec5c950f1668be4a48992bc1ee0d75;p=oota-llvm.git diff --git a/lib/VMCore/Value.cpp b/lib/VMCore/Value.cpp index 66fcaf38fba..2cdd55217cc 100644 --- a/lib/VMCore/Value.cpp +++ b/lib/VMCore/Value.cpp @@ -18,7 +18,9 @@ #include "llvm/Instructions.h" #include "llvm/Operator.h" #include "llvm/Module.h" +#include "llvm/Metadata.h" #include "llvm/ValueSymbolTable.h" +#include "llvm/ADT/SmallString.h" #include "llvm/Support/Debug.h" #include "llvm/Support/ErrorHandling.h" #include "llvm/Support/LeakDetector.h" @@ -67,9 +69,9 @@ Value::~Value() { // a // if (!use_empty()) { - cerr << "While deleting: " << *VTy << " %" << getNameStr() << "\n"; + errs() << "While deleting: " << *VTy << " %" << getNameStr() << "\n"; for (use_iterator I = use_begin(), E = use_end(); I != E; ++I) - cerr << "Use still stuck around after Def is destroyed:" + errs() << "Use still stuck around after Def is destroyed:" << **I << "\n"; } #endif @@ -140,51 +142,42 @@ static bool getSymTab(Value *V, ValueSymbolTable *&ST) { } else if (Argument *A = dyn_cast(V)) { if (Function *P = A->getParent()) ST = &P->getValueSymbolTable(); - } else { + } else if (NamedMDNode *N = dyn_cast(V)) { + if (Module *P = N->getParent()) { + ST = &P->getValueSymbolTable(); + } + } else if (isa(V)) + return true; + else { assert(isa(V) && "Unknown value type!"); return true; // no name is setable for this. } return false; } -/// getNameStart - Return a pointer to a null terminated string for this name. -/// Note that names can have null characters within the string as well as at -/// their end. This always returns a non-null pointer. -const char *Value::getNameStart() const { - if (Name == 0) return ""; - return Name->getKeyData(); -} - -/// getNameLen - Return the length of the string, correctly handling nul -/// characters embedded into them. -unsigned Value::getNameLen() const { - return Name ? Name->getKeyLength() : 0; +StringRef Value::getName() const { + // Make sure the empty string is still a C string. For historical reasons, + // some clients want to call .data() on the result and expect it to be null + // terminated. + if (!Name) return StringRef("", 0); + return Name->getKey(); } -/// isName - Return true if this value has the name specified by the provided -/// nul terminated string. -bool Value::isName(const char *N) const { - unsigned InLen = strlen(N); - return InLen == getNameLen() && memcmp(getNameStart(), N, InLen) == 0; -} - - std::string Value::getNameStr() const { - if (Name == 0) return ""; - return std::string(Name->getKeyData(), - Name->getKeyData()+Name->getKeyLength()); + return getName().str(); } -void Value::setName(const std::string &name) { - setName(&name[0], name.size()); -} +void Value::setName(const Twine &NewName) { + SmallString<32> NameData; + NewName.toVector(NameData); -void Value::setName(const char *Name) { - setName(Name, Name ? strlen(Name) : 0); -} + const char *NameStr = NameData.data(); + unsigned NameLen = NameData.size(); + + // Name isn't changing? + if (getName() == StringRef(NameStr, NameLen)) + return; -void Value::setName(const char *NameStr, unsigned NameLen) { - if (NameLen == 0 && !hasName()) return; assert(getType() != Type::VoidTy && "Cannot assign a name to void values!"); // Get the symbol table to update for this object. @@ -200,13 +193,8 @@ void Value::setName(const char *NameStr, unsigned NameLen) { return; } - if (Name) { - // Name isn't changing? - if (NameLen == Name->getKeyLength() && - !memcmp(Name->getKeyData(), NameStr, NameLen)) - return; + if (Name) Name->Destroy(); - } // NOTE: Could optimize for the case the name is shrinking to not deallocate // then reallocated. @@ -220,11 +208,6 @@ void Value::setName(const char *NameStr, unsigned NameLen) { // NOTE: Could optimize for the case the name is shrinking to not deallocate // then reallocated. if (hasName()) { - // Name isn't changing? - if (NameLen == Name->getKeyLength() && - !memcmp(Name->getKeyData(), NameStr, NameLen)) - return; - // Remove old name. ST->removeValueName(Name); Name->Destroy(); @@ -235,7 +218,7 @@ void Value::setName(const char *NameStr, unsigned NameLen) { } // Name is changing to something new. - Name = ST->createValueName(NameStr, NameLen, this); + Name = ST->createValueName(StringRef(NameStr, NameLen), this); } @@ -249,7 +232,7 @@ void Value::takeName(Value *V) { if (getSymTab(this, ST)) { // We can't set a name on this value, but we need to clear V's name if // it has one. - if (V->hasName()) V->setName(0, 0); + if (V->hasName()) V->setName(""); return; // Cannot set a name on this value (e.g. constant). } @@ -269,7 +252,7 @@ void Value::takeName(Value *V) { if (!ST) { if (getSymTab(this, ST)) { // Clear V's name. - V->setName(0, 0); + V->setName(""); return; // Cannot set a name on this value (e.g. constant). } } @@ -363,8 +346,6 @@ Value *Value::getUnderlyingObject() { unsigned MaxLookup = 6; do { if (GEPOperator *GEP = dyn_cast(V)) { - if (GEP->hasNoPointerOverflow()) - return V; V = GEP->getPointerOperand(); } else if (Operator::getOpcode(V) == Instruction::BitCast) { V = cast(V)->getOperand(0); @@ -388,6 +369,8 @@ Value *Value::DoPHITranslation(const BasicBlock *CurBB, return this; } +LLVMContext &Value::getContext() const { return VTy->getContext(); } + //===----------------------------------------------------------------------===// // ValueHandleBase Class //===----------------------------------------------------------------------===// @@ -501,8 +484,8 @@ void ValueHandleBase::ValueIsDeleted(Value *V) { switch (ThisNode->getKind()) { case Assert: #ifndef NDEBUG // Only in -g mode... - cerr << "While deleting: " << *V->getType() << " %" << V->getNameStr() - << "\n"; + errs() << "While deleting: " << *V->getType() << " %" << V->getNameStr() + << "\n"; #endif llvm_unreachable("An asserting value handle still pointed to this" " value!");