For PR1297:
[oota-llvm.git] / include / llvm / ValueSymbolTable.h
index df3fe181971bcab03c5ff3484c5cb43773d9802a..f5dcae0877fe49154cc68a32b780918210145a71 100644 (file)
 #define LLVM_VALUE_SYMBOL_TABLE_H
 
 #include "llvm/Value.h"
-#include <map>
+#include "llvm/ADT/StringMap.h"
 
 namespace llvm {
-
+  template<typename ValueSubClass, typename ItemParentClass,
+           typename SymTabClass, typename SubClass>
+        class SymbolTableListTraits;
+  template<typename NodeTy> struct ilist_traits;
+  class BasicBlock;
+  class Function;
+  class Module;
+  
 /// This class provides a symbol table of name/value pairs. It is essentially
 /// a std::map<std::string,Value*> but has a controlled interface provided by
 /// LLVM as well as ensuring uniqueness of names.
 ///
 class ValueSymbolTable {
-
+  friend class Value;
+  friend class SymbolTableListTraits<Argument, Function, Function,
+                                     ilist_traits<Argument> >;
+  friend class SymbolTableListTraits<BasicBlock, Function, Function,
+                                     ilist_traits<BasicBlock> >;
+  friend class SymbolTableListTraits<Instruction, BasicBlock, Function,
+                                     ilist_traits<Instruction> >;
+  friend class SymbolTableListTraits<Function, Module, Module, 
+                                     ilist_traits<Function> >;
+  friend class SymbolTableListTraits<GlobalVariable, Module, Module, 
+                                     ilist_traits<GlobalVariable> >;
 /// @name Types
 /// @{
 public:
-
   /// @brief A mapping of names to values.
-  typedef std::map<const std::string, Value *> ValueMap;
+  typedef StringMap<Value*> ValueMap;
 
   /// @brief An iterator over a ValueMap.
   typedef ValueMap::iterator iterator;
@@ -45,7 +61,7 @@ public:
 /// @{
 public:
 
-  ValueSymbolTable() : LastUnique(0) {}
+  ValueSymbolTable() : vmap(16), LastUnique(0) {}
   ~ValueSymbolTable();
 
 /// @}
@@ -81,7 +97,6 @@ public:
 /// @name Iteration
 /// @{
 public:
-
   /// @brief Get an iterator that from the beginning of the symbol table.
   inline iterator begin() { return vmap.begin(); }
 
@@ -93,44 +108,35 @@ public:
 
   /// @brief Get a const_iterator to the end of the symbol table.
   inline const_iterator end() const { return vmap.end(); }
-
+  
 /// @}
 /// @name Mutators
 /// @{
-public:
-
-  /// This method will strip the symbol table of its names.
-  /// @brief Strip the symbol table.
-  bool strip();
-
+private:
   /// This method adds the provided value \p N to the symbol table.  The Value
   /// must have a name which is used to place the value in the symbol table. 
+  /// If the inserted name conflicts, this renames the value.
   /// @brief Add a named value to the symbol table
-  void insert(Value *Val);
-
-  /// 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.
-  /// @returns true if \p Val was successfully erased, false otherwise
-  /// @brief Remove a value from the symbol table.
-  bool erase(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 reinsertValue(Value *V);
+    
+  /// createValueName - This method attempts to create a value name and insert
+  /// it into the symbol table with the specified name.  If it conflicts, it
+  /// auto-renames the name and returns that instead.
+  ValueName *createValueName(const char *NameStart, unsigned NameLen, Value *V);
+  
+  /// This method removes a value from the symbol table.  It leaves the
+  /// ValueName attached to the value, but it is no longer inserted in the
+  /// symtab.
+  void removeValueName(ValueName *V);
+  
 /// @}
 /// @name Internal Data
 /// @{
 private:
   ValueMap vmap;                    ///< The map that holds the symbol table.
-  mutable unsigned long LastUnique; ///< Counter for tracking unique names
+  mutable uint32_t LastUnique; ///< Counter for tracking unique names
 
 /// @}
-
 };
 
 } // End llvm namespace