remove all of the various setName implementations, consolidating them into
authorChris Lattner <sabre@nondot.org>
Sat, 5 Mar 2005 19:51:50 +0000 (19:51 +0000)
committerChris Lattner <sabre@nondot.org>
Sat, 5 Mar 2005 19:51:50 +0000 (19:51 +0000)
Value::setName, which is no longer virtual.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@20464 91177308-0d34-0410-b5e6-96231b3b80d8

13 files changed:
include/llvm/Argument.h
include/llvm/BasicBlock.h
include/llvm/Constant.h
include/llvm/Function.h
include/llvm/GlobalVariable.h
include/llvm/Instruction.h
include/llvm/Value.h
lib/VMCore/BasicBlock.cpp
lib/VMCore/Constants.cpp
lib/VMCore/Function.cpp
lib/VMCore/Globals.cpp
lib/VMCore/Instruction.cpp
lib/VMCore/Value.cpp

index 51e53b17bd1321afe319a8b9c3ebb0c68ac9dd7a..3c38cdea037137f66b99ede2edc5cf12b5b0b181 100644 (file)
@@ -39,9 +39,6 @@ public:
   ///
   Argument(const Type *Ty, const std::string &Name = "", Function *F = 0);
 
-  /// setName - Specialize setName to handle symbol table majik.
-  virtual void setName(const std::string &name);
-
   inline const Function *getParent() const { return Parent; }
   inline       Function *getParent()       { return Parent; }
  
index b48693f0dcd7af4f875eb23f8b3c88bb0588bfa5..ad509bb2cc5c976432965f6c8270f65cddcfef0d 100644 (file)
@@ -76,9 +76,6 @@ public:
              BasicBlock *InsertBefore = 0);
   ~BasicBlock();
 
-  // Specialize setName to take care of symbol table majik
-  virtual void setName(const std::string &name);
-
   /// getParent - Return the enclosing method, or null if none
   ///
   const Function *getParent() const { return InstList.getParent(); }
index 112cb4d2abcfcf4d2c015fd53138c593758ffb6c..43a736e49c50904392638bd42d4e87f0b4c960b6 100644 (file)
@@ -26,9 +26,6 @@ protected:
 
   void destroyConstantImpl();
 public:
-  // setName - Specialize setName to handle symbol table majik.
-  virtual void setName(const std::string &name);
-
   /// Static constructor to get a '0' constant of arbitrary type...
   ///
   static Constant *getNullValue(const Type *Ty);
index 112958002c9971be6fbd62de2c39cc2a88689b13..05ac47ddd67d7652fc637c2f5fd742f48b04ef18 100644 (file)
@@ -85,9 +85,6 @@ public:
            const std::string &N = "", Module *M = 0);
   ~Function();
 
-  // Specialize setName to handle symbol table majik.
-  virtual void setName(const std::string &name);
-
   const Type *getReturnType() const;           // Return the type of the ret val
   const FunctionType *getFunctionType() const; // Return the FunctionType for me
 
index 9f73911872da8cb3490eb79ea2175a5159ac5869..1faa095d0513bc20b49c37719cbb0076912492b1 100644 (file)
@@ -51,9 +51,6 @@ public:
                 Constant *Initializer = 0, const std::string &Name = "",
                  Module *Parent = 0);
 
-  // Specialize setName to handle symbol table majik.
-  virtual void setName(const std::string &name);
-
   /// isExternal - Is this global variable lacking an initializer?  If so, the
   /// global variable is defined in some other translation unit, and is thus
   /// externally defined here.
index ae8d5caf08a9c1e0e3d57b3ca192b79225f965e2..da0767d47f4706f507fdef7e79dc6f79c5d7a2f3 100644 (file)
@@ -54,9 +54,6 @@ public:
     assert(Parent == 0 && "Instruction still linked in the program!");
   }
 
-  // Specialize setName to handle symbol table majik.
-  virtual void setName(const std::string &name);
-  
   /// mayWriteToMemory - Return true if this instruction may modify memory.
   ///
   virtual bool mayWriteToMemory() const { return false; }
index f59e9461282d6f581a69d8aba0d33f43c5fd6a8f..164c7ee811c7ee50460c2b96c2e9e0138d99550e 100644 (file)
@@ -75,9 +75,7 @@ public:
   inline bool               hasName() const { return !Name.empty(); }
   inline const std::string &getName() const { return Name; }
 
-  virtual void setName(const std::string &name) {
-    Name = name;
-  }
+  void setName(const std::string &name);
   
   /// replaceAllUsesWith - Go through the uses list for this definition and make
   /// each use point to "V" instead of "this".  After this completes, 'this's 
index 232a4e3391b5301cfe0b2179908ac7c46fe77d35..49bd8cf7be89443bc8f7d827ccc5d517f5adb8cb 100644 (file)
@@ -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 @@ void BasicBlock::setParent(Function *parent) {
     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);
 }
index 99a15eae704811488183aff713ea48b8eb6569dd..dfba3508e0e4d98f76e9db0dc0ea3330f9951644 100644 (file)
@@ -31,10 +31,6 @@ ConstantBool *ConstantBool::False = new ConstantBool(false);
 //                              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
index 7cced301e63f566f54d95a90413322baec8220ae..df8d1f904f39be21a9277d5b51fcd7c69f080d69 100644 (file)
@@ -62,15 +62,6 @@ Argument::Argument(const Type *Ty, const std::string &Name, Function *Par)
     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 @@ Function::~Function() {
   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);
index efa588bd561c3a539de2a120b3dcb5813a163487..c0264ae3c11d35414e394c222ef6bdc178bc66c2 100644 (file)
@@ -99,14 +99,6 @@ void GlobalVariable::setParent(Module *parent) {
     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);
 }
index eeba47b52e9ef6398796684df7ba6611af320fc8..4ccbd74dfdd4f3c2e37cc00849a853c098d2ca8b 100644 (file)
@@ -57,15 +57,6 @@ void Instruction::setParent(BasicBlock *P) {
   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);
 }
index b3b133f77984fa75c0afbfb625cbf7a24e2624b5..cdde96b455b7765372e12199e39dc2f312095ce0 100644 (file)
 //
 //===----------------------------------------------------------------------===//
 
+#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