This is an archive of the discontinued LLVM Phabricator instance.

[MLIR][Bufferization] Introduce `EmptyTensorToAllocTensorOp`
ClosedPublic

Authored by chelini on Dec 14 2022, 6:56 AM.

Details

Summary

Introduce a new transform operation to replace tensor.empty with
alloc_tensor operations. The operation is a pass-through if the target
operation is already a alloc_tensor; otherwise, it expects a
tensor.empty as a target. Currently, it does not return any results.

The operation is expected to run before one_shot_bufferize as
one_shot_bufferize rejects tensor.empty.

Diff Detail

Event Timeline

chelini created this revision.Dec 14 2022, 6:56 AM
chelini requested review of this revision.Dec 14 2022, 6:56 AM
springerm added inline comments.Dec 15 2022, 1:24 AM
mlir/include/mlir/Dialect/Bufferization/TransformOps/BufferizationTransformOps.td
75–77
  • Consumes the target handle, produces the result handle
  • target must be mapped to only tensor.empty ops
  • always succeeds.
81

You can try using Transform_ConcreteOpType<"tensor.empty"> here. See LoopPeelOp in SCFTransformOps.td for an example. It's a typed alternative for PDL_Operation. We don't use it widely yet, but here it would fit well.

82

Add result for the generated alloc_tensor op here.

88

You can write ::mlir::tensor::EmptyOp here, then you also don't need check the type of the op in the impl.

mlir/lib/Dialect/Bufferization/TransformOps/BufferizationTransformOps.cpp
81

IRRewriter

chelini updated this revision to Diff 483562.Dec 16 2022, 9:20 AM
  • Use Transform_ConcreteOpType for target and transformed handle.
  • Add result
  • Use IRRewriter
springerm accepted this revision.Dec 16 2022, 9:23 AM
This revision is now accepted and ready to land.Dec 16 2022, 9:23 AM