aboutsummaryrefslogtreecommitdiff
path: root/lib/VMCore/Value.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'lib/VMCore/Value.cpp')
-rw-r--r--lib/VMCore/Value.cpp31
1 files changed, 28 insertions, 3 deletions
diff --git a/lib/VMCore/Value.cpp b/lib/VMCore/Value.cpp
index b3b133f779..cdde96b455 100644
--- a/lib/VMCore/Value.cpp
+++ b/lib/VMCore/Value.cpp
@@ -11,11 +11,11 @@
//
//===----------------------------------------------------------------------===//
+#include "llvm/Constant.h"
+#include "llvm/DerivedTypes.h"
#include "llvm/InstrTypes.h"
+#include "llvm/Module.h"
#include "llvm/SymbolTable.h"
-#include "llvm/DerivedTypes.h"
-#include "llvm/Constant.h"
-#include "llvm/GlobalValue.h"
#include "llvm/Support/LeakDetector.h"
#include <algorithm>
#include <iostream>
@@ -93,6 +93,31 @@ unsigned Value::getNumUses() const {
}
+void Value::setName(const std::string &name) {
+ if (Name == name) return; // Name is already set.
+
+ SymbolTable *ST = 0;
+
+ if (Instruction *I = dyn_cast<Instruction>(this)) {
+ if (BasicBlock *P = I->getParent())
+ if (Function *PP = P->getParent())
+ ST = &PP->getSymbolTable();
+ } else if (BasicBlock *BB = dyn_cast<BasicBlock>(this)) {
+ if (Function *P = BB->getParent()) ST = &P->getSymbolTable();
+ } else if (GlobalValue *GV = dyn_cast<GlobalValue>(this)) {
+ if (Module *P = GV->getParent()) ST = &P->getSymbolTable();
+ } else if (Argument *A = dyn_cast<Argument>(this)) {
+ if (Function *P = A->getParent()) ST = &P->getSymbolTable();
+ } else {
+ assert(isa<Constant>(this) && "Unknown value type!");
+ return; // no name is setable for this.
+ }
+
+ if (ST && hasName()) ST->remove(this);
+ Name = name;
+ if (ST && hasName()) ST->insert(this);
+}
+
// 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