@@ -227,12 +227,14 @@ def Bufferization_MaterializeInDestinationOp
227
227
let summary = "copy a tensor";
228
228
229
229
let description = [{
230
- This op indicates that the data of the `source` tensor should materialize
231
- in `dest`, which can be a tensor or a memref. In case of a tensor, `source`
232
- should materialize in the future buffer of `dest` and a the updated
233
- destination tensor is returned. In case of a memref, `source` should
234
- materialize in `dest`, which is already a buffer. The op has no results in
235
- that case.
230
+ This op indicates that the data of the `source` tensor is guaranteed to
231
+ materialize in `dest`, which can be a tensor or a memref. In case of a
232
+ tensor, `source` materializes in the future buffer of `dest` and a the
233
+ updated destination tensor is returned. If this is not possible, e.g.,
234
+ because the destination tensor is read-only or because its original
235
+ contents are still read later, the input IR fails to bufferize. In case of a
236
+ memref, `source` materializes in `dest`, which is already a buffer. The op
237
+ has no results in that case.
236
238
237
239
`source`, `dest` and `result` (if present) must have the same shape and
238
240
element type. If the op has a result, the types of `result` and `dest` must
@@ -252,7 +254,8 @@ def Bufferization_MaterializeInDestinationOp
252
254
indicates that this op is the only way for the tensor IR to access `dest`
253
255
(or an alias thereof). E.g., there must be no other `to_tensor` ops with
254
256
`dest` or with an alias of `dest`. Such IR is not supported by
255
- One-Shot Bufferize.
257
+ One-Shot Bufferize. Ops that have incorrect usage of `restrict` may
258
+ bufferize incorrectly.
256
259
257
260
Note: `restrict` and `writable` could be removed from this op because they
258
261
must always be set for memref destinations. This op has these attributes to
@@ -262,7 +265,9 @@ def Bufferization_MaterializeInDestinationOp
262
265
Note: If `dest` is a tensor, `tensor.insert_slice` could be used for the
263
266
same purpose, but since tensor dialect ops only indicate *what* should be
264
267
computed but not *where*, it could fold away, causing the computation to
265
- materialize in a different buffer.
268
+ materialize in a different buffer. It is also possible that the
269
+ `tensor.insert_slice` destination bufferizes out-of-place, which would also
270
+ cause the computation to materialize in a buffer different buffer.
266
271
}];
267
272
268
273
let arguments = (ins AnyTensor:$source, AnyShaped:$dest,
@@ -282,6 +287,9 @@ def Bufferization_MaterializeInDestinationOp
282
287
bool bufferizesToElementwiseAccess(const AnalysisState &state,
283
288
ArrayRef<OpOperand *> opOperands);
284
289
290
+ bool mustBufferizeInPlace(OpOperand &opOperand,
291
+ const AnalysisState &state);
292
+
285
293
AliasingValueList getAliasingValues(
286
294
OpOperand &opOperand, const AnalysisState &state);
287
295
@@ -408,6 +416,7 @@ def Bufferization_ToTensorOp : Bufferization_Op<"to_tensor", [
408
416
Note: Only `to_tensor` ops with the `restrict` unit attribute are supported
409
417
by One-Shot Bufferize. Other IR is rejected. (To support `to_tensor`
410
418
without `restrict`, One-Shot Bufferize would have to analyze memref IR.)
419
+ Ops that have incorrect usage of `restrict` may bufferize incorrectly.
411
420
412
421
Example:
413
422
0 commit comments