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

[Moore] Add constant materialization, fold constant conversions #7478

Merged
merged 1 commit into from
Aug 9, 2024

Conversation

fabianschuiki
Copy link
Contributor

Implement the materializeConstant function for the Moore dialect and mark the ConstantOp as a ConstantLike operation. This now allows us to write constant folders for various operations. As a first example, add a constant folder for ConversionOp that directly applies domain conversions (e.g., i42 to l42 or vice versa) to constants.

Copy link
Member

@maerhart maerhart left a comment

Choose a reason for hiding this comment

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

Isn't it required to implement a fold function for operations that have the ConstantLike trait that just returns the attribute?

Also, ConstantStringOp already has ConstantLike added, so maybe also support that in the constant materializer?

Otherwise, this looks great! 🎉

@fabianschuiki
Copy link
Contributor Author

Oh good point, I forgot about the string constant op. Will add a fold method there. Apparently it's not technically required, or at least nothing complained so far about the string constant being ConstantLike but having no folder. Let me fix that.

@fabianschuiki
Copy link
Contributor Author

Ugh just realized that the moore.string_constant op returns an IntType, so the folder and constant materializer will have to convert the string constants to an FVInt and back. That's probably something for a separate PR.

@maerhart
Copy link
Member

maerhart commented Aug 9, 2024

Ugh just realized that the moore.string_constant op returns an IntType, so the folder and constant materializer will have to convert the string constants to an FVInt and back. That's probably something for a separate PR.

Oh, yeah that sounds annoying.

Copy link
Member

@hailongSun2000 hailongSun2000 left a comment

Choose a reason for hiding this comment

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

Awesome!

@fabianschuiki fabianschuiki force-pushed the fschuiki/more-assigned-vars branch 2 times, most recently from 4576518 to 9dde613 Compare August 9, 2024 21:03
Base automatically changed from fschuiki/more-assigned-vars to main August 9, 2024 21:18
Implement the `materializeConstant` function for the Moore dialect and
mark the `ConstantOp` as a `ConstantLike` operation. This now allows us
to write constant folders for various operations. As a first example,
add a constant folder for `ConversionOp` that directly applies domain
conversions (e.g., `i42` to `l42` or vice versa) to constants.
@fabianschuiki fabianschuiki force-pushed the fschuiki/moore-fold-conversions branch from 5343d71 to d4d6c0f Compare August 9, 2024 21:20
@fabianschuiki fabianschuiki merged commit 7c32ed4 into main Aug 9, 2024
4 checks passed
@fabianschuiki fabianschuiki deleted the fschuiki/moore-fold-conversions branch August 9, 2024 21:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants