[llvm] [mlir] [mlir][emitc] Ensure memref-to-emitc applies type converter to memref element types (PR #203742)
Jeremy Kun via llvm-commits
llvm-commits at lists.llvm.org
Thu Jun 18 10:19:09 PDT 2026
================
@@ -186,23 +192,20 @@ struct ConvertAlloc final : public OpConversionPattern<memref::AllocOp> {
}
Type sizeTType = emitc::SizeTType::get(rewriter.getContext());
- Type elementType = memrefType.getElementType();
+ Type elementType =
+ getTypeConverter()->convertType(memrefType.getElementType());
+ if (!elementType) {
+ return rewriter.notifyMatchFailure(
+ loc, "failed to convert memref element type");
+ }
IndexType indexType = rewriter.getIndexType();
- emitc::CallOpaqueOp sizeofElementOp = emitc::CallOpaqueOp::create(
- rewriter, loc, sizeTType, rewriter.getStringAttr("sizeof"),
- ValueRange{},
- ArrayAttr::get(rewriter.getContext(), {TypeAttr::get(elementType)}));
-
- int64_t numElements = 1;
- for (int64_t dimSize : memrefType.getShape()) {
- numElements *= dimSize;
+ FailureOr<Value> totalSizeOrFail = calculateMemrefTotalSizeBytes(
+ loc, memrefType, rewriter, getTypeConverter());
----------------
j2kun wrote:
Done
https://github.com/llvm/llvm-project/pull/203742
More information about the llvm-commits
mailing list