eliminate ValueSymbolTable::rename, it has no advantage over using remove+insert.
authorChris Lattner <sabre@nondot.org>
Wed, 7 Feb 2007 06:13:49 +0000 (06:13 +0000)
committerChris Lattner <sabre@nondot.org>
Wed, 7 Feb 2007 06:13:49 +0000 (06:13 +0000)
Make insert/remove assert if used incorrectly instead of returning a bool.

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

include/llvm/ValueSymbolTable.h
lib/VMCore/Value.cpp
lib/VMCore/ValueSymbolTable.cpp

index 501e04f59258704246e011122ffdf0f1b16f2c11..d17cd7729c19e6177811dd615991569ae79a4701 100644 (file)
@@ -91,7 +91,7 @@ public:
 
   /// @return 1 if the name is in the symbol table, 0 otherwise
   /// @brief Determine if a name is in the symbol table
-  ValueMap::size_type count(const std::string &name) const { 
+  bool count(const std::string &name) const { 
     return vmap.count(name);
   }
 
@@ -134,18 +134,10 @@ private:
 
   /// This method removes a value from the symbol table. The name of the
   /// Value is extracted from \p Val and used to lookup the Value in the
-  /// symbol table. If the Value is not in the symbol table, this method
-  /// returns false. \p Val is not deleted, just removed from the symbol table.
-  /// @returns true if \p Val was successfully removed, false otherwise
+  /// symbol table.  \p Val is not deleted, just removed from the symbol table.
   /// @brief Remove a value from the symbol table.
-  bool remove(Value* Val);
-
-  /// Given a value with a non-empty name, remove its existing
-  /// entry from the symbol table and insert a new one for Name.  This is
-  /// equivalent to doing "remove(V), V->Name = Name, insert(V)".
-  /// @brief Rename a value in the symbol table
-  bool rename(Value *V, const std::string &Name);
-
+  void remove(Value* Val);
+  
 /// @}
 /// @name Internal Data
 /// @{
@@ -154,7 +146,6 @@ private:
   mutable uint32_t LastUnique; ///< Counter for tracking unique names
 
 /// @}
-
 };
 
 } // End llvm namespace
index 0218e5798fad37e351d81bdb8371357e6cdb42b5..f84671d4756b1d3bb281ef0c5272f2e20c623794 100644 (file)
@@ -120,7 +120,9 @@ void Value::setName(const std::string &name) {
     Name = name;
   else if (hasName()) {
     if (!name.empty()) {    // Replacing name.
-      ST->rename(this, name);
+      ST->remove(this);
+      Name = name;
+      ST->insert(this);
     } else {                // Transitioning from hasName -> noname.
       ST->remove(this);
       Name.clear();
index 358b5a23d0b888c7bfba758eb7dd1c7300971f78..41b6d7b5a3feaac39314f9942b15194a7cfcf483 100644 (file)
@@ -103,54 +103,15 @@ void ValueSymbolTable::insert(Value* V) {
 }
 
 // Remove a value
-bool ValueSymbolTable::remove(Value *V) {
+void ValueSymbolTable::remove(Value *V) {
   assert(V->hasName() && "Value doesn't have name!");
   iterator Entry = vmap.find(V->getName());
-  if (Entry == vmap.end())
-    return false;
+  assert(Entry != vmap.end() && "Entry was not in the symtab!");
 
   DEBUG(DOUT << " Removing Value: " << Entry->second->getName() << "\n");
 
   // Remove the value from the plane...
   vmap.erase(Entry);
-  return true;
-}
-
-
-// rename - Given a value with a non-empty name, remove its existing entry
-// from the symbol table and insert a new one for Name.  This is equivalent to
-// doing "remove(V), V->Name = Name, insert(V)", 
-//
-bool ValueSymbolTable::rename(Value *V, const std::string &name) {
-  assert(V && "Can't rename a null Value");
-  assert(V->hasName() && "Can't rename a nameless Value");
-  assert(!V->getName().empty() && "Can't rename an Value with null name");
-  assert(V->getName() != name && "Can't rename a Value with same name");
-  assert(!name.empty() && "Can't rename a named Value with a null name");
-
-  // Find the name
-  iterator VI = vmap.find(V->getName());
-
-  // If we didn't find it, we're done
-  if (VI == vmap.end())
-    return false;
-
-  // Remove the old entry.
-  vmap.erase(VI);
-
-  // See if we can insert the new name.
-  VI = vmap.lower_bound(name);
-
-  // Is there a naming conflict?
-  if (VI != vmap.end() && VI->first == name) {
-    V->Name = getUniqueName( name);
-    vmap.insert(make_pair(V->Name, V));
-  } else {
-    V->Name = name;
-    vmap.insert(VI, make_pair(V->Name, V));
-  }
-
-  return true;
 }
 
 // DumpVal - a std::for_each function for dumping a value