summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2007-02-11 00:37:27 +0000
committerChris Lattner <sabre@nondot.org>2007-02-11 00:37:27 +0000
commitb625082a4261aacb4a91d770f6ebce9a8a7b4735 (patch)
treed5f3625a6f2f84a5e5459c6b2ee994fb7c15900c
parenta48a96ef5f0b9d08b739787251e83f3773a4e92f (diff)
downloadbcm5719-llvm-b625082a4261aacb4a91d770f6ebce9a8a7b4735.tar.gz
bcm5719-llvm-b625082a4261aacb4a91d770f6ebce9a8a7b4735.zip
add a helper method: Value::takeName
llvm-svn: 34171
-rw-r--r--llvm/include/llvm/Value.h4
-rw-r--r--llvm/lib/VMCore/Value.cpp38
2 files changed, 30 insertions, 12 deletions
diff --git a/llvm/include/llvm/Value.h b/llvm/include/llvm/Value.h
index 63af0f747d6..3c072e0d676 100644
--- a/llvm/include/llvm/Value.h
+++ b/llvm/include/llvm/Value.h
@@ -88,6 +88,10 @@ public:
inline const std::string &getName() const { return 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
/// each use point to "V" instead of "this". After this completes, 'this's
diff --git a/llvm/lib/VMCore/Value.cpp b/llvm/lib/VMCore/Value.cpp
index f84671d4756..af753236c1d 100644
--- a/llvm/lib/VMCore/Value.cpp
+++ b/llvm/lib/VMCore/Value.cpp
@@ -92,29 +92,34 @@ unsigned Value::getNumUses() const {
return (unsigned)std::distance(use_begin(), use_end());
}
-
-void Value::setName(const std::string &name) {
- if (Name == name) return; // Name is already set.
-
- // Get the symbol table to update for this object.
- ValueSymbolTable *ST = 0;
- if (Instruction *I = dyn_cast<Instruction>(this)) {
+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>(this)) {
+ } else if (BasicBlock *BB = dyn_cast<BasicBlock>(V)) {
if (Function *P = BB->getParent())
ST = &P->getValueSymbolTable();
- } else if (GlobalValue *GV = dyn_cast<GlobalValue>(this)) {
+ } else if (GlobalValue *GV = dyn_cast<GlobalValue>(V)) {
if (Module *P = GV->getParent())
ST = &P->getValueSymbolTable();
- } else if (Argument *A = dyn_cast<Argument>(this)) {
+ } else if (Argument *A = dyn_cast<Argument>(V)) {
if (Function *P = A->getParent())
ST = &P->getValueSymbolTable();
} else {
- assert(isa<Constant>(this) && "Unknown value type!");
- return; // no name is setable for this.
+ assert(isa<Constant>(V) && "Unknown value type!");
+ return true; // no name is setable for this.
}
+ return false;
+}
+
+void Value::setName(const std::string &name) {
+ if (Name == name) return; // Name is already set.
+
+ // Get the symbol table to update for this object.
+ ValueSymbolTable *ST;
+ if (getSymTab(this, ST))
+ return; // Cannot set a name on this value (e.g. constant).
if (!ST) // No symbol table to update? Just do the change.
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,
// 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
OpenPOWER on IntegriCloud