[llvm-commits] CVS: llvm/lib/VMCore/Value.cpp

Chris Lattner sabre at nondot.org
Sat Feb 10 16:37:48 PST 2007



Changes in directory llvm/lib/VMCore:

Value.cpp updated: 1.62 -> 1.63
---
Log message:

add a helper method: Value::takeName


---
Diffs of the changes:  (+26 -12)

 Value.cpp |   38 ++++++++++++++++++++++++++------------
 1 files changed, 26 insertions(+), 12 deletions(-)


Index: llvm/lib/VMCore/Value.cpp
diff -u llvm/lib/VMCore/Value.cpp:1.62 llvm/lib/VMCore/Value.cpp:1.63
--- llvm/lib/VMCore/Value.cpp:1.62	Wed Feb  7 00:13:49 2007
+++ llvm/lib/VMCore/Value.cpp	Sat Feb 10 18:37:27 2007
@@ -92,29 +92,34 @@
   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 @@
   }
 }
 
+/// 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






More information about the llvm-commits mailing list