remove all of the various setName implementations, consolidating them into
Value::setName, which is no longer virtual.

llvm-svn: 20464
diff --git a/llvm/lib/VMCore/BasicBlock.cpp b/llvm/lib/VMCore/BasicBlock.cpp
index 232a4e3..49bd8cf 100644
--- a/llvm/lib/VMCore/BasicBlock.cpp
+++ b/llvm/lib/VMCore/BasicBlock.cpp
@@ -16,7 +16,6 @@
 #include "llvm/Instructions.h"
 #include "llvm/Type.h"
 #include "llvm/Support/CFG.h"
-#include "llvm/SymbolTable.h"
 #include "llvm/Support/LeakDetector.h"
 #include "SymbolTableListTraitsImpl.h"
 #include <algorithm>
@@ -95,14 +94,6 @@
     LeakDetector::removeGarbageObject(this);
 }
 
-// Specialize setName to take care of symbol table majik
-void BasicBlock::setName(const std::string &name) {
-  Function *P;
-  if ((P = getParent()) && hasName()) P->getSymbolTable().remove(this);
-  Value::setName(name);
-  if (P && hasName()) P->getSymbolTable().insert(this);
-}
-
 void BasicBlock::removeFromParent() {
   getParent()->getBasicBlockList().remove(this);
 }
diff --git a/llvm/lib/VMCore/Constants.cpp b/llvm/lib/VMCore/Constants.cpp
index 99a15ea..dfba350 100644
--- a/llvm/lib/VMCore/Constants.cpp
+++ b/llvm/lib/VMCore/Constants.cpp
@@ -31,10 +31,6 @@
 //                              Constant Class
 //===----------------------------------------------------------------------===//
 
-void Constant::setName(const std::string &Name) {
-  // Constants can't take names.
-}
-
 void Constant::destroyConstantImpl() {
   // When a Constant is destroyed, there may be lingering
   // references to the constant by other constants in the constant pool.  These
diff --git a/llvm/lib/VMCore/Function.cpp b/llvm/lib/VMCore/Function.cpp
index 7cced30..df8d1f9 100644
--- a/llvm/lib/VMCore/Function.cpp
+++ b/llvm/lib/VMCore/Function.cpp
@@ -62,15 +62,6 @@
     Par->getArgumentList().push_back(this);
 }
 
-
-// Specialize setName to take care of symbol table majik
-void Argument::setName(const std::string &name) {
-  Function *P;
-  if ((P = getParent()) && hasName()) P->getSymbolTable().remove(this);
-  Value::setName(name);
-  if (P && hasName()) P->getSymbolTable().insert(this);
-}
-
 void Argument::setParent(Function *parent) {
   if (getParent())
     LeakDetector::addGarbageObject(this);
@@ -118,14 +109,6 @@
   delete SymTab;
 }
 
-// Specialize setName to take care of symbol table majik
-void Function::setName(const std::string &name) {
-  Module *P;
-  if ((P = getParent()) && hasName()) P->getSymbolTable().remove(this);
-  Value::setName(name);
-  if (P && hasName()) P->getSymbolTable().insert(this);
-}
-
 void Function::setParent(Module *parent) {
   if (getParent())
     LeakDetector::addGarbageObject(this);
diff --git a/llvm/lib/VMCore/Globals.cpp b/llvm/lib/VMCore/Globals.cpp
index efa588b..c0264ae 100644
--- a/llvm/lib/VMCore/Globals.cpp
+++ b/llvm/lib/VMCore/Globals.cpp
@@ -99,14 +99,6 @@
     LeakDetector::removeGarbageObject(this);
 }
 
-// Specialize setName to take care of symbol table majik
-void GlobalVariable::setName(const std::string &name) {
-  Module *P;
-  if ((P = getParent()) && hasName()) P->getSymbolTable().remove(this);
-  Value::setName(name);
-  if (P && hasName()) P->getSymbolTable().insert(this);
-}
-
 void GlobalVariable::removeFromParent() {
   getParent()->getGlobalList().remove(this);
 }
diff --git a/llvm/lib/VMCore/Instruction.cpp b/llvm/lib/VMCore/Instruction.cpp
index eeba47b..4ccbd74 100644
--- a/llvm/lib/VMCore/Instruction.cpp
+++ b/llvm/lib/VMCore/Instruction.cpp
@@ -57,15 +57,6 @@
   Parent = P;
 }
 
-// Specialize setName to take care of symbol table majik
-void Instruction::setName(const std::string &name) {
-  BasicBlock *P = 0; Function *PP = 0;
-  if ((P = getParent()) && (PP = P->getParent()) && hasName())
-    PP->getSymbolTable().remove(this);
-  Value::setName(name);
-  if (PP && hasName()) PP->getSymbolTable().insert(this);
-}
-
 void Instruction::removeFromParent() {
   getParent()->getInstList().remove(this);
 }
diff --git a/llvm/lib/VMCore/Value.cpp b/llvm/lib/VMCore/Value.cpp
index b3b133f..cdde96b 100644
--- a/llvm/lib/VMCore/Value.cpp
+++ b/llvm/lib/VMCore/Value.cpp
@@ -11,11 +11,11 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "llvm/InstrTypes.h"
-#include "llvm/SymbolTable.h"
-#include "llvm/DerivedTypes.h"
 #include "llvm/Constant.h"
-#include "llvm/GlobalValue.h"
+#include "llvm/DerivedTypes.h"
+#include "llvm/InstrTypes.h"
+#include "llvm/Module.h"
+#include "llvm/SymbolTable.h"
 #include "llvm/Support/LeakDetector.h"
 #include <algorithm>
 #include <iostream>
@@ -93,6 +93,31 @@
 }
 
 
+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