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

Chris Lattner sabre at nondot.org
Fri Jun 27 14:09:11 PDT 2008


Author: lattner
Date: Fri Jun 27 16:09:10 2008
New Revision: 52834

URL: http://llvm.org/viewvc/llvm-project?rev=52834&view=rev
Log:
Add a new version of Module::getFunction that takes a const char* instead
of a std::string.  This avoids copying the string to the heap in common
cases.  Patch by Pratik Solanki!

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

Modified: llvm/trunk/include/llvm/Module.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Module.h?rev=52834&r1=52833&r2=52834&view=diff

==============================================================================
--- llvm/trunk/include/llvm/Module.h (original)
+++ llvm/trunk/include/llvm/Module.h Fri Jun 27 16:09:10 2008
@@ -209,6 +209,7 @@
   /// getFunction - Look up the specified function in the module symbol table.
   /// If it does not exist, return null.
   Function *getFunction(const std::string &Name) const;
+  Function *getFunction(const char *Name) const;
 
 /// @}
 /// @name Global Variable Accessors

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

==============================================================================
--- llvm/trunk/include/llvm/ValueSymbolTable.h (original)
+++ llvm/trunk/include/llvm/ValueSymbolTable.h Fri Jun 27 16:09:10 2008
@@ -67,6 +67,7 @@
   /// @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;
 
   /// @returns true iff the symbol table is empty
   /// @brief Determine if the symbol table is empty

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

==============================================================================
--- llvm/trunk/lib/VMCore/Module.cpp (original)
+++ llvm/trunk/lib/VMCore/Module.cpp Fri Jun 27 16:09:10 2008
@@ -201,6 +201,11 @@
   return dyn_cast_or_null<Function>(SymTab.lookup(Name));
 }
 
+Function *Module::getFunction(const char *Name) const {
+  const ValueSymbolTable &SymTab = getValueSymbolTable();
+  return dyn_cast_or_null<Function>(SymTab.lookup(Name, Name+strlen(Name)));
+}
+
 //===----------------------------------------------------------------------===//
 // Methods for easy access to the global variables in the module.
 //

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

==============================================================================
--- llvm/trunk/lib/VMCore/ValueSymbolTable.cpp (original)
+++ llvm/trunk/lib/VMCore/ValueSymbolTable.cpp Fri Jun 27 16:09:10 2008
@@ -54,6 +54,14 @@
   return 0;
 }
 
+Value *ValueSymbolTable::lookup(const char *NameBegin,
+                                const char *NameEnd) const {
+  const_iterator VI = vmap.find(NameBegin, NameEnd);
+  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) {





More information about the llvm-commits mailing list