Skip to content
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

Dialect Conversion #20

Merged
merged 15 commits into from
Oct 21, 2023
4 changes: 3 additions & 1 deletion lib/Conversion/PolyToStandard/PolyToStandard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ struct ConvertAdd : public OpConversionPattern<AddOp> {
LogicalResult matchAndRewrite(
AddOp op, OpAdaptor adaptor,
ConversionPatternRewriter &rewriter) const override {
// TODO: implement
arith::AddIOp addOp = rewriter.create<arith::AddIOp>(
op.getLoc(), adaptor.getLhs(), adaptor.getRhs());
rewriter.replaceOp(op.getOperation(), {addOp});

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

{addOp} will trigger ambiguous error in LLVM 20, so this can be implemented in this way:

rewriter.replaceOp(op.getOperation(), addOp.getOperation());

return success();
}
};
Expand Down
8 changes: 8 additions & 0 deletions tests/poly_to_standard.mlir
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// RUN: tutorial-opt --poly-to-standard %s | FileCheck %s

// CHECK-LABEL: test_lower_add
func.func @test_lower_add(%0 : !poly.poly<10>, %1 : !poly.poly<10>) -> !poly.poly<10> {
// CHECK: arith.addi
%2 = poly.add %0, %1: !poly.poly<10>
return %2 : !poly.poly<10>
}