-
Notifications
You must be signed in to change notification settings - Fork 42
fix: add pto.tfillpad_inplace; stop tfillpad from auto-lowering to TFILLPAD_INPLACE #473
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6696,12 +6696,33 @@ struct PTOFillPadToEmitC : public OpConversionPattern<pto::TFillPadOp> { | |
|
|
||
| Value src = peelUnrealized(adaptor.getSrc()); | ||
| Value dst = peelUnrealized(adaptor.getDst()); | ||
| llvm::StringRef callee = | ||
| (op.getSrc() == op.getDst() || src == dst) ? "TFILLPAD_INPLACE" | ||
| : "TFILLPAD"; | ||
|
|
||
| rewriter.create<emitc::CallOpaqueOp>( | ||
| loc, TypeRange{}, callee, | ||
| loc, TypeRange{}, "TFILLPAD", | ||
| /*args=*/ArrayAttr{}, /*templateArgs=*/ArrayAttr{}, | ||
| /*operands=*/ValueRange{dst, src}); | ||
|
|
||
| rewriter.eraseOp(op); | ||
| return success(); | ||
| } | ||
| }; | ||
| //===----------------------------------------------------------------------===// | ||
| // pto.tfillpad_inplace lowering -> TFILLPAD_INPLACE(dst, src) | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| struct PTOFillPadInplaceToEmitC | ||
| : public OpConversionPattern<pto::TFillPadInplaceOp> { | ||
| using OpConversionPattern<pto::TFillPadInplaceOp>::OpConversionPattern; | ||
|
|
||
| LogicalResult matchAndRewrite(pto::TFillPadInplaceOp op, OpAdaptor adaptor, | ||
| ConversionPatternRewriter &rewriter) const override { | ||
| auto loc = op.getLoc(); | ||
|
|
||
| Value src = peelUnrealized(adaptor.getSrc()); | ||
| Value dst = peelUnrealized(adaptor.getDst()); | ||
|
|
||
| rewriter.create<emitc::CallOpaqueOp>( | ||
| loc, TypeRange{}, "TFILLPAD_INPLACE", | ||
| /*args=*/ArrayAttr{}, /*templateArgs=*/ArrayAttr{}, | ||
| /*operands=*/ValueRange{dst, src}); | ||
|
|
||
|
Comment on lines
+6717
to
6728
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The LogicalResult matchAndRewrite(pto::TFillPadInplaceOp op, OpAdaptor adaptor,
ConversionPatternRewriter &rewriter) const override {
auto loc = op.getLoc();
Value src = peelUnrealized(adaptor.getSrc());
Value dst = peelUnrealized(adaptor.getDst());
rewriter.replaceOpWithNewOp<emitc::CallOpaqueOp>(
op, TypeRange{}, "TFILLPAD_INPLACE",
/*args=*/ArrayAttr{}, /*templateArgs=*/ArrayAttr{},
/*operands=*/ValueRange{dst, src});
return success();
}
}; |
||
|
|
@@ -9852,7 +9873,8 @@ static void populatePTOToEmitCPatterns(RewritePatternSet &patterns, | |
| patterns.add<PTOPartAddToEmitC>(typeConverter, ctx); | ||
| patterns.add<PTOExtractToEmitC, PTOExtractFPToEmitC, PTOInsertToEmitC, | ||
| PTOInsertFPToEmitC>(typeConverter, ctx); | ||
| patterns.add<PTOFillPadToEmitC, PTOFillPadExpandToEmitC>(typeConverter, ctx); | ||
| patterns.add<PTOFillPadToEmitC, PTOFillPadInplaceToEmitC, PTOFillPadExpandToEmitC>( | ||
| typeConverter, ctx); | ||
| patterns.add<PTOGatherToEmitC>(typeConverter, ctx); | ||
| patterns.add<PTOGatherbToEmitC>(typeConverter, ctx); | ||
| patterns.add<PTOMovFPToEmitC>(typeConverter, ctx); | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -2314,6 +2314,32 @@ struct PTOViewToMemrefPass | |||||||||
| dst); | ||||||||||
| } | ||||||||||
|
|
||||||||||
| SmallVector<mlir::pto::TFillPadInplaceOp, 8> fillpadInplaceOps; | ||||||||||
| func.walk( | ||||||||||
| [&](mlir::pto::TFillPadInplaceOp op) { fillpadInplaceOps.push_back(op); }); | ||||||||||
|
|
||||||||||
| for (auto op : fillpadInplaceOps) { | ||||||||||
| IRRewriter rewriter(ctx); | ||||||||||
|
Comment on lines
+2321
to
+2322
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instantiating an
Suggested change
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fixed |
||||||||||
| rewriter.setInsertionPoint(op); | ||||||||||
|
|
||||||||||
| Value src = op.getSrc(); | ||||||||||
| Value dst = op.getDst(); | ||||||||||
|
|
||||||||||
| auto srcTy = dyn_cast<MemRefType>(src.getType()); | ||||||||||
| auto dstTy = dyn_cast<MemRefType>(dst.getType()); | ||||||||||
| if (!srcTy || !dstTy) { | ||||||||||
| op.emitError("ins/outs are not memref yet"); | ||||||||||
| signalPassFailure(); | ||||||||||
| return; | ||||||||||
| } | ||||||||||
|
|
||||||||||
| rewriter.replaceOpWithNewOp<pto::TFillPadInplaceOp>( | ||||||||||
| op, | ||||||||||
| TypeRange{}, | ||||||||||
| src, | ||||||||||
| dst); | ||||||||||
| } | ||||||||||
|
|
||||||||||
| // --- TSetValOp [Dst, Offset, Val] --- | ||||||||||
| // Lower tile-world scalar write to memref-world SETVAL DPS op. | ||||||||||
| SmallVector<mlir::pto::TSetValOp, 8> tsetvalops; | ||||||||||
|
|
||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| // RUN: ptoas %s | FileCheck %s | ||
|
|
||
| module { | ||
| func.func @tfillpad_same_ssa() { | ||
| %tile = pto.alloc_tile : !pto.tile_buf<loc=vec, dtype=f32, rows=32, cols=32, v_row=32, v_col=32, blayout=row_major, slayout=none_box, fractal=512, pad=1> | ||
| pto.tfillpad ins(%tile : !pto.tile_buf<loc=vec, dtype=f32, rows=32, cols=32, v_row=32, v_col=32, blayout=row_major, slayout=none_box, fractal=512, pad=1>) | ||
| outs(%tile : !pto.tile_buf<loc=vec, dtype=f32, rows=32, cols=32, v_row=32, v_col=32, blayout=row_major, slayout=none_box, fractal=512, pad=1>) | ||
| return | ||
| } | ||
| } | ||
|
|
||
| // CHECK-LABEL: AICORE void tfillpad_same_ssa( | ||
| // CHECK: TFILLPAD( | ||
| // CHECK-NOT: TFILLPAD_INPLACE( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using
replaceOpWithNewOpis more idiomatic in MLIR conversion patterns than manually creating an operation and then erasing the original one. It ensures that the conversion driver is correctly notified of the replacement.