xref: /llvm-project/mlir/include/mlir/Dialect/SparseTensor/IR/SparseTensorInterfaces.td (revision db791b278a414fb6df1acc1799adcf11d8fb9169)
1//===- SparseTensorInterfaces.td --------------------------*- tablegen -*-===//
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#ifndef SPARSETENSOR_IR_SPARSETENSORINTERFACES
10#define SPARSETENSOR_IR_SPARSETENSORINTERFACES
11
12include "mlir/IR/OpBase.td"
13
14def StageWithSortSparseOpInterface : OpInterface<"StageWithSortSparseOp"> {
15  let description = [{
16    A stage-with-sort sparse tensor operation is an operation that produces
17    unordered intermediate output. An extra sort is required to obtain the final
18    ordered result.
19
20    E.g., convert csr -> csc need to be implemented as
21          convert csr -> unordered coo -> sort by column -> csc; and
22          concatenate csr, csc -> csr can be staged into
23          concatenate csr, csr -> unordered coo -> sort by row -> csr.
24  }];
25  let cppNamespace = "::mlir::sparse_tensor";
26  let methods = [
27    InterfaceMethod<
28    /*desc=*/"Return true if the operation needs an extra sort to produce the final result.",
29    /*retTy=*/"bool",
30    /*methodName=*/"needsExtraSort",
31    /*args=*/(ins),
32    /*methodBody=*/"">,
33    InterfaceMethod<
34    /*desc=*/"Stage the operation, return the final result value after staging.",
35    /*retTy=*/"::llvm::LogicalResult",
36    /*methodName=*/"stageWithSort",
37    /*args=*/(ins "::mlir::PatternRewriter &":$rewriter,
38                  "Value &":$tmpBuf),
39    /*methodBody=*/[{
40        return detail::stageWithSortImpl($_op, rewriter, tmpBuf);
41    }]>,
42  ];
43}
44
45
46#endif // SPARSETENSOR_IR_SPARSETENSORINTERFACES
47