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

Printer: add support to print types in MLIR style #136

Merged
merged 19 commits into from
Aug 24, 2022
Merged

Conversation

tobiasgrosser
Copy link
Contributor

@tobiasgrosser tobiasgrosser commented Jul 12, 2022

This brings the xDSL output closer to the syntax MLIR is using.

Copy link
Collaborator

@webmiche webmiche left a 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 a great idea, but I would like to see some test cases. Afterward, we can merge 👍

Copy link
Collaborator

@math-fehr math-fehr left a comment

Choose a reason for hiding this comment

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

Thanks for this patch, I just added two nits comments.
I think I made a bad choice by having types closely linked with the values. While I think this makes more sense that the MLIR way, I believe that the change is not good enough to differ from MLIR.
I think this option should be the one by default, though we should give time to people to update their project with this version, before changing everything!

src/xdsl/printer.py Outdated Show resolved Hide resolved
src/xdsl/printer.py Outdated Show resolved Hide resolved
Copy link
Collaborator

@Dinistro Dinistro left a comment

Choose a reason for hiding this comment

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

Maybe add a test or two, otherwise LGTM.

@math-fehr
Copy link
Collaborator

Actually, my bad, I want to add more things to it before merging it. I'm not sure how to make this a draft PR though.
I would like to essentially print correct MLIR (without going through the converter) as well.

@webmiche
Copy link
Collaborator

webmiche commented Aug 5, 2022

Actually, my bad, I want to add more things to it before merging it. I'm not sure how to make this a draft PR though. I would like to essentially print correct MLIR (without going through the converter) as well.

You can make it a draft in the reviewers section of the PR (not a very natural place to be IMO ,but it is :))

@math-fehr math-fehr marked this pull request as draft August 5, 2022 15:40
@math-fehr math-fehr marked this pull request as ready for review August 15, 2022 22:40
@math-fehr
Copy link
Collaborator

Okay, that should now be ready for review, I made quite some changes since the last review!
The PR adds an MLIR target in xDSL, which allows to print MLIR instead of xDSL. This should allow to directly print an MLIR program without having to install MLIR. I made this the default of the -t MLIR target in xdsl_opt_main, @webmiche tell me what you think about this.
Attribute can override a method to have a custom printing format for MLIR (I'll add a similar thing for xDSL in a future commit). They can also inherit MLIRType to express that they should be printed as a type rather than an attribute.

I added a unit test file, and a simple test file for LLVM. The LLVM test is quite small, mostly because I did not wanted to implement the printing for each dialect, we can do this step by step.

Copy link
Collaborator

@webmiche webmiche left a comment

Choose a reason for hiding this comment

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

LGTM!A short test of printing and reparsing with MLIR also worked fine.

I think you did not yet handle UnitAttrs, which I feel should be part of this PR as well.

src/xdsl/xdsl_opt_main.py Show resolved Hide resolved
tests/mlir_printer_test.py Show resolved Hide resolved
@math-fehr math-fehr force-pushed the mlir_types branch 2 times, most recently from 57cb8d0 to 732bf1f Compare August 18, 2022 17:07
@math-fehr
Copy link
Collaborator

I added differential testing in mlir-conversion/ops.xdsl !

@Dinistro
Copy link
Collaborator

Does this now pass all the mlir related tests or is there still something missing? Unfortunately, I do currently not have an up to date python bindings build and can thus not test it locally.

@webmiche
Copy link
Collaborator

It works on my machine, so LGTM!

@Dinistro
Copy link
Collaborator

We might consider to add an LLVM build to the CI and pin the LLVM version with a submodule. Running these test in the CI might be beneficial.

@math-fehr math-fehr added the dialects Changes on the dialects label Aug 24, 2022
@math-fehr math-fehr merged commit 302b12d into main Aug 24, 2022
@math-fehr math-fehr deleted the mlir_types branch August 24, 2022 02:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dialects Changes on the dialects
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants