This is an archive of the discontinued LLVM Phabricator instance.

[mlir][bufferization] Simplify `getBufferType`
ClosedPublic

Authored by springerm on Aug 16 2023, 2:37 AM.

Details

Summary

getBufferType computes the bufferized type of an SSA value without bufferizing any IR. This is useful for predicting the bufferized type of iter_args of a loop.

To avoid endless recursion (e.g., in the case of "scf.for", the type of the iter_arg depends on the type of init_arg and the type of the yielded value; the type of the yielded value depends on the type of the iter_arg again), fixedTypes was used to fall back to "fixed" type. A simpler way is to maintain an "invocation stack". getBufferType implementations can then inspect the invocation stack to detect repetitive computations (typically when computing the bufferized type of a block argument).

Diff Detail

Event Timeline

springerm created this revision.Aug 16 2023, 2:37 AM
Herald added a project: Restricted Project. · View Herald Transcript
springerm requested review of this revision.Aug 16 2023, 2:37 AM
maerhart accepted this revision.Aug 16 2023, 3:45 AM
maerhart added inline comments.
mlir/include/mlir/Dialect/Bufferization/IR/BufferizableOpInterface.h
623

Nit: potentially a more generic type like SmallVectorImpl could be used?

mlir/lib/Dialect/Bufferization/IR/BufferizableOpInterface.cpp
742–744

This getBufferType function has the invariant that the passed value is not already pushed to the stack, but the getBufferType method of the OpInterface uses the invariant that it is already pushed to the stack. Couldn't we make this more consistent? Or document it better?

mlir/lib/Dialect/SCF/Transforms/BufferizableOpInterfaceImpl.cpp
385–391

I don't quite understand why both of them can be casted to a ranked memref/tensor. Couldn't they also be unranked?

This revision is now accepted and ready to land.Aug 16 2023, 3:45 AM
springerm marked 3 inline comments as done.Aug 16 2023, 6:02 AM
springerm added inline comments.
mlir/include/mlir/Dialect/Bufferization/IR/BufferizableOpInterface.h
623

I've been using SmallVector throughout the bufferization (e.g., AliasingOpOperandList), so keeping that for consistency.

mlir/lib/Dialect/Bufferization/IR/BufferizableOpInterface.cpp
742–744

That's so that users do not have to bother with invocationStack in most cases. Added some documentation that the interface method should not be called from user code.

This revision was automatically updated to reflect the committed changes.
springerm marked 2 inline comments as done.