[llvm-commits] [llvm] r76894 - in /llvm/trunk: include/llvm/ValueSymbolTable.h lib/Linker/LinkModules.cpp lib/VMCore/Module.cpp lib/VMCore/ValueSymbolTable.cpp

Daniel Dunbar daniel at zuster.org
Thu Jul 23 11:52:22 PDT 2009


Author: ddunbar
Date: Thu Jul 23 13:52:12 2009
New Revision: 76894

URL: http://llvm.org/viewvc/llvm-project?rev=76894&view=rev
Log:
Switch ValueSymbolTable to StringRef based API.

Modified:
    llvm/trunk/include/llvm/ValueSymbolTable.h
    llvm/trunk/lib/Linker/LinkModules.cpp
    llvm/trunk/lib/VMCore/Module.cpp
    llvm/trunk/lib/VMCore/ValueSymbolTable.cpp

Modified: llvm/trunk/include/llvm/ValueSymbolTable.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ValueSymbolTable.h?rev=76894&r1=76893&r2=76894&view=diff

==============================================================================
--- llvm/trunk/include/llvm/ValueSymbolTable.h (original)
+++ llvm/trunk/include/llvm/ValueSymbolTable.h Thu Jul 23 13:52:12 2009
@@ -24,6 +24,7 @@
   class BasicBlock;
   class Function;
   class Module;
+  class StringRef;
   
 /// 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
@@ -62,12 +63,11 @@
 /// @{
 public:
 
-  /// This method finds the value with the given \p name in the
+  /// This method finds the value with the given \p Name in the
   /// the symbol table. 
-  /// @returns the value associated with the \p name
+  /// @returns the value associated with the \p Name
   /// @brief Lookup a named Value.
-  Value *lookup(const std::string &name) const;
-  Value *lookup(const char *NameBegin, const char *NameEnd) const;
+  Value *lookup(const StringRef &Name) const { return vmap.lookup(Name); }
 
   /// @returns true iff the symbol table is empty
   /// @brief Determine if the symbol table is empty
@@ -110,7 +110,7 @@
   /// 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);
+  ValueName *createValueName(const StringRef &Name, 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

Modified: llvm/trunk/lib/Linker/LinkModules.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Linker/LinkModules.cpp?rev=76894&r1=76893&r2=76894&view=diff

==============================================================================
--- llvm/trunk/lib/Linker/LinkModules.cpp (original)
+++ llvm/trunk/lib/Linker/LinkModules.cpp Thu Jul 23 13:52:12 2009
@@ -548,8 +548,7 @@
     // Check to see if may have to link the global with the global, alias or
     // function.
     if (SGV->hasName() && !SGV->hasLocalLinkage())
-      DGV = cast_or_null<GlobalValue>(DestSymTab.lookup(SGV->getNameStart(),
-                                                        SGV->getNameEnd()));
+      DGV = cast_or_null<GlobalValue>(DestSymTab.lookup(SGV->getNameRef()));
 
     // If we found a global with the same name in the dest module, but it has
     // internal linkage, we are really not doing any linkage here.
@@ -942,8 +941,7 @@
     // Check to see if may have to link the function with the global, alias or
     // function.
     if (SF->hasName() && !SF->hasLocalLinkage())
-      DGV = cast_or_null<GlobalValue>(DestSymTab.lookup(SF->getNameStart(),
-                                                        SF->getNameEnd()));
+      DGV = cast_or_null<GlobalValue>(DestSymTab.lookup(SF->getNameRef()));
 
     // If we found a global with the same name in the dest module, but it has
     // internal linkage, we are really not doing any linkage here.

Modified: llvm/trunk/lib/VMCore/Module.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/Module.cpp?rev=76894&r1=76893&r2=76894&view=diff

==============================================================================
--- llvm/trunk/lib/VMCore/Module.cpp (original)
+++ llvm/trunk/lib/VMCore/Module.cpp Thu Jul 23 13:52:12 2009
@@ -118,7 +118,7 @@
 }
 
 GlobalValue *Module::getNamedValue(const char *Name) const {
-  llvm::Value *V = getValueSymbolTable().lookup(Name, Name+strlen(Name));
+  llvm::Value *V = getValueSymbolTable().lookup(Name);
   return cast_or_null<GlobalValue>(V);
 }
 

Modified: llvm/trunk/lib/VMCore/ValueSymbolTable.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/ValueSymbolTable.cpp?rev=76894&r1=76893&r2=76894&view=diff

==============================================================================
--- llvm/trunk/lib/VMCore/ValueSymbolTable.cpp (original)
+++ llvm/trunk/lib/VMCore/ValueSymbolTable.cpp Thu Jul 23 13:52:12 2009
@@ -30,24 +30,6 @@
 #endif
 }
 
-// lookup a value - Returns null on failure...
-//
-Value *ValueSymbolTable::lookup(const std::string &Name) const {
-  const_iterator VI = vmap.find(Name);
-  if (VI != vmap.end())                   // We found the symbol
-    return VI->getValue();
-  return 0;
-}
-
-Value *ValueSymbolTable::lookup(const char *NameBegin,
-                                const char *NameEnd) const {
-  // FIXME: ValueSymbolTable should move to a StringRef based API.
-  const_iterator VI = vmap.find(StringRef(NameBegin, NameEnd - NameBegin));
-  if (VI != vmap.end())                   // We found the symbol
-    return VI->getValue();
-  return 0;
-}
-
 // Insert a value into the symbol table with the specified name...
 //
 void ValueSymbolTable::reinsertValue(Value* V) {
@@ -93,10 +75,9 @@
 /// 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 *ValueSymbolTable::createValueName(const char *NameStart,
-                                             unsigned NameLen, Value *V) {
+ValueName *ValueSymbolTable::createValueName(const StringRef &Name, Value *V) {
   // In the common case, the name is not already in the symbol table.
-  ValueName &Entry = vmap.GetOrCreateValue(StringRef(NameStart, NameLen));
+  ValueName &Entry = vmap.GetOrCreateValue(Name);
   if (Entry.getValue() == 0) {
     Entry.setValue(V);
     //DEBUG(DOUT << " Inserted value: " << Entry.getKeyData() << ": "
@@ -105,11 +86,11 @@
   }
   
   // Otherwise, there is a naming conflict.  Rename this value.
-  SmallString<128> UniqueName(NameStart, NameStart+NameLen);
+  SmallString<128> UniqueName(Name.begin(), Name.end());
   
   while (1) {
     // Trim any suffix off.
-    UniqueName.resize(NameLen);
+    UniqueName.resize(Name.size());
     UniqueName.append_uint_32(++LastUnique);
     
     // Try insert the vmap entry with this suffix.





More information about the llvm-commits mailing list