[Mlir-commits] [mlir] Expand the MemRefToEmitC pass - Lowering `AllocOp` (PR #148257)

Paul Kirth llvmlistbot at llvm.org
Fri Jul 11 11:29:19 PDT 2025


================
@@ -77,6 +77,38 @@ struct ConvertAlloca final : public OpConversionPattern<memref::AllocaOp> {
   }
 };
 
+struct ConvertAlloc final : public OpConversionPattern<memref::AllocOp> {
+  using OpConversionPattern::OpConversionPattern;
+  LogicalResult
+  matchAndRewrite(memref::AllocOp allocOp, OpAdaptor operands,
+                  ConversionPatternRewriter &rewriter) const override {
+    mlir::Location loc = allocOp.getLoc();
+    auto memrefType = allocOp.getType();
+    if (!memrefType.hasStaticShape())
+      return rewriter.notifyMatchFailure(
+          allocOp.getLoc(), "cannot transform alloc op with dynamic shape");
----------------
ilovepi wrote:

Is this always a limitation? I'd imagine its just something we can't handle for now, but could potentially in the future (e.g. if the size of the alloc is the result of some function you could evaluate the function and then use the result in the call to allocate). If we think it may be possible, add a TODO: to figure that out. I'm not 100% on this, so I'll defer to folks who grasp the minutiae in the two dialects more firmly.

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


More information about the Mlir-commits mailing list