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