This is an archive of the discontinued LLVM Phabricator instance.

[mlir][shape] Add a pattern to rewrite `shape.reduce` as `scf.for`.
ClosedPublic

Authored by pifon2a on Jun 11 2020, 2:23 PM.

Diff Detail

Event Timeline

pifon2a created this revision.Jun 11 2020, 2:23 PM
Herald added a reviewer: silvas. · View Herald Transcript
Herald added a project: Restricted Project. · View Herald Transcript

@jpienaar Jacques, I put this pattern to Transform directory, because I am not really converting Shape Ops inside the reduction operator. The only thing that changes here is just the reduce op "expanded" as a loop.
I am also not completely happy with how I named the pass. So, suggestions are very-very welcome.

silvas requested changes to this revision.Jun 11 2020, 2:43 PM
silvas added inline comments.
mlir/include/mlir/Dialect/Shape/Transforms/Passes.td
19 ↗(On Diff #270237)

All dialects share the same "namespace" of pass names, so I recommend calling it shape-* to avoid naming conflicts with other dialect passes.

Also, lower-reduce-to-scf and lower-shape-to-shape would be my name preferences so it is consistent at a glance what are lowering passes.

mlir/lib/Dialect/Shape/Transforms/ExpandReduce.cpp
41 ↗(On Diff #270237)

llvm naming convention is extentTensor

52 ↗(On Diff #270237)

should this use b instead of rewriter?

57 ↗(On Diff #270237)

can you use mlir::inlineRegion for this?

This revision now requires changes to proceed.Jun 11 2020, 2:43 PM
pifon2a updated this revision to Diff 270365.EditedJun 12 2020, 5:04 AM
pifon2a marked 3 inline comments as done.

Address the comments.

pifon2a marked an inline comment as done.Jun 12 2020, 5:06 AM
pifon2a added inline comments.
mlir/lib/Dialect/Shape/Transforms/ExpandReduce.cpp
57 ↗(On Diff #270237)

I am not sure that would look nicer since I need to convert shape.yield to scf.yield after inlining. Also blocks have different signatures. I would prefer to leave it as it is.

Nice to see this become a thing!

mlir/lib/Dialect/Shape/Transforms/ShapeToSCFLowering.cpp
1 ↗(On Diff #270365)

Should this live in Conversion/ShapeToSCF? Only transformations within a dialect are in transforms IIUC.

46 ↗(On Diff #270365)

This should be dim %extent, 0 and not rank. The rank of the extent tensor is always 1 (as it is a vector).

62 ↗(On Diff #270365)

clone with a mapping already does this for you.

65 ↗(On Diff #270365)

Can this be done with makeArrayRef?

ftynse added a subscriber: ftynse.Jun 12 2020, 7:02 AM
ftynse added inline comments.
mlir/lib/Dialect/Shape/Transforms/ShapeToSCFLowering.cpp
1 ↗(On Diff #270365)

Yes, and it should not be called "lowering". That name was deprecated long time ago.

silvas added inline comments.Jun 12 2020, 9:27 AM
mlir/lib/Dialect/Shape/Transforms/ShapeToSCFLowering.cpp
1 ↗(On Diff #270365)

Can you update the docs https://mlir.llvm.org/getting_started/Glossary/#lowering ? I was not aware of that deprecation.

frgossen accepted this revision.Jun 15 2020, 3:24 AM
pifon2a marked 6 inline comments as done.Jun 15 2020, 8:14 AM
pifon2a added inline comments.
mlir/lib/Dialect/Shape/Transforms/ShapeToSCFLowering.cpp
65 ↗(On Diff #270365)

if we could lookup arrays of values, then yes.

pifon2a updated this revision to Diff 270754.Jun 15 2020, 8:14 AM
pifon2a marked an inline comment as done.

Address the comments.

frgossen accepted this revision.Jun 15 2020, 8:17 AM
frgossen added inline comments.
mlir/include/mlir/Conversion/ShapeToSCF/ShapeToSCF.h
15

If I remember correctly, the using namespace mlir variant is preferred in LLVM.

herhut accepted this revision.Jun 15 2020, 8:23 AM

Neat!

mlir/include/mlir/Conversion/ShapeToSCF/ShapeToSCF.h
15

Only for uses, not definitions.

This revision was not accepted when it landed; it landed in state Needs Review.Jun 15 2020, 9:14 AM
This revision was automatically updated to reflect the committed changes.