summaryrefslogtreecommitdiffstats
path: root/llvm/lib/VMCore/Module.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2002-03-29 03:44:18 +0000
committerChris Lattner <sabre@nondot.org>2002-03-29 03:44:18 +0000
commita483b0616a2605863f371cb63f5d4ffd03ef0460 (patch)
tree74016e966e9cbcffe3551873575da3221b08348c /llvm/lib/VMCore/Module.cpp
parentc46dcca2200772cb7f451bf73d80a8bfdbc834dc (diff)
downloadbcm5719-llvm-a483b0616a2605863f371cb63f5d4ffd03ef0460.tar.gz
bcm5719-llvm-a483b0616a2605863f371cb63f5d4ffd03ef0460.zip
Implement new getFunction and getOrInsertFunction methods
llvm-svn: 2033
Diffstat (limited to 'llvm/lib/VMCore/Module.cpp')
-rw-r--r--llvm/lib/VMCore/Module.cpp31
1 files changed, 31 insertions, 0 deletions
diff --git a/llvm/lib/VMCore/Module.cpp b/llvm/lib/VMCore/Module.cpp
index 144c6f35578..c0767cd7d19 100644
--- a/llvm/lib/VMCore/Module.cpp
+++ b/llvm/lib/VMCore/Module.cpp
@@ -11,6 +11,7 @@
#include "llvm/ValueHolderImpl.h"
#include "llvm/Type.h"
#include "llvm/ConstantVals.h"
+#include "llvm/DerivedTypes.h"
#include "Support/STLExtras.h"
#include <map>
@@ -40,6 +41,36 @@ Module::~Module() {
FunctionList.setParent(0);
}
+// getOrInsertFunction - Look up the specified function in the module symbol
+// table. If it does not exist, add a prototype for the function and return
+// it. This is nice because it allows most passes to get away with not handling
+// the symbol table directly for this common task.
+//
+Function *Module::getOrInsertFunction(const std::string &Name,
+ const FunctionType *Ty) {
+ SymbolTable *SymTab = getSymbolTableSure();
+
+ // See if we have a definitions for the specified function already...
+ if (Value *V = SymTab->lookup(PointerType::get(Ty), Name)) {
+ return cast<Function>(V); // Yup, got it
+ } else { // Nope, add one
+ Function *New = new Function(Ty, false, Name);
+ FunctionList.push_back(New);
+ return New; // Return the new prototype...
+ }
+}
+
+// getFunction - Look up the specified function in the module symbol table.
+// If it does not exist, return null.
+//
+Function *Module::getFunction(const std::string &Name, const FunctionType *Ty) {
+ SymbolTable *SymTab = getSymbolTable();
+ if (SymTab == 0) return 0; // No symtab, no symbols...
+
+ return cast_or_null<Function>(SymTab->lookup(PointerType::get(Ty), Name));
+}
+
+
// dropAllReferences() - This function causes all the subinstructions to "let
// go" of all references that they are maintaining. This allows one to
OpenPOWER on IntegriCloud