[Mlir-commits] [mlir] [mlir][acc] Erase empty kernel_environment ops during canonicalization (PR #166633)
Razvan Lupusoru
llvmlistbot at llvm.org
Wed Nov 5 13:49:39 PST 2025
================
@@ -1042,6 +1042,35 @@ struct RemoveConstantIfConditionWithRegion : public OpRewritePattern<OpTy> {
}
};
+/// Remove empty acc.kernel_environment operations. If the operation has wait
+/// operands, create a acc.wait operation to preserve synchronization.
+struct RemoveEmptyKernelEnvironment
+ : public OpRewritePattern<acc::KernelEnvironmentOp> {
+ using OpRewritePattern<acc::KernelEnvironmentOp>::OpRewritePattern;
+
+ LogicalResult matchAndRewrite(acc::KernelEnvironmentOp op,
+ PatternRewriter &rewriter) const override {
+ assert(op->getNumRegions() == 1 && "expected op to have one region");
+
+ Block &block = op.getRegion().front();
+ if (!block.empty())
+ return failure();
+
+ // Remove empty kernel environment
+ // preserve synchronization by creating acc.wait operation if needed
+ if (!op.getWaitOperands().empty())
----------------
razvanlupusoru wrote:
FWIW - it looks like to me that acc.wait would only support a subset of functionality from acc.kernel_environment - primarily due to not having support for device_type. So I think your approach would be one of:
- only handle waitOperands and waitOnly and avoid "canonicalizing/folding" the empty kernels_environment region
- add the needed support to acc.wait
https://github.com/llvm/llvm-project/pull/166633
More information about the Mlir-commits
mailing list