Buffer placement can now operates on functions that return buffers. These buffers escape from the deallocation phase of buffer placement.
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
Just some nits.
mlir/include/mlir/Transforms/BufferPlacement.h | ||
---|---|---|
109 | Maybe rephrase in what it does rather than what it should have done. Rewrites the ReturnOp to conform with the changed function signature. Operands that correspond to return values that have been rewritten from tensor results to memref arguments are dropped. In their place, a corresponding copy operation from the operand to the new function argument is inserted. | |
145 | Nit: argument -> arguments | |
mlir/lib/Transforms/BufferPlacement.cpp | ||
399 | If it escapes, there should be no dealloc. Is that worth asserting? Can we have a case where such a dealloc exists? What should be done in such cases? | |
mlir/test/Transforms/buffer-placement.mlir | ||
471 | This is missing the CHECK lines. | |
mlir/test/lib/Transforms/TestBufferPlacement.cpp | ||
53–55 | ShapedType does not require rank. I do not understand this assertion. If it is not a ShapedType then there is simply nothing to do. As this is a test pass, I am fine with not supporting scalars, though. With a better assertion message. | |
90 | Before adding the extra arguments, we know that oldBlock and newBlock have the same number of arguments here. So why not do this earlier and use the version of map with iterators instead of the loop? Something like mapping.map(oldBlock.getArguments(), newBlock->getArguments()) | |
155 | Is the WalkResult needed here or would implicit conversion just work? |
mlir/lib/Transforms/BufferPlacement.cpp | ||
---|---|---|
399 | Asserts now if there is any DeallocOp. The other possibility is erasing that DeallocOp instead of asserting it. If a DeallocOp exists before the last user (ReturnOp), then it is already in the input IR and it has not been created by the Buffer Placement. Although, In this case, the rewriter also produces an error that the value is not dominated. | |
mlir/test/lib/Transforms/TestBufferPlacement.cpp | ||
53–55 | The Assert message was changed. | |
90 | Thanks. | |
155 | Unfortunately, the implicit conversion produces a compile error. |
mlir/test/lib/Transforms/TestBufferPlacement.cpp | ||
---|---|---|
77–96 | Looking at this again, would it not be easier to use rewriter.inlineRegionBefore to move over the entire region into the new op and then only add the new arguments to the first block? Sorry for not suggesting this earlier. | |
155 | Maybe making the return type of the lambda explicit would help? Like [&](FuncOp function) -> WalkResult {...? |
Change walk return type to WalkResult and move BlockAndValueMapping before adding new arguments to the new block.
mlir/test/lib/Transforms/TestBufferPlacement.cpp | ||
---|---|---|
77–96 | Thanks for the suggestion. The problem in this way is that we should add the new arguments using block.addArgument which happens outside of the rewriter and is not undoable. |
mlir/test/lib/Transforms/TestBufferPlacement.cpp | ||
---|---|---|
90 | It also moved before adding the new arguments. |
mlir/test/lib/Transforms/TestBufferPlacement.cpp | ||
---|---|---|
96 | This mapping happens automatically. |
mlir/test/lib/Transforms/TestBufferPlacement.cpp | ||
---|---|---|
96 | Thanks. |
Maybe rephrase in what it does rather than what it should have done.
Rewrites the ReturnOp to conform with the changed function signature. Operands that correspond to return values that have been rewritten from tensor results to memref arguments are dropped. In their place, a corresponding copy operation from the operand to the new function argument is inserted.