#include "llvm/Instructions.h"
#include "llvm/Operator.h"
#include "llvm/Module.h"
-#include "llvm/MDNode.h"
+#include "llvm/Metadata.h"
#include "llvm/ValueSymbolTable.h"
#include "llvm/ADT/SmallString.h"
#include "llvm/Support/Debug.h"
} else if (Argument *A = dyn_cast<Argument>(V)) {
if (Function *P = A->getParent())
ST = &P->getValueSymbolTable();
+ } else if (NamedMDNode *N = dyn_cast<NamedMDNode>(V)) {
+ if (Module *P = N->getParent()) {
+ ST = &P->getValueSymbolTable();
+ }
} else if (isa<MDString>(V))
return true;
else {
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();
}
-
std::string Value::getNameStr() const {
return getName().str();
}
-void Value::setName(const Twine &Name) {
+void Value::setName(const Twine &NewName) {
SmallString<32> NameData;
- Name.toVector(NameData);
- setName(NameData.begin(), NameData.size());
-}
+ NewName.toVector(NameData);
+
+ 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.
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.
// 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();
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).
}
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).
}
}