This is an archive of the discontinued LLVM Phabricator instance.

[mlir][memref] Add transform to make alloca ops loop-independent
ClosedPublic

Authored by springerm on Apr 26 2023, 6:23 PM.

Details

Summary

Add a helper function that makes dynamic sizes of memref.alloca ops independent of a given set of values. This functionality can be used to make dynamic allocations hoistable from loops.

Depends On: D143910

Diff Detail

Event Timeline

springerm created this revision.Apr 26 2023, 6:23 PM
Herald added a project: Restricted Project. · View Herald TranscriptApr 26 2023, 6:23 PM
springerm requested review of this revision.Apr 26 2023, 6:23 PM
springerm updated this revision to Diff 517433.Apr 26 2023, 7:04 PM

add test case

dcaballe added inline comments.Apr 26 2023, 10:54 PM
mlir/include/mlir/Dialect/MemRef/Transforms/Transforms.h
129

can't parse this but maybe it's just me: who's -> whose?

138

same

176

Awesome!

mlir/lib/Dialect/MemRef/TransformOps/MemRefTransformOps.cpp
111

ub to var

mlir/lib/Dialect/MemRef/Transforms/IndependenceTransforms.cpp
104

same

114

We can hoist this to a utility function as it looks like we may have to add support for more ops. We should also set/restore the insertion point per user (iteration) to prevent accidental uses of a wrong insertion point.

150

Any way we could minimize the risk of creating invalid code here?

springerm updated this revision to Diff 517778.Apr 27 2023, 8:07 PM
springerm marked 7 inline comments as done.

address comments

mlir/include/mlir/Dialect/MemRef/Transforms/Transforms.h
129

ah yes i always mix those two up

mlir/lib/Dialect/MemRef/Transforms/IndependenceTransforms.cpp
104

Here we actually want unrealizedConversions.size() in the check because new ops are getting added to unrealizedConversions in the loop body.

150

We will need an interface for this eventually. This interface can be used for more than just this transform here. E.g., I think it would also be useful for canonicalization in general: it could be used to canonicalize away/simplify layout maps. There, we have the same problem, that some of the IR has to be re-created in the worst case.

(I'm not aware of any ops where we would generate invalid IR at the moment.)

dcaballe accepted this revision.May 1 2023, 10:02 AM
This revision is now accepted and ready to land.May 1 2023, 10:02 AM
This revision was landed with ongoing or failed builds.May 3 2023, 10:19 PM
This revision was automatically updated to reflect the committed changes.