[llvm-commits] CVS: llvm/include/llvm/Constant.h GlobalValue.h User.h Value.h ValueSymbolTable.h

Chris Lattner sabre at nondot.org
Sun Feb 11 21:18:29 PST 2007



Changes in directory llvm/include/llvm:

Constant.h updated: 1.33 -> 1.34
GlobalValue.h updated: 1.32 -> 1.33
User.h updated: 1.36 -> 1.37
Value.h updated: 1.92 -> 1.93
ValueSymbolTable.h updated: 1.7 -> 1.8
---
Log message:

Switch ValueSymbolTable to use StringMap<Value*> instead of std::map<std::string, Value*>
as its main datastructure.  There are many improvements yet to be made, but
this speeds up opt --std-compile-opts on 447.dealII by 7.3%.



---
Diffs of the changes:  (+30 -31)

 Constant.h         |    5 ++---
 GlobalValue.h      |    6 ++++--
 User.h             |    6 ++----
 Value.h            |   11 +++++++----
 ValueSymbolTable.h |   33 +++++++++++++++------------------
 5 files changed, 30 insertions(+), 31 deletions(-)


Index: llvm/include/llvm/Constant.h
diff -u llvm/include/llvm/Constant.h:1.33 llvm/include/llvm/Constant.h:1.34
--- llvm/include/llvm/Constant.h:1.33	Sat Dec 16 23:15:12 2006
+++ llvm/include/llvm/Constant.h	Sun Feb 11 23:18:08 2007
@@ -39,9 +39,8 @@
   void operator=(const Constant &);     // Do not implement
   Constant(const Constant &);           // Do not implement
 protected:
-  Constant(const Type *Ty, ValueTy vty, Use *Ops, unsigned NumOps,
-           const std::string& Name = "")
-    : User(Ty, vty, Ops, NumOps, Name) {}
+  Constant(const Type *Ty, ValueTy vty, Use *Ops, unsigned NumOps)
+    : User(Ty, vty, Ops, NumOps) {}
 
   void destroyConstantImpl();
 public:


Index: llvm/include/llvm/GlobalValue.h
diff -u llvm/include/llvm/GlobalValue.h:1.32 llvm/include/llvm/GlobalValue.h:1.33
--- llvm/include/llvm/GlobalValue.h:1.32	Tue Jan 30 14:08:38 2007
+++ llvm/include/llvm/GlobalValue.h	Sun Feb 11 23:18:08 2007
@@ -49,8 +49,10 @@
 protected:
   GlobalValue(const Type *Ty, ValueTy vty, Use *Ops, unsigned NumOps,
               LinkageTypes linkage, const std::string &name = "")
-    : Constant(Ty, vty, Ops, NumOps, name), Parent(0),
-      Linkage(linkage), Visibility(DefaultVisibility), Alignment(0) { }
+    : Constant(Ty, vty, Ops, NumOps), Parent(0),
+      Linkage(linkage), Visibility(DefaultVisibility), Alignment(0) {
+    if (!name.empty()) setName(name);
+  }
 
   Module *Parent;
   LinkageTypes Linkage;   // The linkage of this global


Index: llvm/include/llvm/User.h
diff -u llvm/include/llvm/User.h:1.36 llvm/include/llvm/User.h:1.37
--- llvm/include/llvm/User.h:1.36	Mon May  8 00:59:36 2006
+++ llvm/include/llvm/User.h	Sun Feb 11 23:18:08 2007
@@ -20,7 +20,6 @@
 #define LLVM_USER_H
 
 #include "llvm/Value.h"
