Altering the number of results of an existing operation

While working with an operation that has a variadic number of results, I noticed that there is seemingly no way to add / erase results for an operation without creating a new one in its place.

The particular case where this was needed for me was when adding an extra return value for mlir::func::FuncOp. All of the mlir::func::CallOps for this function would need to be updated to connect the extra result value to other operations. For operands it is straightforward to modify them via the MutableOperandRange adaptor, but I do not see a similar mechanism for results. Instead, a new mlir::func::CallOp can be created with the correct list of result types and the connections updated.

What is the reason for the results not being mutable? I imagine that the reason is tied to the way OpResults / Values are stored, considering that getting a result here needs to cast the operation to InlineOpResult, but I do not have a clear picture of this. Could someone please offer a brief explanation? Additionally, are there some plans to expose a mechanism for mutating the results of an operation?

Thank you!

Indeed.

This open meeting should provide some details on how the operation storage works:

  • 2023-02-09: Deep Dive on MLIR Internals, Operation&Attribute, towards Properties slides - recording

By “mutating the results”, do you mean adding or removing some results? If so then no there are no plans for that right now.

That presentation is fantastic; it answered all of my questions. Thank you, @mehdi_amini!