[PATCH] D77643: Keep output file after successful execution of mlir-opt

Lukas Sommer via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Apr 7 05:55:08 PDT 2020


LukasSommerTu created this revision.
LukasSommerTu added a reviewer: mehdi_amini.
Herald added subscribers: llvm-commits, grosul1, Joonsoo, liufengdb, aartbik, lucyrfox, mgester, arpith-jacob, nicolasvasilache, antiagainst, shauheen, burmako, jpienaar, rriddle.
Herald added a project: LLVM.

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 and also adds a missing parameter to the invocation of `MlirOptMain` in `standalone-opt`.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D77643

Files:
  mlir/examples/standalone/standalone-opt/standalone-opt.cpp
  mlir/test/mlir-opt/outputfile.mlir
  mlir/tools/mlir-opt/mlir-opt.cpp


Index: mlir/tools/mlir-opt/mlir-opt.cpp
===================================================================
--- mlir/tools/mlir-opt/mlir-opt.cpp
+++ 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;
 }
Index: mlir/test/mlir-opt/outputfile.mlir
===================================================================
--- /dev/null
+++ mlir/test/mlir-opt/outputfile.mlir
@@ -0,0 +1,2 @@
+// RUN: mlir-opt %s -o %t
+// RUN: test -f %t
Index: mlir/examples/standalone/standalone-opt/standalone-opt.cpp
===================================================================
--- mlir/examples/standalone/standalone-opt/standalone-opt.cpp
+++ 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<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 @@
     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;
 }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D77643.255651.patch
Type: text/x-patch
Size: 2277 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200407/ba5d8e8f/attachment.bin>


More information about the llvm-commits mailing list