This is an archive of the discontinued LLVM Phabricator instance.

[NFC][mlir][MemRef] Make use of InferTypeOpInterface
ClosedPublic

Authored by qcolombet on Oct 11 2022, 6:03 PM.

Details

Summary

The InferTypeOpInterface generates builders for things it can infer the types.

Thanks to that interface we can:

  • Eliminate a builder for DimOp, and
  • Describe how to infer the result types of extract_strided_metadata from its source, and get a simpler builder as a result

NFC

Diff Detail

Event Timeline

qcolombet created this revision.Oct 11 2022, 6:03 PM
qcolombet requested review of this revision.Oct 11 2022, 6:03 PM

This seems like implementing the type inference trait would also result in this.

qcolombet added a comment.EditedOct 11 2022, 6:35 PM

This seems like implementing the type inference trait would also result in this.

I knew it was useful to do a review :).

Thanks @jpienaar !

Let me look at that closer.

This seems like implementing the type inference trait would also result in this.

Does implementing the type inference trait result in automatically emitted builders via Tablegen?
If so, could we have some doc for this ?

Generally, it would be good to have an Interface section in the docs mirrored on the MLIR website like we have for dialects so that a high-level overview gives the key information before digging into particulars.

nicolasvasilache accepted this revision.Oct 13 2022, 2:47 AM

I am ok with landing as is to get the stack in and implementing Jacques' suggestion as a followup

This revision is now accepted and ready to land.Oct 13 2022, 2:47 AM
qcolombet updated this revision to Diff 467649.Oct 13 2022, 6:15 PM
qcolombet retitled this revision from {NFC][mlir][MemRef] Add a builder for `extract_strided_metadata(source)` to [NFC][mlir][MemRef] Make use of InferTypeOpInterface.
qcolombet edited the summary of this revision. (Show Details)
  • Use InferTypeOpInterface

@jpienaar Could you take another look please?

jpienaar accepted this revision.Oct 13 2022, 7:42 PM

LG thanks!

This seems like implementing the type inference trait would also result in this.

Does implementing the type inference trait result in automatically emitted builders via Tablegen?
If so, could we have some doc for this ?

It does yes, and let me follow up on docs (I thought it was but I'll check in morning).

Generally, it would be good to have an Interface section in the docs mirrored on the MLIR website like we have for dialects so that a high-level overview gives the key information before digging into particulars.

Could you file an issue for this? This is good idea and we can autogenerate a lot of them ... We need to update a few things doc side (and definitely something which needs help and hands :-)).

mlir/lib/Dialect/MemRef/IR/MemRefOps.cpp
1257

You can use the OpAdaptor generated for this op if you want to use the generated accessor methods.

1262

It's been some time since I've worked with memrefs. To double check: they always have a memory space and rank? And it's fine to ignore layout here and just insert empty?

qcolombet added inline comments.Oct 14 2022, 9:30 AM
mlir/lib/Dialect/MemRef/IR/MemRefOps.cpp
1257

Thanks for the pointer, let me double check that.

1262

Thanks for double checking.

For MemRefTypes, yes they always have a rank and memory space.

UnrankedMemRefType don't have a rank, but they inherit from BaseMemRefType, not MemRefType (i.e., MemRefType == ranked, UnrankedMemRefType == unranked). I believe this is how we tell them apart.

Regarding the layout, yes, this is what we want. Essentially this operation generate 0-D memref from an arbitrary memref.

  • Use OpAdaptor to avoid using hardcoded indices
This revision was landed with ongoing or failed builds.Oct 14 2022, 11:52 AM
This revision was automatically updated to reflect the committed changes.