MLIR  19.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 
12 #include "mlir/IR/Builders.h"
13 #include "mlir/IR/BuiltinTypes.h"
16 #include "mlir/IR/Types.h"
17 #include "llvm/ADT/TypeSwitch.h"
18 #include "llvm/Support/Compiler.h"
19 
20 using namespace mlir;
21 
22 // These are automatically generated by ODS but are not used as the Transform
23 // dialect uses a different dispatch mechanism to support dialect extensions.
24 LLVM_ATTRIBUTE_UNUSED static OptionalParseResult
25 generatedTypeParser(AsmParser &parser, StringRef *mnemonic, Type &value);
26 LLVM_ATTRIBUTE_UNUSED static LogicalResult
28 
29 #define GET_TYPEDEF_CLASSES
30 #include "mlir/Dialect/Transform/IR/TransformTypes.cpp.inc"
31 
32 void transform::TransformDialect::initializeTypes() {
33  addTypesChecked<
34 #define GET_TYPEDEF_LIST
35 #include "mlir/Dialect/Transform/IR/TransformTypes.cpp.inc"
36  >();
37 }
38 
39 //===----------------------------------------------------------------------===//
40 // transform::AffineMapParamType
41 //===----------------------------------------------------------------------===//
42 
44 transform::AffineMapParamType::checkPayload(Location loc,
45  ArrayRef<Attribute> payload) const {
46  for (Attribute attr : payload) {
47  if (!attr.isa<AffineMapAttr>()) {
48  return emitSilenceableError(loc)
49  << "expected affine map attribute, got " << attr;
50  }
51  }
53 }
54 
55 //===----------------------------------------------------------------------===//
56 // transform::AnyOpType
57 //===----------------------------------------------------------------------===//
58 
60 transform::AnyOpType::checkPayload(Location loc,
61  ArrayRef<Operation *> payload) const {
63 }
64 
65 //===----------------------------------------------------------------------===//
66 // transform::AnyValueType
67 //===----------------------------------------------------------------------===//
68 
70 transform::AnyValueType::checkPayload(Location loc,
71  ArrayRef<Value> payload) const {
73 }
74 
75 //===----------------------------------------------------------------------===//
76 // transform::OperationType
77 //===----------------------------------------------------------------------===//
78 
80 transform::OperationType::checkPayload(Location loc,
81  ArrayRef<Operation *> payload) const {
82  OperationName opName(getOperationName(), loc.getContext());
83  for (Operation *op : payload) {
84  if (opName != op->getName()) {
86  emitSilenceableError(loc)
87  << "incompatible payload operation name expected " << opName << " vs "
88  << op->getName() << " -> " << *op;
89  diag.attachNote(op->getLoc()) << "payload operation";
90  return diag;
91  }
92  }
93 
95 }
96 
97 //===----------------------------------------------------------------------===//
98 // transform::AnyParamType
99 //===----------------------------------------------------------------------===//
100 
102 transform::AnyParamType::checkPayload(Location loc,
103  ArrayRef<Attribute> payload) const {
105 }
106 
107 //===----------------------------------------------------------------------===//
108 // transform::ParamType
109 //===----------------------------------------------------------------------===//
110 
113  Type type) {
114  IntegerType intType = llvm::dyn_cast<IntegerType>(type);
115  if (!intType || intType.getWidth() > 64)
116  return emitError() << "only supports integer types with width <=64";
117  return success();
118 }
119 
121 transform::ParamType::checkPayload(Location loc,
122  ArrayRef<Attribute> payload) const {
123  for (Attribute attr : payload) {
124  auto integerAttr = llvm::dyn_cast<IntegerAttr>(attr);
125  if (!integerAttr) {
126  return emitSilenceableError(loc)
127  << "expected parameter to be an integer attribute, got " << attr;
128  }
129  if (integerAttr.getType() != getType()) {
130  return emitSilenceableError(loc)
131  << "expected the type of the parameter attribute ("
132  << integerAttr.getType() << ") to match the parameter type ("
133  << getType() << ")";
134  }
135  }
137 }
138 
139 //===----------------------------------------------------------------------===//
140 // transform::TypeParamType
141 //===----------------------------------------------------------------------===//
142 
144 transform::TypeParamType::checkPayload(Location loc,
145  ArrayRef<Attribute> payload) const {
146  for (Attribute attr : payload) {
147  if (!attr.isa<TypeAttr>()) {
148  return emitSilenceableError(loc)
149  << "expected type attribute, got " << attr;
150  }
151  }
153 }
static std::string diag(const llvm::Value &value)
static LLVM_ATTRIBUTE_UNUSED OptionalParseResult generatedTypeParser(AsmParser &parser, StringRef *mnemonic, Type &value)
static LLVM_ATTRIBUTE_UNUSED 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.
Definition: Diagnostics.h:308
This class defines the main interface for locations in MLIR and acts as a non-nullable wrapper around...
Definition: Location.h:63
MLIRContext * getContext() const
Return the context this location is uniqued in.
Definition: Location.h:73
Operation is the basic unit of execution within MLIR.
Definition: Operation.h:88
Location getLoc()
The source location the operation was defined or derived from.
Definition: Operation.h:223
OperationName getName()
The name of an operation is the key identifier for it.
Definition: Operation.h:119
This class implements Optional functionality for ParseResult.
Definition: OpDefinition.h:39
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.
InFlightDiagnostic emitError(Location loc)
Utility method to emit an error message using this location.
LogicalResult success(bool isSuccess=true)
Utility function to generate a LogicalResult.
Definition: LogicalResult.h:56
LogicalResult verify(Operation *op, bool verifyRecursively=true)
Perform (potentially expensive) checks of invariants, used to detect compiler bugs,...
Definition: Verifier.cpp:421
This class represents an efficient way to signal success or failure.
Definition: LogicalResult.h:26