This is an archive of the discontinued LLVM Phabricator instance.

[mlir][SCF] Adding custom builder to SCF::WhileOp.
ClosedPublic

Authored by Moerafaat on Nov 9 2022, 5:32 AM.

Details

Summary

This is a similar builder to the one for SCF::IfOp which allows users to pass region builders to it. Refer to the builders for IfOp.

Diff Detail

Event Timeline

Moerafaat created this revision.Nov 9 2022, 5:32 AM
Herald added a project: Restricted Project. · View Herald TranscriptNov 9 2022, 5:32 AM
Moerafaat requested review of this revision.Nov 9 2022, 5:32 AM
tpopp added inline comments.Nov 10 2022, 6:35 PM
mlir/include/mlir/Dialect/SCF/IR/SCFOps.td
988

ForOp uses a BodyBuilderFn to represent this type. Let's use that here also, and move the definition of BodyBuilderFn inside of a let extraClassDeclaration = ... inside of the SCF_Dialect definition.

mlir/lib/Dialect/SCF/IR/SCF.cpp
2692

Here and below, I don't actually know the signature of this method, so can you modify them to beforeRegion, /*parameterNameHere=*/{}, resultTypes?

Moerafaat updated this revision to Diff 474704.Nov 11 2022, 2:38 AM

[mlir][SCF] Updating one of the usages of SCF::WhileOp to use the new builder.

Moerafaat updated this revision to Diff 474717.Nov 11 2022, 3:52 AM

[mlir][SCF] Resolving comments

Moerafaat added inline comments.Nov 11 2022, 3:55 AM
mlir/include/mlir/Dialect/SCF/IR/SCFOps.td
988

Done

mlir/lib/Dialect/SCF/IR/SCF.cpp
2692

Done

tpopp accepted this revision.Nov 14 2022, 6:08 AM
tpopp added inline comments.
mlir/include/mlir/Dialect/SCF/IR/SCFOps.td
988

Can you use BodyBuilderFn here now?

This revision is now accepted and ready to land.Nov 14 2022, 6:08 AM
tpopp added a comment.Nov 14 2022, 6:11 AM

It looks like you will also need to run clang-format on this. I use git clang-format --style=LLVM HEAD to format my patches before landing (then you can use arc diff to upload the final patch this time and I can submit it on your behalf).

Moerafaat added inline comments.Nov 14 2022, 8:01 AM
mlir/include/mlir/Dialect/SCF/IR/SCFOps.td
988

I tried this before and it fails in SCFOps.h.inc saying "unknown type name 'BodyBuilderFn'". I checked ForOp and it also does it the way I am currently doing. My guess is the extra declarations reflect in the .cpp file which are not visible to the header file. What do you think?

Moerafaat updated this revision to Diff 475156.Nov 14 2022, 8:14 AM

Fixing clang formatting

tpopp added inline comments.Nov 14 2022, 11:10 AM
mlir/include/mlir/Dialect/SCF/IR/SCFOps.td
988

Right, it looks like extraClassDeclarations come after the generated methods. I think it would be more ideal for extraClassDeclarations to come before, but that would only work if extraClassDeclarations didn't have definitions also, which it often does, I believe, so let's leave this as it is.

We could also get around this by putting this in the extraClassDeclarations of the SCF dialect, I believe, but that is not necesarilly a good choice, as there's no guarantee that all SCF ops have the same body builder function.

This revision was automatically updated to reflect the committed changes.