xref: /llvm-project/mlir/include/mlir/Dialect/Linalg/IR/LinalgBase.td (revision e7d09cecc9123f89ace1712a617e252d78b179e9)
1//===- LinalgBase.td - Linalg dialect base support ---------*- 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// This is the definition file for base linear algebra support.
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef LINALG_BASE
14#define LINALG_BASE
15
16include "mlir/Dialect/Utils/StructuredOpsUtils.td"
17include "mlir/Dialect/Linalg/IR/LinalgEnums.td"
18include "mlir/IR/EnumAttr.td"
19include "mlir/IR/OpBase.td"
20
21def Linalg_Dialect : Dialect {
22  let name = "linalg";
23  let description = [{
24    The `linalg` dialect groups together a set of types, operations and
25    transformations that are useful to implement a structured abstraction on
26    buffers and tensors. These abstractions are useful for transformations and
27    can lower to scalar load/store and other operations or to more general
28    library calls.
29
30    Additional [Linalg Dialect
31    Documentation](https://mlir.llvm.org/docs/Dialects/Linalg) and a
32    [Rationale
33    Document](https://mlir.llvm.org/docs/Rationale/RationaleLinalgDialect) are
34    are also available and should be read first before going in the details of
35    the op semantics.
36  }];
37  let cppNamespace = "::mlir::linalg";
38  let dependentDialects = [
39    "arith::ArithDialect",
40    "affine::AffineDialect",
41    "math::MathDialect",
42    "memref::MemRefDialect",
43    "tensor::TensorDialect",
44  ];
45  let useDefaultAttributePrinterParser = 1;
46  let hasCanonicalizer = 1;
47  let hasOperationAttrVerify = 1;
48  let hasConstantMaterializer = 1;
49  let extraClassDeclaration = [{
50    /// Attribute name used to memoize indexing maps for named ops.
51    constexpr const static ::llvm::StringLiteral
52        kMemoizedIndexingMapsAttrName = "linalg.memoized_indexing_maps";
53
54    using RegionBuilderFunType = llvm::function_ref<
55      void(ImplicitLocOpBuilder &b, Block &, ArrayRef<NamedAttribute>)>;
56    RegionBuilderFunType getRegionBuilder(StringRef name) {
57      return namedStructuredOpRegionBuilders.lookup(name);
58    }
59    private:
60      llvm::StringMap<RegionBuilderFunType> namedStructuredOpRegionBuilders;
61  }];
62}
63
64// Define the function attribute enums matching the OpDSL functions.
65def UnaryFnAttr : EnumAttr<Linalg_Dialect, UnaryFn, "unary_fn"> {
66  let assemblyFormat = "`<` $value `>`";
67}
68def BinaryFnAttr : EnumAttr<Linalg_Dialect, BinaryFn, "binary_fn"> {
69  let assemblyFormat = "`<` $value `>`";
70}
71def TernaryFnAttr : EnumAttr<Linalg_Dialect, TernaryFn, "ternary_fn"> {
72  let assemblyFormat = "`<` $value `>`";
73}
74def TypeFnAttr : EnumAttr<Linalg_Dialect, TypeFn, "type_fn"> {
75  let assemblyFormat = "`<` $value `>`";
76}
77
78def IteratorTypeEnum : EnumAttr<Linalg_Dialect, IteratorType, "iterator_type"> {
79  let assemblyFormat = "`<` $value `>`";
80}
81def IteratorTypeArrayAttr : TypedArrayAttrBase<IteratorTypeEnum,
82  "Iterator type should be an enum.">;
83
84#endif // LINALG_BASE
85