[Mlir-commits] [mlir] Expand the MemRefToEmitC pass - Lowering `AllocOp` (PR #148257)
Paul Kirth
llvmlistbot at llvm.org
Fri Jul 11 11:29:18 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;
----------------
ilovepi wrote:
In some contexts bits/byte aren't guaranteed to be 8. IDK if that's the case here or if there's a API we can use to guarantee we use the right constants. If this pattern is used elsewhere its fine. I just know we've run into similar issues on the LLVM side, and its often hard to run down.
https://github.com/llvm/llvm-project/pull/148257
More information about the Mlir-commits
mailing list