This is an archive of the discontinued LLVM Phabricator instance.

[mlir][linalg][bufferize] Fix CallOp bufferization
ClosedPublic

Authored by springerm on Dec 31 2021, 7:47 AM.

Details

Summary

Previously, CallOps did not have any aliasing OpResult/OpOperand pairs. Therefore, CallOps were mostly ignored by the analysis and buffer copies were not inserted when necessary.

This commit introduces the following changes:

  • Function bbArgs writable by default. A function can now be bufferized without inspecting its callers.
  • Callers must introduce buffer copies of function arguments when necessary. If a function is external, the caller must conservatively assume that a function argument is modified by the callee after bufferization. If the function is not external, the caller inspects the callee to determine if a function argument is modified.

Depends On D116456

Diff Detail

Event Timeline

springerm created this revision.Dec 31 2021, 7:47 AM
springerm requested review of this revision.Dec 31 2021, 7:47 AM

One note is to add comments/doc re what is a heuristic and how combining with "reuse any opoperand" type of heuristic may create undesirable cases (e.g. the constant case).

nicolasvasilache accepted this revision.Jan 11 2022, 1:52 AM
nicolasvasilache added inline comments.
mlir/lib/Dialect/Linalg/ComprehensiveBufferize/ModuleBufferization.cpp
97

Maybe add a comment that BBArg knows about its parent FuncOp so there is no need to store a func -> bbargs map ?

186

Can we have "Must not be called" + add an assertion ?

208

is this checked (here and everywhere)?
You may have multiple blocks in the function, you may have multiple returns (with switch or cond branches).

627

Mental note: the analysis is not iterative and we are then conservative.
A greedy pattern rewriter is iterative and would return failure to signify "not now but maybe later".

662

note allow return memref would let you go through here?

678

Should you return a list here ?

mlir/test/Dialect/Linalg/comprehensive-module-bufferize.mlir
729

Maybe add a little doc to explain why copies happen here?
There is a transitive effect occuring.

730

This also tests that in the first callee there is no need to copy, which covers the base success case.
Do we have an independent more isolated such test where there is no need to copy?

Also, TODO, add an example with recursion that needs to copy?

1038

remove?

This revision is now accepted and ready to land.Jan 11 2022, 1:52 AM
springerm updated this revision to Diff 398890.Jan 11 2022, 3:05 AM
springerm marked 7 inline comments as done.

address comments

This revision was landed with ongoing or failed builds.Jan 11 2022, 3:10 AM
This revision was automatically updated to reflect the committed changes.