[llvm-commits] CVS: llvm/lib/VMCore/BasicBlock.cpp Constants.cpp Function.cpp Globals.cpp Instruction.cpp Value.cpp

Chris Lattner lattner at cs.uiuc.edu
Sat Mar 5 11:52:03 PST 2005



Changes in directory llvm/lib/VMCore:

BasicBlock.cpp updated: 1.58 -> 1.59
Constants.cpp updated: 1.122 -> 1.123
Function.cpp updated: 1.89 -> 1.90
Globals.cpp updated: 1.9 -> 1.10
Instruction.cpp updated: 1.43 -> 1.44
Value.cpp updated: 1.54 -> 1.55
---
Log message:

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



---
Diffs of the changes:  (+28 -50)

 BasicBlock.cpp  |    9 ---------
 Constants.cpp   |    4 ----
 Function.cpp    |   17 -----------------
 Globals.cpp     |    8 --------
 Instruction.cpp |    9 ---------
 Value.cpp       |   31 ++++++++++++++++++++++++++++---
 6 files changed, 28 insertions(+), 50 deletions(-)


Index: llvm/lib/VMCore/BasicBlock.cpp
diff -u llvm/lib/VMCore/BasicBlock.cpp:1.58 llvm/lib/VMCore/BasicBlock.cpp:1.59
--- llvm/lib/VMCore/BasicBlock.cpp:1.58	Sat Mar  5 13:01:49 2005
+++ llvm/lib/VMCore/BasicBlock.cpp	Sat Mar  5 13:51:49 2005
@@ -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);
 }


Index: llvm/lib/VMCore/Constants.cpp
diff -u llvm/lib/VMCore/Constants.cpp:1.122 llvm/lib/VMCore/Constants.cpp:1.123
--- llvm/lib/VMCore/Constants.cpp:1.122	Sat Mar  5 13:01:59 2005
+++ llvm/lib/VMCore/Constants.cpp	Sat Mar  5 13:51:50 2005
@@ -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


Index: llvm/lib/VMCore/Function.cpp
diff -u llvm/lib/VMCore/Function.cpp:1.89 llvm/lib/VMCore/Function.cpp:1.90
--- llvm/lib/VMCore/Function.cpp:1.89	Sat Mar  5 13:01:49 2005
+++ llvm/lib/VMCore/Function.cpp	Sat Mar  5 13:51:50 2005
@@ -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);


Index: llvm/lib/VMCore/Globals.cpp
diff -u llvm/lib/VMCore/Globals.cpp:1.9 llvm/lib/VMCore/Globals.cpp:1.10
--- llvm/lib/VMCore/Globals.cpp:1.9	Sat Mar  5 13:01:49 2005
+++ llvm/lib/VMCore/Globals.cpp	Sat Mar  5 13:51:50 2005
@@ -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);
 }


Index: llvm/lib/VMCore/Instruction.cpp
diff -u llvm/lib/VMCore/Instruction.cpp:1.43 llvm/lib/VMCore/Instruction.cpp:1.44
--- llvm/lib/VMCore/Instruction.cpp:1.43	Sat Mar  5 13:01:49 2005
+++ llvm/lib/VMCore/Instruction.cpp	Sat Mar  5 13:51:50 2005
@@ -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);
 }


Index: llvm/lib/VMCore/Value.cpp
diff -u llvm/lib/VMCore/Value.cpp:1.54 llvm/lib/VMCore/Value.cpp:1.55
--- llvm/lib/VMCore/Value.cpp:1.54	Wed Feb 23 10:51:11 2005
+++ llvm/lib/VMCore/Value.cpp	Sat Mar  5 13:51:50 2005
@@ -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 @@
 }
 
 
+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






More information about the llvm-commits mailing list