mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-12-13 20:32:21 +00:00
add a helper method: Value::takeName
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@34171 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
9cc2d3dce8
commit
7216811ea2
@ -88,6 +88,10 @@ public:
|
|||||||
inline const std::string &getName() const { return Name; }
|
inline const std::string &getName() const { return Name; }
|
||||||
|
|
||||||
void setName(const std::string &name);
|
void setName(const std::string &name);
|
||||||
|
|
||||||
|
/// takeName - transfer the name from V to this value, setting V's name to
|
||||||
|
/// empty. It is an error to call V->takeName(V).
|
||||||
|
void takeName(Value *V);
|
||||||
|
|
||||||
/// replaceAllUsesWith - Go through the uses list for this definition and make
|
/// replaceAllUsesWith - Go through the uses list for this definition and make
|
||||||
/// each use point to "V" instead of "this". After this completes, 'this's
|
/// each use point to "V" instead of "this". After this completes, 'this's
|
||||||
|
@ -92,29 +92,34 @@ unsigned Value::getNumUses() const {
|
|||||||
return (unsigned)std::distance(use_begin(), use_end());
|
return (unsigned)std::distance(use_begin(), use_end());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool getSymTab(Value *V, ValueSymbolTable *&ST) {
|
||||||
|
if (Instruction *I = dyn_cast<Instruction>(V)) {
|
||||||
|
if (BasicBlock *P = I->getParent())
|
||||||
|
if (Function *PP = P->getParent())
|
||||||
|
ST = &PP->getValueSymbolTable();
|
||||||
|
} else if (BasicBlock *BB = dyn_cast<BasicBlock>(V)) {
|
||||||
|
if (Function *P = BB->getParent())
|
||||||
|
ST = &P->getValueSymbolTable();
|
||||||
|
} else if (GlobalValue *GV = dyn_cast<GlobalValue>(V)) {
|
||||||
|
if (Module *P = GV->getParent())
|
||||||
|
ST = &P->getValueSymbolTable();
|
||||||
|
} else if (Argument *A = dyn_cast<Argument>(V)) {
|
||||||
|
if (Function *P = A->getParent())
|
||||||
|
ST = &P->getValueSymbolTable();
|
||||||
|
} else {
|
||||||
|
assert(isa<Constant>(V) && "Unknown value type!");
|
||||||
|
return true; // no name is setable for this.
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
void Value::setName(const std::string &name) {
|
void Value::setName(const std::string &name) {
|
||||||
if (Name == name) return; // Name is already set.
|
if (Name == name) return; // Name is already set.
|
||||||
|
|
||||||
// Get the symbol table to update for this object.
|
// Get the symbol table to update for this object.
|
||||||
ValueSymbolTable *ST = 0;
|
ValueSymbolTable *ST;
|
||||||
if (Instruction *I = dyn_cast<Instruction>(this)) {
|
if (getSymTab(this, ST))
|
||||||
if (BasicBlock *P = I->getParent())
|
return; // Cannot set a name on this value (e.g. constant).
|
||||||
if (Function *PP = P->getParent())
|
|
||||||
ST = &PP->getValueSymbolTable();
|
|
||||||
} else if (BasicBlock *BB = dyn_cast<BasicBlock>(this)) {
|
|
||||||
if (Function *P = BB->getParent())
|
|
||||||
ST = &P->getValueSymbolTable();
|
|
||||||
} else if (GlobalValue *GV = dyn_cast<GlobalValue>(this)) {
|
|
||||||
if (Module *P = GV->getParent())
|
|
||||||
ST = &P->getValueSymbolTable();
|
|
||||||
} else if (Argument *A = dyn_cast<Argument>(this)) {
|
|
||||||
if (Function *P = A->getParent())
|
|
||||||
ST = &P->getValueSymbolTable();
|
|
||||||
} else {
|
|
||||||
assert(isa<Constant>(this) && "Unknown value type!");
|
|
||||||
return; // no name is setable for this.
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!ST) // No symbol table to update? Just do the change.
|
if (!ST) // No symbol table to update? Just do the change.
|
||||||
Name = name;
|
Name = name;
|
||||||
@ -133,6 +138,15 @@ void Value::setName(const std::string &name) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// takeName - transfer the name from V to this value, setting V's name to
|
||||||
|
/// empty. It is an error to call V->takeName(V).
|
||||||
|
void Value::takeName(Value *V) {
|
||||||
|
std::string Name = V->getName();
|
||||||
|
V->setName("");
|
||||||
|
setName(Name);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// uncheckedReplaceAllUsesWith - This is exactly the same as replaceAllUsesWith,
|
// uncheckedReplaceAllUsesWith - This is exactly the same as replaceAllUsesWith,
|
||||||
// except that it doesn't have all of the asserts. The asserts fail because we
|
// 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
|
// are half-way done resolving types, which causes some types to exist as two
|
||||||
|
Loading…
Reference in New Issue
Block a user