Implement a module-level symbol table for functions, enforcing uniqueness of
names across the module and auto-renaming conflicts. Have the parser reject
malformed modules that have redefinitions.
PiperOrigin-RevId: 209227560
diff --git a/lib/IR/Module.cpp b/lib/IR/Module.cpp
index 99e5e32..5a33d26 100644
--- a/lib/IR/Module.cpp
+++ b/lib/IR/Module.cpp
@@ -19,3 +19,16 @@
using namespace mlir;
Module::Module(MLIRContext *context) : context(context) {}
+
+/// Look up a function with the specified name, returning null if no such
+/// name exists.
+Function *Module::getNamedFunction(StringRef name) {
+ return getNamedFunction(Identifier::get(name, context));
+}
+
+/// Look up a function with the specified name, returning null if no such
+/// name exists.
+Function *Module::getNamedFunction(Identifier name) {
+ auto it = symbolTable.find(name);
+ return it != symbolTable.end() ? it->second : nullptr;
+}