xref: /llvm-project/mlir/include/mlir/Dialect/IRDL/IR/IRDLTypes.td (revision 84580a02e0f0d3a43efc73dacd6bf5a18cf628cc)
1//===- IRDLTypes.td - IRDL Types ---------------------------*- 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 file declares the types IRDL uses.
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef MLIR_DIALECT_IRDL_IR_IRDLTYPES
14#define MLIR_DIALECT_IRDL_IR_IRDLTYPES
15
16include "mlir/IR/AttrTypeBase.td"
17include "IRDL.td"
18
19class IRDL_Type<string name, string typeMnemonic, list<Trait> traits = []>
20    : TypeDef<IRDL_Dialect, name, traits> {
21  let mnemonic = typeMnemonic;
22}
23
24def IRDL_AttributeType : IRDL_Type<"Attribute", "attribute"> {
25  let summary = "IRDL handle to an `mlir::Attribute`";
26  let description = [{
27    This type represents a handle to an instance of an `mlir::Attribute`,
28    so it can be used in an IRDL operation, type, or attribute definition.
29    This type can also represent a handle to an instance of an `mlir::Type`,
30    by wrapping it in a `mlir::TypeAttr`.
31
32    Example:
33
34    ```mlir
35    irdl.dialect @cmath {
36
37      irdl.type @complex { /* ... */ }
38
39      irdl.operation @norm {
40        %0 = irdl.any
41        %1 = irdl.parametric @cmath::@complex<%0>
42        irdl.operands(%1)
43        irdl.results(%0)
44      }
45    }
46    ```
47
48    Here, `%0` and `%1` are both of type `!irdl.attribute`. Note that in
49    particular, `%1` will be a handle to a `mlir::TypeAttr` wrapping an
50    instance of a `cmath.complex` type.
51  }];
52}
53
54def IRDL_RegionType : IRDL_Type<"Region", "region"> {
55  let summary = "IRDL handle to a region definition";
56  let description = [{
57    This type represents a region constraint. It is produced by
58    the `irdl.region` operation and consumed by the `irdl.regions` operation.
59    The region can be constrained on the number of arguments
60    and the number of blocks.
61
62    Example:
63    ```mlir
64    irdl.dialect @example {
65      irdl.operation @op_with_regions {
66        %r1 = irdl.region with size 3
67        %0 = irdl.any
68        %r2 = irdl.region(%0)
69        irdl.regions(%r1, %r2)
70      }
71    }
72    ```
73
74    Here we have `%r1` and `%r2`, both of which have the type `!irdl.region`.
75  }];
76}
77
78#endif // MLIR_DIALECT_IRDL_IR_IRDLTYPES
79