[Mlir-commits] [mlir] [mlir][EmitC] Expand the MemRefToEmitC pass - Lowering `extract_strided_metadata` (PR #152208)
Paul Kirth
llvmlistbot at llvm.org
Thu Aug 7 09:32:40 PDT 2025
================
@@ -288,6 +290,70 @@ struct ConvertStore final : public OpConversionPattern<memref::StoreOp> {
return success();
}
};
+
+struct ConvertExtractStridedMetadata final
+ : public OpConversionPattern<memref::ExtractStridedMetadataOp> {
+ using OpConversionPattern::OpConversionPattern;
+
+ LogicalResult
+ matchAndRewrite(memref::ExtractStridedMetadataOp extractStridedMetadataOp,
+ OpAdaptor operands,
+ ConversionPatternRewriter &rewriter) const override {
+ Location loc = extractStridedMetadataOp.getLoc();
+ Value source = extractStridedMetadataOp.getSource();
+
+ MemRefType memrefType = cast<MemRefType>(source.getType());
+ if (!isMemRefTypeLegalForEmitC(memrefType))
+ return rewriter.notifyMatchFailure(
+ loc, "incompatible memref type for EmitC conversion");
+
+ emitc::ConstantOp zeroIndex = rewriter.create<emitc::ConstantOp>(
+ loc, rewriter.getIndexType(), rewriter.getIndexAttr(0));
+ TypedValue<emitc::ArrayType> srcArrayValue =
+ cast<TypedValue<emitc::ArrayType>>(operands.getSource());
+ auto createPointerFromEmitcArray = [loc, &rewriter, &zeroIndex,
+ srcArrayValue]() -> emitc::ApplyOp {
+ int64_t rank = srcArrayValue.getType().getRank();
+ llvm::SmallVector<mlir::Value> indices;
+ for (int i = 0; i < rank; ++i) {
+ indices.push_back(zeroIndex);
+ }
----------------
ilovepi wrote:
```suggestion
llvm::SmallVector<mlir::Value> indices(rank, zeroIndex);
```
https://github.com/llvm/llvm-project/pull/152208
More information about the Mlir-commits
mailing list