Commit 1919c8bf authored by Stephan Herhut's avatar Stephan Herhut
Browse files

Make linalg::ReshapeOp implement ViewLikeOpInterface

Summary: A reshape aliases its input memref, so it acts like a view.

Differential Revision: https://reviews.llvm.org/D83773
parent c86c1e97
Loading
Loading
Loading
Loading
+4 −3
Original line number Diff line number Diff line
@@ -61,8 +61,8 @@ def Linalg_RangeOp :
  let assemblyFormat = "$min `:` $max `:` $step attr-dict `:` type(results)";
}

class Linalg_ReshapeLikeOp<string mnemonic> :
    Linalg_Op<mnemonic, [NoSideEffect]> {
class Linalg_ReshapeLikeOp<string mnemonic, list<OpTrait> traits = []> :
    Linalg_Op<mnemonic, !listconcat(traits, [NoSideEffect])> {
  let builders = [
    // Builders for a contracting reshape whose result type is computed from
    // `src` and `reassociation`.
@@ -103,7 +103,8 @@ class Linalg_ReshapeLikeOp<string mnemonic> :
  }];
}

def Linalg_ReshapeOp : Linalg_ReshapeLikeOp<"reshape">,
def Linalg_ReshapeOp : Linalg_ReshapeLikeOp<"reshape",
    [DeclareOpInterfaceMethods<ViewLikeOpInterface>]>,
    Arguments<(ins AnyStridedMemRef:$src, AffineMapArrayAttr:$reassociation)>,
    Results<(outs AnyStridedMemRef:$result)> {
  let summary = "linalg.reshape produces a new view into the operand view";
+2 −0
Original line number Diff line number Diff line
@@ -591,6 +591,8 @@ void mlir::linalg::ReshapeOp::build(OpBuilder &b, OperationState &result,
                      b.getAffineMapArrayAttr(maps));
}

Value mlir::linalg::ReshapeOp::getViewSource() { return src(); }

// Common verifier for reshape-like types. Fills `expandedType` and
// `collapsedType` with the proper `src` or `result` type.
template <typename Op, typename T>