1 | //===- Specialize.cpp - linalg generic ops to named ops ------------------===// |
2 | // |
3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
4 | // See https://llvm.org/LICENSE.txt for license information. |
5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
6 | // |
7 | //===----------------------------------------------------------------------===// |
8 | // |
9 | // This file implements a method to specialize generic operations to named |
10 | // operations. Conceptually it is the opposite of generalize.cpp. |
11 | // |
12 | //===----------------------------------------------------------------------===// |
13 | |
14 | #include "mlir/Dialect/Linalg/IR/Linalg.h" |
15 | #include "mlir/Dialect/Linalg/IR/LinalgInterfaces.h" |
16 | #include "mlir/Dialect/Linalg/Transforms/Transforms.h" |
17 | #include "llvm/Support/Debug.h" |
18 | |
19 | #define DEBUG_TYPE "linalg-specialization" |
20 | |
21 | using namespace mlir; |
22 | using namespace mlir::linalg; |
23 | |
24 | FailureOr<LinalgOp> mlir::linalg::specializeGenericOp(RewriterBase &rewriter, |
25 | GenericOp genericOp) { |
26 | if (isaCopyOpInterface(genericOp)) { |
27 | LinalgOp namedOp = rewriter.replaceOpWithNewOp<CopyOp>( |
28 | genericOp, genericOp.getDpsInputs()[0], genericOp.getDpsInits()[0]); |
29 | return namedOp; |
30 | } |
31 | return failure(); |
32 | } |
33 | |