-#include <vector>
 
 namespace llvm {
 
@@ -39,9 +38,8 @@
   unsigned NumOperands;
 
 public:
-  User(const Type *Ty, unsigned vty, Use *OpList, unsigned NumOps,
-       const std::string &name = "")
-    : Value(Ty, vty, name), OperandList(OpList), NumOperands(NumOps) {}
+  User(const Type *Ty, unsigned vty, Use *OpList, unsigned NumOps)
+    : Value(Ty, vty), OperandList(OpList), NumOperands(NumOps) {}
 
   Value *getOperand(unsigned i) const {
     assert(i < NumOperands && "getOperand() out of range!");


Index: llvm/include/llvm/Value.h
diff -u llvm/include/llvm/Value.h:1.92 llvm/include/llvm/Value.h:1.93
--- llvm/include/llvm/Value.h:1.92	Sat Feb 10 18:37:27 2007
+++ llvm/include/llvm/Value.h	Sun Feb 11 23:18:08 2007
@@ -33,6 +33,8 @@
 class InlineAsm;
 class ValueSymbolTable;
 class TypeSymbolTable;
+template<typename ValueTy> class StringMapEntry;
+typedef StringMapEntry<Value*> ValueName;
 
 //===----------------------------------------------------------------------===//
 //                                 Value Class
@@ -61,13 +63,13 @@
 
   friend class ValueSymbolTable; // Allow ValueSymbolTable to directly mod Name.
   friend class SymbolTable;      // Allow SymbolTable to directly poke Name.
-  std::string Name;
+  ValueName *Name;
 
   void operator=(const Value &);     // Do not implement
   Value(const Value &);              // Do not implement
 
 public:
-  Value(const Type *Ty, unsigned scid, const std::string &name = "");
+  Value(const Type *Ty, unsigned scid);
   virtual ~Value();
 
   /// dump - Support for debugging, callable in GDB: V->dump()
@@ -84,8 +86,9 @@
   inline const Type *getType() const { return Ty; }
 
   // All values can potentially be named...
-  inline bool               hasName() const { return !Name.empty(); }
-  inline const std::string &getName() const { return Name; }
+  inline bool hasName() const { return Name != 0; }
+  std::string getName() const;
+  ValueName *getValueName() const { return Name; }
 
   void setName(const std::string &name);
   


Index: llvm/include/llvm/ValueSymbolTable.h
diff -u llvm/include/llvm/ValueSymbolTable.h:1.7 llvm/include/llvm/ValueSymbolTable.h:1.8
--- llvm/include/llvm/ValueSymbolTable.h:1.7	Wed Feb  7 00:22:45 2007
+++ llvm/include/llvm/ValueSymbolTable.h	Sun Feb 11 23:18:08 2007
@@ -17,7 +17,7 @@
 #define LLVM_VALUE_SYMBOL_TABLE_H
 
 #include "llvm/Value.h"
-#include <map>
+#include "llvm/ADT/StringMap.h"
 
 namespace llvm {
   template<typename ValueSubClass, typename ItemParentClass,
@@ -47,9 +47,8 @@
 /// @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;
@@ -89,12 +88,6 @@
   /// @brief Get a name unique to this symbol table
   std::string getUniqueName(const std::string &BaseName) const;
 
-  /// @return 1 if the name is in the symbol table, 0 otherwise
-  /// @brief Determine if a name is in the symbol table
-  bool count(const std::string &name) const { 
-    return vmap.count(name);
-  }
-
   /// This function can be used from the debugger to display the
   /// content of the symbol table while debugging.
   /// @brief Print out symbol table on stderr
@@ -104,7 +97,6 @@
 /// @name Iteration
 /// @{
 public:
-
   /// @brief Get an iterator that from the beginning of the symbol table.
   inline iterator begin() { return vmap.begin(); }
 
@@ -116,21 +108,26 @@
 
   /// @brief Get a const_iterator to the end of the symbol table.
   inline const_iterator end() const { return vmap.end(); }
-
+  
 /// @}
 /// @name Mutators
 /// @{
 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.  \p Val is not deleted, just removed from the symbol table.
-  /// @brief Remove a value from the symbol table.
-  void remove(Value* Val);
+  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






More information about the llvm-commits mailing list