summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2008-06-27 21:09:10 +0000
committerChris Lattner <sabre@nondot.org>2008-06-27 21:09:10 +0000
commite43649fa621e2b6b437c67b00c88ae384ba20c2c (patch)
treeb745389029855f1856088315c9a4776dc5c45bca
parentd9f84134027d026eaaf4926195a2e6c958bb359d (diff)
downloadbcm5719-llvm-e43649fa621e2b6b437c67b00c88ae384ba20c2c.tar.gz
bcm5719-llvm-e43649fa621e2b6b437c67b00c88ae384ba20c2c.zip
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! llvm-svn: 52834
-rw-r--r--llvm/include/llvm/Module.h1
-rw-r--r--llvm/include/llvm/ValueSymbolTable.h1
-rw-r--r--llvm/lib/VMCore/Module.cpp5
-rw-r--r--llvm/lib/VMCore/ValueSymbolTable.cpp8
4 files changed, 15 insertions, 0 deletions
diff --git a/llvm/include/llvm/Module.h b/llvm/include/llvm/Module.h
index bce671ddb29..56207a0af27 100644
--- a/llvm/include/llvm/Module.h
+++ b/llvm/include/llvm/Module.h
@@ -209,6 +209,7 @@ public:
/// 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
diff --git a/llvm/include/llvm/ValueSymbolTable.h b/llvm/include/llvm/ValueSymbolTable.h
index 54522df6a15..6f79f6f393a 100644
--- a/llvm/include/llvm/ValueSymbolTable.h
+++ b/llvm/include/llvm/ValueSymbolTable.h
@@ -67,6 +67,7 @@ public:
/// @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
diff --git a/llvm/lib/VMCore/Module.cpp b/llvm/lib/VMCore/Module.cpp
index 429cf1a4c69..893a5fdcb00 100644
--- a/llvm/lib/VMCore/Module.cpp
+++ b/llvm/lib/VMCore/Module.cpp
@@ -201,6 +201,11 @@ Function *Module::getFunction(const std::string &Name) const {
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.
//
diff --git a/llvm/lib/VMCore/ValueSymbolTable.cpp b/llvm/lib/VMCore/ValueSymbolTable.cpp
index fb7c0d8509b..f527863e1b5 100644
--- a/llvm/lib/VMCore/ValueSymbolTable.cpp
+++ b/llvm/lib/VMCore/ValueSymbolTable.cpp
@@ -54,6 +54,14 @@ Value *ValueSymbolTable::lookup(const std::string &Name) const {
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) {
OpenPOWER on IntegriCloud