[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");
+
+    int64_t totalSize =
+        memrefType.getNumElements() * memrefType.getElementTypeBitWidth() / 8;
+    auto alignment = allocOp.getAlignment();
+    if (alignment) {
----------------
ilovepi wrote:

```suggestion
    if (auto alignment = allocOp.getAlignment()) {
```
I don't see alignment getting used outside of this block...

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


More information about the Mlir-commits mailing list