Page MenuHomePhabricator

[mlir][bufferize] Add memory space inference

Authored by springerm on Tue, Jun 21, 7:02 AM.



Bufferization usually processes ops top-to-bottom during the rewriting phase. In that case, the memref type (and thus memory space) of an op can be directly inferred from all previous ops. However, there are a few exceptions such as scf.if.

These ops have a body with a terminator that must be bufferized. The terminator is bufferized together with the parent op. In that case, the bufferization infrastructure must compute a memref type and cannot directly take the memref type from a previous (already bufferized) op. E.g.:

scf.if %c -> tensor<?xf32> {
  // ...
  // To bufferize this op, the memory space of buffer(%r) is needed.
  scf.yield %r : tensor<?xf32>

In the above example, the bufferized type of %r is unknown when bufferizing the scf.yield op.

This change adds an ad-hoc analysis that inspects reverse SSA use-def chains of tensor values until a tensor is found for which the memory space is known.

Note: This change sets up the infrastructure and updates the BufferizableOpInterface implementations of the "arith" dialect to provide a meaningful test case. The BufferizableOpInterface implementations of other dialects are updated in subsequent changes.

Depends On D128278

Diff Detail

Event Timeline

springerm created this revision.Tue, Jun 21, 7:02 AM
springerm requested review of this revision.Tue, Jun 21, 7:02 AM
Herald added a project: Restricted Project. · View Herald TranscriptTue, Jun 21, 7:02 AM
springerm updated this revision to Diff 438738.Tue, Jun 21, 9:33 AM

update tests

springerm abandoned this revision.Thu, Jun 23, 3:30 AM

major refactoring and rolling over changes into a different revision