[Mlir-commits] [mlir] d86ece1 - Keep output file after successful execution of mlir-opt
Mehdi Amini
llvmlistbot at llvm.org
Tue Apr 7 20:38:00 PDT 2020
Author: Lukas Sommer
Date: 2020-04-08T03:37:45Z
New Revision: d86ece13d93870241d838d2873f123aa771b7077
URL: https://github.com/llvm/llvm-project/commit/d86ece13d93870241d838d2873f123aa771b7077
DIFF: https://github.com/llvm/llvm-project/commit/d86ece13d93870241d838d2873f123aa771b7077.diff
LOG: Keep output file after successful execution of mlir-opt
Invoke `keep()` on the output file of `mlir-opt` in case the invocation of `MlirOptMain` was successful, to make sure the output file is not deleted on exit from `mlir-opt`.
Fixes a similar problem in `standalone-opt` from the example for an out-of-tree, standalone MLIR dialect.
This revision also adds a missing parameter to the invocation of `MlirOptMain` in `standalone-opt`.
Differential Revision: https://reviews.llvm.org/D77643
Added:
mlir/test/mlir-opt/outputfile.mlir
Modified:
mlir/examples/standalone/standalone-opt/standalone-opt.cpp
mlir/tools/mlir-opt/mlir-opt.cpp
Removed:
################################################################################
diff --git a/mlir/examples/standalone/standalone-opt/standalone-opt.cpp b/mlir/examples/standalone/standalone-opt/standalone-opt.cpp
index 024bc8c468fa..80c68f658bdb 100644
--- a/mlir/examples/standalone/standalone-opt/standalone-opt.cpp
+++ b/mlir/examples/standalone/standalone-opt/standalone-opt.cpp
@@ -46,6 +46,11 @@ static llvm::cl::opt<bool> verifyPasses(
llvm::cl::desc("Run the verifier after each transformation pass"),
llvm::cl::init(true));
+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>
showDialects("show-dialects",
llvm::cl::desc("Print the list of registered dialects"),
@@ -91,7 +96,12 @@ int main(int argc, char **argv) {
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
index 000000000000..cd7135e94524
--- /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
index 0aca9f6d37d2..e8b2f3dc49f5 100644
--- a/mlir/tools/mlir-opt/mlir-opt.cpp
+++ b/mlir/tools/mlir-opt/mlir-opt.cpp
@@ -166,7 +166,12 @@ int main(int argc, char **argv) {
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;
}
More information about the Mlir-commits
mailing list