[Mlir-commits] [mlir] [mlir][gpu] `gpu-module-to-binary`: add option to dump intermediate files (PR #170016)

Fabian Mora llvmlistbot at llvm.org
Mon Dec 1 04:02:26 PST 2025


================
@@ -92,44 +90,52 @@ void GpuModuleToBinaryPass::runOnOperation() {
   for (const std::string &path : linkFiles)
     librariesToLink.push_back(StringAttr::get(&getContext(), path));
 
+  Operation *op = getOperation();
+
   // Create dump directory if specified.
   if (!dumpIntermediates.empty()) {
     if (std::error_code ec =
             llvm::sys::fs::create_directories(dumpIntermediates)) {
-      getOperation()->emitError() << "Failed to create dump directory '"
-                                  << dumpIntermediates << "': " << ec.message();
+      op->emitError() << "Failed to create dump directory '"
+                      << dumpIntermediates << "': " << ec.message();
       return signalPassFailure();
     }
   }
 
   // Create callbacks for dumping intermediate artifacts if requested.
   auto initialIRCallback = [&](llvm::Module &mod) {
-    dumpToFile(dumpIntermediates, mod.getName() + ".initial.ll",
-               [&](llvm::raw_ostream &os) { mod.print(os, nullptr); });
+    if (failed(
+            dumpToFile(op, dumpIntermediates, mod.getName() + ".initial.ll",
+                       [&](llvm::raw_ostream &os) { mod.print(os, nullptr); })))
+      signalPassFailure();
----------------
fabianmcg wrote:

It is failable: https://github.com/llvm/llvm-project/blob/main/mlir/include/mlir/Target/LLVM/ModuleToObject.h#L44

(TODO for me, use FailureOr to make it more evident)

While LLVM it's not resilient to the issues I mentioned. It makes for a better debugging/user experience to fail at the earliest.

https://github.com/llvm/llvm-project/pull/170016


More information about the Mlir-commits mailing list