xref: /llvm-project/mlir/include/mlir/Dialect/PDL/IR/PDLTypes.td (revision 5c8ce6d5761ed6a9a39ef5a77aa45d8b6095e0f5)
1//===- PDLTypes.td - Pattern descriptor 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 Pattern Descriptor Language dialect types.
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef MLIR_DIALECT_PDL_IR_PDLTYPES
14#define MLIR_DIALECT_PDL_IR_PDLTYPES
15
16include "mlir/IR/AttrTypeBase.td"
17include "mlir/Dialect/PDL/IR/PDLDialect.td"
18
19//===----------------------------------------------------------------------===//
20// PDL Types
21//===----------------------------------------------------------------------===//
22
23class PDL_Type<string name, string typeMnemonic>
24    : TypeDef<PDL_Dialect, name, [], "::mlir::pdl::PDLType"> {
25  let mnemonic = typeMnemonic;
26}
27
28//===----------------------------------------------------------------------===//
29// pdl::AttributeType
30//===----------------------------------------------------------------------===//
31
32def PDL_Attribute : PDL_Type<"Attribute", "attribute"> {
33  let summary = "PDL handle to an `mlir::Attribute`";
34  let description = [{
35    This type represents a handle to an instance of an `mlir::Attribute`, bound
36    to a value that is usable within a PDL pattern or rewrite.
37  }];
38}
39
40//===----------------------------------------------------------------------===//
41// pdl::OperationType
42//===----------------------------------------------------------------------===//
43
44def PDL_Operation : PDL_Type<"Operation", "operation"> {
45  let summary = "PDL handle to an `mlir::Operation *`";
46  let description = [{
47    This type represents a handle to an instance of an `mlir::Operation *`,
48    bound to a value that is usable within a PDL pattern or rewrite.
49  }];
50}
51
52//===----------------------------------------------------------------------===//
53// pdl::RangeType
54//===----------------------------------------------------------------------===//
55
56def PDL_Range : PDL_Type<"Range", "range"> {
57  let summary = "PDL handle to a range of a given sub-type";
58  let description = [{
59    This type represents a range of instances of the given PDL element type,
60    i.e. `Attribute`, `Operation`, `Type`, or `Value`.
61  }];
62  let parameters = (ins "Type":$elementType);
63
64  let builders = [
65    TypeBuilderWithInferredContext<(ins "Type":$elementType), [{
66      return $_get(elementType.getContext(), elementType);
67    }]>,
68  ];
69  let genVerifyDecl = 1;
70  let hasCustomAssemblyFormat = 1;
71  let skipDefaultBuilders = 1;
72}
73
74//===----------------------------------------------------------------------===//
75// pdl::TypeType
76//===----------------------------------------------------------------------===//
77
78def PDL_Type : PDL_Type<"Type", "type"> {
79  let summary = "PDL handle to an `mlir::Type`";
80  let description = [{
81    This type represents a handle to an instance of an `mlir::Type`, bound to a
82    value that is usable within a PDL pattern or rewrite.
83  }];
84}
85
86//===----------------------------------------------------------------------===//
87// pdl::ValueType
88//===----------------------------------------------------------------------===//
89
90def PDL_Value : PDL_Type<"Value", "value"> {
91  let summary = "PDL handle for an `mlir::Value`";
92  let description = [{
93    This type represents a handle to an instance of an `mlir::Value`, bound to a
94    value that is usable within a PDL pattern or rewrite.
95  }];
96}
97
98//===----------------------------------------------------------------------===//
99// Additional Type Constraints
100//===----------------------------------------------------------------------===//
101
102def PDL_AnyType : Type<
103  CPred<"::llvm::isa<::mlir::pdl::PDLType>($_self)">, "pdl type",
104        "::mlir::pdl::PDLType">;
105
106// A range of positional values of one of the provided types.
107class PDL_RangeOf<Type positionalType> :
108  ContainerType<AnyTypeOf<[positionalType]>, PDL_Range.predicate,
109                "::llvm::cast<::mlir::pdl::RangeType>($_self).getElementType()",
110                "range", "::mlir::pdl::RangeType">,
111    BuildableType<"::mlir::pdl::RangeType::get(" # positionalType.builderCall #
112                  ")">;
113
114// Either a positional value or a range of positional values for a given type.
115class PDL_InstOrRangeOf<Type positionalType> :
116    AnyTypeOf<[positionalType, PDL_RangeOf<positionalType>],
117              "single element or range of " # positionalType.summary,
118              "::mlir::pdl::PDLType">;
119
120#endif // MLIR_DIALECT_PDL_IR_PDLTYPES
121