This is an archive of the discontinued LLVM Phabricator instance.

[mlir][bufferize] Add memory space inference
AbandonedPublic

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

Details

Summary

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.Jun 21 2022, 7:02 AM
springerm requested review of this revision.Jun 21 2022, 7:02 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 21 2022, 7:02 AM
springerm updated this revision to Diff 438738.Jun 21 2022, 9:33 AM

update tests

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

major refactoring and rolling over changes into a different revision