-
Notifications
You must be signed in to change notification settings - Fork 383
[MooreToCore] Convert unreachable, stop, finish, finish_message ops #8895
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
Conversation
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.
I think this is reasonable but ConversionPatternSet is not actually used in the PR yet, is that correct?
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.
LGTM
| /// Add a `matchAndRewrite` function as a conversion pattern to the set. | ||
| template <class Op> | ||
| ConversionPatternSet & | ||
| add(LogicalResult (*implFn)(Op, typename Op::Adaptor, | ||
| ConversionPatternRewriter &)) { | ||
|
|
||
| struct FnPattern final : public OpConversionPattern<Op> { | ||
| using OpConversionPattern<Op>::OpConversionPattern; | ||
| LogicalResult (*implFn)(Op, typename Op::Adaptor, | ||
| ConversionPatternRewriter &); | ||
|
|
||
| LogicalResult | ||
| matchAndRewrite(Op op, typename Op::Adaptor adaptor, | ||
| ConversionPatternRewriter &rewriter) const override { | ||
| return implFn(op, adaptor, rewriter); | ||
| } | ||
| }; | ||
|
|
||
| auto pattern = | ||
| std::make_unique<FnPattern>(typeConverter, patterns.getContext()); | ||
| pattern->implFn = implFn; | ||
| patterns.add(std::move(pattern)); | ||
| return *this; | ||
| } |
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.
This part doesn't seem to be used, thus also not tested. Maybe it'd be a good idea to add this upstream? Seems like it's also useful outside of CIRCT.
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.
Ah I forgot to migrate one of the patterns that actually needs the adaptor. Added that. Good idea about upstreaming this!
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.
I think you might actually have to migrate over all the patterns, because the upstream implementation uses OpRewritePattern as base. I'm not sure if it's still the case with all the dialect conversion framework changes happening, but it used to be (and possibly still is) incompatible with conversion patterns.
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.
Seems to work 🤔
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.
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.
Hmm yeah, the RewritePatternSet uses OpRewritePattern. But it's still used to collect the OpConversionPatterns in a dialect conversion 🤔. This new pattern set just factors out creating a subclass of OpConversionPattern into a helper function, but the rest is still the same as any other dialect conversion.
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.
Yes, that's part of what's meant with "API design suggests that Conversion/RewritePattern are compatible" in the slides. What I was suggesting is to change all convert functions in the pass to have the adaptor argument even if it is not used (or change the add function in ConversionPatternSet that currently delegates to RewritePatternSet to also create a OpConversionPattern instead)
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.
Ah I see! Sorry, slow brain today. Let me change those over to use the adaptor 👍.
Add conversion patterns for the following ops:
- `moore.unreachable`
- `moore.builtin.stop`
- `moore.builtin.finish`
- `moore.builtin.finish_message`
Also create a `ConversionPatternSet` utility that simplifies creating
small conversion patterns. This basically allows us to define patterns
simply through a conversion function instead of having to define an
entire pattern struct. The `RewritePatternSet` already supports this,
but only for functions with the `matchAndRewrite` signature of rewrite
patterns:
LogicalResult (Op, PatternRewriter&)
This new utility allows us to do the same for functions with the usual
`matchAndRewrite` signature of conversion patterns, too:
LogicalResult (Op, Op::Adaptor, ConversionPatternRewriter&)
12efba4 to
1df40c6
Compare
Add conversion patterns for the following ops:
moore.unreachablemoore.builtin.stopmoore.builtin.finishmoore.builtin.finish_messageAlso create a
ConversionPatternSetutility that simplifies creating small conversion patterns. This basically allows us to define patterns simply through a conversion function instead of having to define an entire pattern struct. TheRewritePatternSetalready supports this, but only for functions with thematchAndRewritesignature of rewrite patterns:This new utility allows us to do the same for functions with the usual
matchAndRewritesignature of conversion patterns, too: