Skip to content

Commit

Permalink
squashme: placeholder for remaining poly op lowerings
Browse files Browse the repository at this point in the history
  • Loading branch information
j2kun committed Oct 19, 2023
1 parent afd2e80 commit a81bbd0
Showing 1 changed file with 70 additions and 1 deletion.
71 changes: 70 additions & 1 deletion lib/Conversion/PolyToStandard/PolyToStandard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,67 @@ struct ConvertAdd : public OpConversionPattern<AddOp> {
}
};

struct ConvertSub : public OpConversionPattern<SubOp> {
ConvertSub(mlir::MLIRContext *context)
: OpConversionPattern<SubOp>(context) {}

using OpConversionPattern::OpConversionPattern;

LogicalResult
matchAndRewrite(SubOp op, OpAdaptor adaptor,
ConversionPatternRewriter &rewriter) const override {
arith::SubIOp subOp = rewriter.create<arith::SubIOp>(
op.getLoc(), adaptor.getLhs(), adaptor.getRhs());
rewriter.replaceOp(op.getOperation(), {subOp});
return success();
}
};

struct ConvertMul : public OpConversionPattern<MulOp> {
ConvertMul(mlir::MLIRContext *context)
: OpConversionPattern<MulOp>(context) {}

using OpConversionPattern::OpConversionPattern;

LogicalResult
matchAndRewrite(MulOp op, OpAdaptor adaptor,
ConversionPatternRewriter &rewriter) const override {
// TODO: implement mul as an affine loop
return success();
}
};

struct ConvertEval : public OpConversionPattern<EvalOp> {
ConvertEval(mlir::MLIRContext *context)
: OpConversionPattern<EvalOp>(context) {}

using OpConversionPattern::OpConversionPattern;

LogicalResult
matchAndRewrite(EvalOp op, OpAdaptor adaptor,
ConversionPatternRewriter &rewriter) const override {
// TODO: implement eval as an affine loop
return success();
}
};

struct ConvertFromTensor : public OpConversionPattern<EvalOp> {
ConvertEval(mlir::MLIRContext *context)
: OpConversionPattern<FromTensorOp>(context) {}

using OpConversionPattern::OpConversionPattern;

LogicalResult
matchAndRewrite(FromTensorOp op, OpAdaptor adaptor,
ConversionPatternRewriter &rewriter) const override {
// The input tensor needs to be extended to the size of the poly type being
// converted.
// rewriter.replaceAllUsesWith(adaptor.getInput());
return success();
}
};


struct ConvertConstant : public OpConversionPattern<ConstantOp> {
ConvertConstant(mlir::MLIRContext *context)
: OpConversionPattern<ConstantOp>(context) {}
Expand Down Expand Up @@ -79,7 +140,15 @@ struct PolyToStandard : impl::PolyToStandardBase<PolyToStandard> {

RewritePatternSet patterns(context);
PolyToStandardTypeConverter typeConverter(context);
patterns.add<ConvertAdd, ConvertConstant>(typeConverter, context);
patterns.add<
ConvertAdd,
ConvertSub,
ConvertMul,
ConvertFromTensor,
ConvertToTensor,
ConvertEval,
ConvertConstant,
>(typeConverter, context);

populateFunctionOpInterfaceTypeConversionPattern<func::FuncOp>(
patterns, typeConverter);
Expand Down

0 comments on commit a81bbd0

Please sign in to comment.