[PATCH] D78996: [MLIR][LINALG] Convert Linalg to Linalg
Mahesh Ravishankar via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Apr 30 09:35:59 PDT 2020
mravishankar added a comment.
Thanks. This is really useful!
================
Comment at: mlir/lib/Dialect/Linalg/Transforms/TensorsToBuffers.cpp:122
+ // Mark return operations illegal as long as they return values.
+ target.addDynamicallyLegalOp<mlir::ReturnOp>(
+ [](mlir::ReturnOp returnOp) { return returnOp.getNumOperands() == 0; });
----------------
dfki-ehna wrote:
> ftynse wrote:
> > This looks like it would make impossible to have simple helper functions that have no Linalg in them.
> >
> > ```
> > func @square(%arg0: f32) {
> > %0 = mulf %arg0, %arg0 : f32
> > return %0 : f32
> > }
> >
> > func @foo(...) {
> > linalg.generic (...buffers...) {
> > %0 = call @square(...) : (f32) -> f32
> > linalg.yield %0 : f32
> > }
> > }
> > ```
> Thanks for mentioning this. We addressed this issue with a quick fix to cover more test cases in this PR. However, the combination of FunctionAndBlockSignatureConverter and NonVoidToVoidReturnOpConverter of BufferAssignment would still fail in cases like the following:
> ```
> func @function(%arg0: f32, %arg1: tensor<4xf32>) -> (f32, f32) {
> %0 = mulf %arg0, %arg0 : f32
> return %0, %0 : f32, f32
> }
> ```
> FunctionAndBlockSignatureConverter converts the function to:
> ```
> func @function(%arg0: f32, %arg1: memref<4xf32>, f32, f32) {
> %0 = mulf %arg0, %arg0 : f32
> return %0, %0 : f32, f32
> }
> ```
> but the return operation remains unchanged and leaves the IR in a broken state.
> These converters must be fixed more fundamentally and we are going to do so in the next PR.
>
>
Understand that this will be fixed later, but if a function is returning a scalar of `scalarType`, the modified function should have an argument that is `memref<scalarType>`. Otherwise I am not sure how to maintain the return semantics.
================
Comment at: mlir/lib/Dialect/Linalg/Transforms/TensorsToBuffers.cpp:166
+}
\ No newline at end of file
----------------
Nit: newline at end of file.
================
Comment at: mlir/test/Dialect/Linalg/tensors-to-buffers.mlir:76
+// CHECK: return %[[RESULT]], %[[RESULT]] : [[TYPE]], [[TYPE]]
\ No newline at end of file
----------------
Nit: newline at end of file.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D78996/new/
https://reviews.llvm.org/D78996
More information about the llvm-commits
mailing list