[mlir][bufferization] Add restrict and writable attrs to to_tensor
authorMatthias Springer <springerm@google.com>
Wed, 15 Feb 2023 08:51:42 +0000 (09:51 +0100)
committerMatthias Springer <springerm@google.com>
Wed, 15 Feb 2023 09:04:54 +0000 (10:04 +0100)
commit8f7e7400b74b362251dcf155e45f4097fd574196
tree238f497139561d5ecf07db5e43f737e98ed826e3
parent462227f1150fc4a12f95a7a101de477c06d35ba7
[mlir][bufferization] Add restrict and writable attrs to to_tensor

`restrict` is similar to the C++ restrict keyword. Results of `to_tensor` that have the `restrict` attribute are guaranteed to not alias any other `to_tensor` result (after bufferization).

Note: Since `to_memref` ops are not supported by One-Shot Bufferize and all bufferizable ops follow DPS rules (i.e., the buffer of the result is the buffer of an operand or an alias thereof), the buffer of a `to_tensor` op that has the `restrict` attribute is always an entirely "new" buffer that is not aliasing with the future buffer of any tensor value in the entire program. This makes such `to_tensor` ops "safe" from a bufferization perspective; they cannot cause RaW conflicts.

Differential Revision: https://reviews.llvm.org/D144021
mlir/include/mlir/Dialect/Bufferization/IR/BufferizationOps.td
mlir/lib/Dialect/Bufferization/IR/BufferizationOps.cpp
mlir/lib/Dialect/Bufferization/Transforms/OneShotAnalysis.cpp
mlir/test/Dialect/Bufferization/Transforms/one-shot-module-bufferize-analysis.mlir
mlir/test/Dialect/Bufferization/Transforms/one-shot-module-bufferize-invalid.mlir
mlir/test/Dialect/Bufferization/ops.mlir