[Mlir-commits] [mlir] [mlir][spirv] Add gpu printf op lowering to spirv.CL.printf op (PR #78510)

Jakub Kuderski llvmlistbot at llvm.org
Wed Sep 18 06:50:46 PDT 2024


================
@@ -597,6 +606,120 @@ class GPUSubgroupReduceConversion final
   }
 };
 
+/// Pattern to convert a gpu.printf op into a SPIR-V CLPrintf op.
+
+LogicalResult GPUPrintfConversion::matchAndRewrite(
+    gpu::PrintfOp gpuPrintfOp, OpAdaptor adaptor,
+    ConversionPatternRewriter &rewriter) const {
+
+  Location loc = gpuPrintfOp.getLoc();
+
+  auto moduleOp = gpuPrintfOp->getParentOfType<spirv::ModuleOp>();
+
+  if (!moduleOp) {
+    return success();
+  }
----------------
kuhar wrote:

`success` indicates that you matched, so we need to return `failure` here. Also some stylistic nits:
```suggestion
  auto moduleOp = gpuPrintfOp.getParentOfType<spirv::ModuleOp>();
  if (!moduleOp)
    return failure();
```

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


More information about the Mlir-commits mailing list