[Mlir-commits] [mlir] 968280b - [mlir-translate] Teach these tools about --allow-unregistered-dialect
Chris Lattner
llvmlistbot at llvm.org
Thu Feb 3 09:00:44 PST 2022
Author: Chris Lattner
Date: 2022-02-03T09:00:38-08:00
New Revision: 968280bc401292f1070f41eb1e03e94c331923f9
URL: https://github.com/llvm/llvm-project/commit/968280bc401292f1070f41eb1e03e94c331923f9
DIFF: https://github.com/llvm/llvm-project/commit/968280bc401292f1070f41eb1e03e94c331923f9.diff
LOG: [mlir-translate] Teach these tools about --allow-unregistered-dialect
Some translations do work with unregistered dialects, this allows one
to write testcases against them. It works the same way as it does for
mlir-opt.
Differential Revision: https://reviews.llvm.org/D118872
Added:
mlir/test/mlir-translate/unregistered-dialects.mlir
Modified:
mlir/lib/Translation/Translation.cpp
Removed:
################################################################################
diff --git a/mlir/lib/Translation/Translation.cpp b/mlir/lib/Translation/Translation.cpp
index 5a8812ab49b21..6da62f68f55a0 100644
--- a/mlir/lib/Translation/Translation.cpp
+++ b/mlir/lib/Translation/Translation.cpp
@@ -140,6 +140,11 @@ LogicalResult mlir::mlirTranslateMain(int argc, char **argv,
"o", llvm::cl::desc("Output filename"), llvm::cl::value_desc("filename"),
llvm::cl::init("-"));
+ static llvm::cl::opt<bool> allowUnregisteredDialects(
+ "allow-unregistered-dialect",
+ llvm::cl::desc("Allow operation with no registered dialects"),
+ llvm::cl::init(false));
+
static llvm::cl::opt<bool> splitInputFile(
"split-input-file",
llvm::cl::desc("Split the input file into pieces and "
@@ -179,6 +184,7 @@ LogicalResult mlir::mlirTranslateMain(int argc, char **argv,
auto processBuffer = [&](std::unique_ptr<llvm::MemoryBuffer> ownedBuffer,
raw_ostream &os) {
MLIRContext context;
+ context.allowUnregisteredDialects(allowUnregisteredDialects);
context.printOpOnDiagnostic(!verifyDiagnostics);
llvm::SourceMgr sourceMgr;
sourceMgr.AddNewSourceBuffer(std::move(ownedBuffer), SMLoc());
diff --git a/mlir/test/mlir-translate/unregistered-dialects.mlir b/mlir/test/mlir-translate/unregistered-dialects.mlir
new file mode 100644
index 0000000000000..0a7330b11c02b
--- /dev/null
+++ b/mlir/test/mlir-translate/unregistered-dialects.mlir
@@ -0,0 +1,13 @@
+// RUN: not mlir-translate %s --allow-unregistered-dialect --mlir-to-llvmir -verify-diagnostics 2>&1 | FileCheck --check-prefix=UNREGOK %s
+// RUN: not mlir-translate %s --mlir-to-llvmir -verify-diagnostics 2>&1 | FileCheck --check-prefix=REGONLY %s
+
+
+// If the parser allows unregistered operations, then the translation fails,
+// otherwise the parse fails.
+
+// UNREGOK: cannot be converted to LLVM IR
+// REGONLY: operation being parsed with an unregistered dialect
+
+func @trivial() {
+ "simple.terminator"() : () -> ()
+}
More information about the Mlir-commits
mailing list