This is an archive of the discontinued LLVM Phabricator instance.

[mlir][scf] support 1:N type conversion for scf.for.
ClosedPublic

Authored by Peiming on Oct 19 2022, 8:52 PM.

Details

Summary

scf.for used to only support 1:1 type conversion, this patch add support for 1:N type conversion.

Diff Detail

Event Timeline

Peiming created this revision.Oct 19 2022, 8:52 PM
Peiming requested review of this revision.Oct 19 2022, 8:52 PM
Peiming added inline comments.Oct 19 2022, 8:56 PM
mlir/lib/Dialect/SCF/Transforms/StructuralTypeConversions.cpp
87

Do we really need to set the attribute here? It breaks a CHECK test with a random attribute attached.

Thanks for adding this functionality so quickly, Peiming!

Alex, for context, we will need this to complete https://reviews.llvm.org/D136286
(where we found that 1:N does not work for for loops yet)

mlir/lib/Dialect/SCF/Transforms/StructuralTypeConversions.cpp
35

Can we swap the if (inputs.size() == 1) here or the if (inputs.size() != 1) above such that the if-true is always e.g. the 1:N and the fall through is the 1:1, that feels a bit more symmetric while reading these two methods

100

an unresolved

This clearly needs a test.

mlir/lib/Dialect/SCF/Transforms/StructuralTypeConversions.cpp
19

Please document the methods.

21

Nit: no need to prefix casts with llvm::, they are reexported.

41–48

Nit: don't specify the number of stack elements in SmallVector unless you have a strong reason to pick one. Legacy code may have a number, but you don't need to replicate it.

51–89

This entire comment is obsoleted by new code, there is no cloning anymore.

87

Transformations are not required to propagate discardable attributes, but it's a sort of a good tone if they do.

Also nit: it shouldn't be necessary to explicitly static_cast, all concrete op classes overload operator-> to provide access to Operation *.

90

Thou shalt not modify IR in patterns without using the rewriter. The rewriter may be keeping track of the blocks created in the constructor and will have a dangling pointer unless it knows the block has been erased.

101

It is preferable for this to go through getTypeConverter().materializeSourceConversion instead so it composes with whatever kind of casts the caller wants to use.

Peiming updated this revision to Diff 469263.Oct 20 2022, 9:41 AM
Peiming marked 9 inline comments as done.

address comments

mlir/lib/Dialect/SCF/Transforms/StructuralTypeConversions.cpp
41–48

Good to know!

Peiming updated this revision to Diff 469275.Oct 20 2022, 10:22 AM

add test for 1:N type conversion.

Peiming updated this revision to Diff 469318.Oct 20 2022, 12:36 PM

[mlir][sparse] attach bufferizableOpInterface to InsertOp.

Peiming updated this revision to Diff 469321.Oct 20 2022, 12:37 PM

revert changes..

LGTM leaving the final approval to Alex.

mlir/lib/Dialect/SCF/Transforms/StructuralTypeConversions.cpp
26

period at end

101

That is a nice way to do that!

mlir/test/Dialect/SCF/1_N_conversion.mlir
1 ↗(On Diff #469321)

I leave this up to Alex, but I feel we should have this in test/Dialect/SparseVector, not SCF

Peiming updated this revision to Diff 469353.Oct 20 2022, 2:02 PM
Peiming marked an inline comment as done.

add missing period.

Peiming updated this revision to Diff 469758.Oct 21 2022, 2:04 PM

move test under sparse tensor dialect.

aartbik accepted this revision.Oct 21 2022, 2:06 PM
This revision is now accepted and ready to land.Oct 21 2022, 2:06 PM
This revision was landed with ongoing or failed builds.Oct 21 2022, 2:12 PM
This revision was automatically updated to reflect the committed changes.