diff --git a/mlir/examples/standalone/standalone-opt/standalone-opt.cpp b/mlir/examples/standalone/standalone-opt/standalone-opt.cpp --- a/mlir/examples/standalone/standalone-opt/standalone-opt.cpp +++ b/mlir/examples/standalone/standalone-opt/standalone-opt.cpp @@ -46,6 +46,11 @@ llvm::cl::desc("Run the verifier after each transformation pass"), llvm::cl::init(true)); +static llvm::cl::opt allowUnregisteredDialects( + "allow-unregistered-dialect", + llvm::cl::desc("Allow operation with no registered dialects"), + llvm::cl::init(false)); + static llvm::cl::opt showDialects("show-dialects", llvm::cl::desc("Print the list of registered dialects"), @@ -91,7 +96,12 @@ exit(1); } - return failed(mlir::MlirOptMain(output->os(), std::move(file), passPipeline, - splitInputFile, verifyDiagnostics, - verifyPasses)); + if (failed(MlirOptMain(output->os(), std::move(file), passPipeline, + splitInputFile, verifyDiagnostics, verifyPasses, + allowUnregisteredDialects))) { + return 1; + } + // Keep the output file if the invocation of MlirOptMain was successful. + output->keep(); + return 0; } diff --git a/mlir/test/mlir-opt/outputfile.mlir b/mlir/test/mlir-opt/outputfile.mlir new file mode 100644 --- /dev/null +++ b/mlir/test/mlir-opt/outputfile.mlir @@ -0,0 +1,2 @@ +// RUN: mlir-opt %s -o %t +// RUN: test -f %t diff --git a/mlir/tools/mlir-opt/mlir-opt.cpp b/mlir/tools/mlir-opt/mlir-opt.cpp --- a/mlir/tools/mlir-opt/mlir-opt.cpp +++ b/mlir/tools/mlir-opt/mlir-opt.cpp @@ -166,7 +166,12 @@ exit(1); } - return failed(MlirOptMain(output->os(), std::move(file), passPipeline, - splitInputFile, verifyDiagnostics, verifyPasses, - allowUnregisteredDialects)); + if (failed(MlirOptMain(output->os(), std::move(file), passPipeline, + splitInputFile, verifyDiagnostics, verifyPasses, + allowUnregisteredDialects))) { + return 1; + } + // Keep the output file if the invocation of MlirOptMain was successful. + output->keep(); + return 0; }