Keep output file after successful execution of mlir-opt
authorLukas Sommer <sommer@esa.tu-darmstadt.de>
Wed, 8 Apr 2020 03:24:08 +0000 (03:24 +0000)
committerMehdi Amini <joker.eph@gmail.com>
Wed, 8 Apr 2020 03:37:45 +0000 (03:37 +0000)
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

mlir/examples/standalone/standalone-opt/standalone-opt.cpp
mlir/test/mlir-opt/outputfile.mlir [new file with mode: 0644]
mlir/tools/mlir-opt/mlir-opt.cpp

index 024bc8c..80c68f6 100644 (file)
@@ -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 (file)
index 0000000..cd7135e
--- /dev/null
@@ -0,0 +1,2 @@
+// RUN: mlir-opt %s -o %t
+// RUN: test -f %t
index 0aca9f6..e8b2f3d 100644 (file)
@@ -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;
 }