MLIR 24.0.0git
TransformTypes.cpp
Go to the documentation of this file.
1//===- TransformTypes.cpp - Transform Dialect Type Definitions ------------===//
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
14#include "mlir/IR/Types.h"
15#include "llvm/Support/Compiler.h"
16
17using namespace mlir;
18
19// These are automatically generated by ODS but are not used as the Transform
20// dialect uses a different dispatch mechanism to support dialect extensions.
21[[maybe_unused]] static OptionalParseResult
22generatedTypeParser(AsmParser &parser, StringRef *mnemonic, Type &value);
23[[maybe_unused]] static LogicalResult generatedTypePrinter(Type def,
24 AsmPrinter &printer);
25
26#define GET_TYPEDEF_CLASSES
27#include "mlir/Dialect/Transform/IR/TransformTypes.cpp.inc"
28
29void transform::TransformDialect::initializeTypes() {
30 addTypesChecked<
31#define GET_TYPEDEF_LIST
32#include "mlir/Dialect/Transform/IR/TransformTypes.cpp.inc"
33 >();
34}
35
36//===----------------------------------------------------------------------===//
37// transform::AffineMapParamType
38//===----------------------------------------------------------------------===//
39
41transform::AffineMapParamType::checkPayload(Location loc,
42 ArrayRef<Attribute> payload) const {
43 for (Attribute attr : payload) {
44 if (!mlir::isa<AffineMapAttr>(attr)) {
45 return emitSilenceableError(loc)
46 << "expected affine map attribute, got " << attr;
47 }
48 }
50}
51
52//===----------------------------------------------------------------------===//
53// transform::AnyOpType
54//===----------------------------------------------------------------------===//
55
57transform::AnyOpType::checkPayload(Location loc,
58 ArrayRef<Operation *> payload) const {
60}
61
62//===----------------------------------------------------------------------===//
63// transform::AnyValueType
64//===----------------------------------------------------------------------===//
65
67transform::AnyValueType::checkPayload(Location loc,
68 ArrayRef<Value> payload) const {
70}
71
72//===----------------------------------------------------------------------===//
73// transform::OperationType
74//===----------------------------------------------------------------------===//
75
77transform::OperationType::checkPayload(Location loc,
78 ArrayRef<Operation *> payload) const {
79 OperationName opName(getOperationName(), loc.getContext());
80 for (Operation *op : payload) {
81 if (opName != op->getName()) {
83 emitSilenceableError(loc)
84 << "incompatible payload operation name expected " << opName << " vs "
85 << op->getName() << " -> " << *op;
86 diag.attachNote(op->getLoc()) << "payload operation";
87 return diag;
88 }
89 }
90
92}
93
94//===----------------------------------------------------------------------===//
95// transform::AnyParamType
96//===----------------------------------------------------------------------===//
97
99transform::AnyParamType::checkPayload(Location loc,
100 ArrayRef<Attribute> payload) const {
102}
103
104//===----------------------------------------------------------------------===//
105// transform::NormalizedOpType
106//===----------------------------------------------------------------------===//
107
109transform::NormalizedOpType::checkPayload(Location loc,
110 ArrayRef<Operation *> payload) const {
111 // Only check payloads that are not already guaranteeing the required forms.
112 SmallVector<Operation *> payloadsToCheck =
113 llvm::filter_to_vector(payload, [this](Operation *op) {
114 auto normalFormCheckedOp = dyn_cast<NormalFormCheckedOpInterface>(op);
115 if (!normalFormCheckedOp)
116 return true;
117
118 SmallVector<NormalFormAttrInterface> checkedNormalForms;
119 normalFormCheckedOp.getCheckedNormalForms(checkedNormalForms);
120 return !llvm::all_of(
121 this->getNormalForms(), [&](NormalFormAttrInterface form) {
122 return llvm::is_contained(checkedNormalForms, form);
123 });
124 });
125 return detail::checkNormalForms(getNormalForms(), payloadsToCheck);
126}
127
128LogicalResult transform::NormalizedOpType::verify(
131 return detail::verifyNormalFormList(emitError, normalForms);
132}
133
134//===----------------------------------------------------------------------===//
135// transform::ParamType
136//===----------------------------------------------------------------------===//
137
138LogicalResult
139transform::ParamType::verify(function_ref<InFlightDiagnostic()> emitError,
140 Type type) {
141 IntegerType intType = llvm::dyn_cast<IntegerType>(type);
142 if (!intType || intType.getWidth() > 64)
143 return emitError() << "only supports integer types with width <=64";
144 return success();
145}
146
148transform::ParamType::checkPayload(Location loc,
149 ArrayRef<Attribute> payload) const {
150 for (Attribute attr : payload) {
151 auto integerAttr = llvm::dyn_cast<IntegerAttr>(attr);
152 if (!integerAttr) {
153 return emitSilenceableError(loc)
154 << "expected parameter to be an integer attribute, got " << attr;
155 }
156 if (integerAttr.getType() != getType()) {
157 return emitSilenceableError(loc)
158 << "expected the type of the parameter attribute ("
159 << integerAttr.getType() << ") to match the parameter type ("
160 << getType() << ")";
161 }
162 }
164}
165
166//===----------------------------------------------------------------------===//
167// transform::TypeParamType
168//===----------------------------------------------------------------------===//
169
171transform::TypeParamType::checkPayload(Location loc,
172 ArrayRef<Attribute> payload) const {
173 for (Attribute attr : payload) {
174 if (!mlir::isa<TypeAttr>(attr)) {
175 return emitSilenceableError(loc)
176 << "expected type attribute, got " << attr;
177 }
178 }
180}
return success()
static OptionalParseResult generatedTypeParser(AsmParser &parser, StringRef *mnemonic, Type &value)
static LogicalResult generatedTypePrinter(Type def, AsmPrinter &printer)
This base class exposes generic asm parser hooks, usable across the various derived parsers.
This base class exposes generic asm printer hooks, usable across the various derived printers.
Attributes are known-constant values of operations.
Definition Attributes.h:25
The result of a transform IR operation application.
static DiagnosedSilenceableFailure success()
Constructs a DiagnosedSilenceableFailure in the success state.
This class represents a diagnostic that is inflight and set to be reported.
This class defines the main interface for locations in MLIR and acts as a non-nullable wrapper around...
Definition Location.h:76
MLIRContext * getContext() const
Return the context this location is uniqued in.
Definition Location.h:86
Operation is the basic unit of execution within MLIR.
Definition Operation.h:87
This class implements Optional functionality for ParseResult.
Instances of the Type class are uniqued, have an immutable identifier and an optional mutable compone...
Definition Types.h:74
Include the generated interface declarations.
Type getType(OpFoldResult ofr)
Returns the int type of the integer in ofr.
Definition Utils.cpp:311
InFlightDiagnostic emitError(Location loc)
Utility method to emit an error message using this location.
llvm::function_ref< Fn > function_ref
Definition LLVM.h:155