mirror of
https://github.com/RPCS3/llvm.git
synced 2025-01-27 13:42:24 +00:00
Add new setName accessor which doesn't require creating a string.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@34197 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
34a451ddc8
commit
042ad36871
@ -91,6 +91,7 @@ public:
|
|||||||
ValueName *getValueName() const { return Name; }
|
ValueName *getValueName() const { return Name; }
|
||||||
|
|
||||||
void setName(const std::string &name);
|
void setName(const std::string &name);
|
||||||
|
void setName(const char *Name, unsigned NameLen);
|
||||||
|
|
||||||
/// takeName - transfer the name from V to this value, setting V's name to
|
/// takeName - transfer the name from V to this value, setting V's name to
|
||||||
/// empty. It is an error to call V->takeName(V).
|
/// empty. It is an error to call V->takeName(V).
|
||||||
|
@ -119,33 +119,40 @@ std::string Value::getName() const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Value::setName(const std::string &name) {
|
void Value::setName(const std::string &name) {
|
||||||
if (name.empty() && !hasName()) return;
|
setName(&name[0], name.size());
|
||||||
|
}
|
||||||
|
|
||||||
|
void Value::setName(const char *NameStr, unsigned NameLen) {
|
||||||
|
if (NameLen == 0 && !hasName()) return;
|
||||||
if (getType() != Type::VoidTy && "Cannot assign a name to void values!");
|
if (getType() != Type::VoidTy && "Cannot assign a name to void values!");
|
||||||
|
|
||||||
|
|
||||||
// Get the symbol table to update for this object.
|
// Get the symbol table to update for this object.
|
||||||
ValueSymbolTable *ST;
|
ValueSymbolTable *ST;
|
||||||
if (getSymTab(this, ST))
|
if (getSymTab(this, ST))
|
||||||
return; // Cannot set a name on this value (e.g. constant).
|
return; // Cannot set a name on this value (e.g. constant).
|
||||||
|
|
||||||
if (!ST) { // No symbol table to update? Just do the change.
|
if (!ST) { // No symbol table to update? Just do the change.
|
||||||
if (name.empty()) {
|
if (NameLen == 0) {
|
||||||
// Free the name for this value.
|
// Free the name for this value.
|
||||||
Name->Destroy();
|
Name->Destroy();
|
||||||
Name = 0;
|
Name = 0;
|
||||||
} else {
|
return;
|
||||||
if (Name) {
|
|
||||||
// Name isn't changing.
|
|
||||||
if (name.size() == Name->getKeyLength() &&
|
|
||||||
!memcmp(Name->getKeyData(), &name[0], name.size()))
|
|
||||||
return;
|
|
||||||
Name->Destroy();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create the new name.
|
|
||||||
Name = ValueName::Create(&name[0], &name[name.size()]);
|
|
||||||
Name->setValue(this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (Name) {
|
||||||
|
// Name isn't changing?
|
||||||
|
if (NameLen == Name->getKeyLength() &&
|
||||||
|
!memcmp(Name->getKeyData(), NameStr, NameLen))
|
||||||
|
return;
|
||||||
|
Name->Destroy();
|
||||||
|
}
|
||||||
|
|
||||||
|
// NOTE: Could optimize for the case the name is shrinking to not deallocate
|
||||||
|
// then reallocated.
|
||||||
|
|
||||||
|
// Create the new name.
|
||||||
|
Name = ValueName::Create(NameStr, NameStr+NameLen);
|
||||||
|
Name->setValue(this);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -153,8 +160,8 @@ void Value::setName(const std::string &name) {
|
|||||||
// then reallocated.
|
// then reallocated.
|
||||||
if (hasName()) {
|
if (hasName()) {
|
||||||
// Name isn't changing?
|
// Name isn't changing?
|
||||||
if (name.size() == Name->getKeyLength() &&
|
if (NameLen == Name->getKeyLength() &&
|
||||||
!memcmp(Name->getKeyData(), &name[0], name.size()))
|
!memcmp(Name->getKeyData(), NameStr, NameLen))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// Remove old name.
|
// Remove old name.
|
||||||
@ -162,14 +169,15 @@ void Value::setName(const std::string &name) {
|
|||||||
Name->Destroy();
|
Name->Destroy();
|
||||||
Name = 0;
|
Name = 0;
|
||||||
|
|
||||||
if (name.empty())
|
if (NameLen == 0)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Name is changing to something new.
|
// Name is changing to something new.
|
||||||
Name = ST->createValueName(&name[0], name.size(), this);
|
Name = ST->createValueName(NameStr, NameLen, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// takeName - transfer the name from V to this value, setting V's name to
|
/// takeName - transfer the name from V to this value, setting V's name to
|
||||||
/// empty. It is an error to call V->takeName(V).
|
/// empty. It is an error to call V->takeName(V).
|
||||||
void Value::takeName(Value *V) {
|
void Value::takeName(Value *V) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user