[Mlir-commits] [mlir] [mlir] load dialects for non-namespaced attrs (PR #94838)

Jeremy Kun llvmlistbot at llvm.org
Thu Jun 20 14:13:52 PDT 2024


j2kun wrote:

As an intermediate workaround, what about providing the MLIRContext as an optional parameter to `mlirTranslateMain`?

```diff
diff --git a/mlir/lib/Tools/mlir-translate/MlirTranslateMain.cpp b/mlir/lib/Tools/mlir-translate/MlirTranslateMain.cpp
index bd9928950ec..92313d679f8 100644
--- a/mlir/lib/Tools/mlir-translate/MlirTranslateMain.cpp
+++ b/mlir/lib/Tools/mlir-translate/MlirTranslateMain.cpp
@@ -47,7 +47,8 @@ public:
 //===----------------------------------------------------------------------===//

 LogicalResult mlir::mlirTranslateMain(int argc, char **argv,
-                                      llvm::StringRef toolName) {
+                                      llvm::StringRef toolName,
+                                      MLIRContext *userProvidedContext) {

   static llvm::cl::opt<std::string> inputFilename(
       llvm::cl::Positional, llvm::cl::desc("<input file>"),
@@ -148,9 +149,12 @@ LogicalResult mlir::mlirTranslateMain(int argc, char **argv,
       TimingScope translationTiming =
           timing.nest(translationRequested->getDescription());

-      MLIRContext context;
-      context.allowUnregisteredDialects(allowUnregisteredDialects);
-      context.printOpOnDiagnostic(!verifyDiagnostics);
+      MLIRContext defaultContext;
+      MLIRContext *context = &defaultContext;
+      if (userProvidedContext)
+        context = userProvidedContext;
+      context->allowUnregisteredDialects(allowUnregisteredDialects);
+      context->printOpOnDiagnostic(!verifyDiagnostics);
       auto sourceMgr = std::make_shared<llvm::SourceMgr>();
       sourceMgr->AddNewSourceBuffer(std::move(ownedBuffer), SMLoc());
```

https://github.com/llvm/llvm-project/pull/94838


More information about the Mlir-commits mailing list