26 ArrayRef<std::unique_ptr<Constraint>> constraints)
27 : constraints(constraints), assigned() {
28 assigned.resize(this->constraints.size());
35 assert(variable < constraints.size() &&
"invalid constraint variable");
38 if (assigned[variable].has_value()) {
39 if (attr == assigned[variable].value()) {
43 return emitError() <<
"expected '" << assigned[variable].value()
44 <<
"' but got '" << attr <<
"'";
49 LogicalResult
result = constraints[variable]->verify(
emitError, attr, *
this);
51 assigned[variable] = attr;
59 if (attr == expectedAttribute)
63 return emitError() <<
"expected '" << expectedAttribute <<
"' but got '"
75 return emitError() <<
"expected base attribute '" << baseName
84 auto typeAttr = dyn_cast<TypeAttr>(attr);
87 return emitError() <<
"expected type, got attribute '" << attr;
91 Type type = typeAttr.getValue();
96 return emitError() <<
"expected base type '" << baseName <<
"' but got '"
106 auto dynAttr = dyn_cast<DynamicAttr>(attr);
107 if (!dynAttr || dynAttr.getAttrDef() != attrDef) {
109 StringRef dialectName = attrDef->getDialect()->getNamespace();
110 StringRef attrName = attrDef->getName();
111 return emitError() <<
"expected base attribute '" << attrName <<
'.'
112 << dialectName <<
"' but got '" << attr <<
"'";
119 if (params.size() != constraints.size()) {
121 StringRef dialectName = attrDef->getDialect()->getNamespace();
122 StringRef attrName = attrDef->getName();
123 emitError() <<
"attribute '" << dialectName <<
"." << attrName
124 <<
"' expects " << params.size() <<
" parameters but got "
125 << constraints.size();
130 for (
size_t i = 0, s = params.size(); i < s; i++)
141 auto typeAttr = dyn_cast<TypeAttr>(attr);
144 return emitError() <<
"expected type, got attribute '" << attr;
149 auto dynType = dyn_cast<DynamicType>(typeAttr.getValue());
150 if (!dynType || dynType.getTypeDef() != typeDef) {
152 StringRef dialectName = typeDef->getDialect()->getNamespace();
153 StringRef attrName = typeDef->getName();
154 return emitError() <<
"expected base type '" << dialectName <<
'.'
155 << attrName <<
"' but got '" << attr <<
"'";
162 if (params.size() != constraints.size()) {
164 StringRef dialectName = typeDef->getDialect()->getNamespace();
165 StringRef attrName = typeDef->getName();
166 emitError() <<
"attribute '" << dialectName <<
"." << attrName
167 <<
"' expects " << params.size() <<
" parameters but got "
168 << constraints.size();
173 for (
size_t i = 0, s = params.size(); i < s; i++)
183 for (
unsigned constr : constraints) {
186 if (succeeded(context.
verify({}, attr, constr))) {
192 return emitError() <<
"'" << attr <<
"' does not satisfy the constraint";
199 for (
unsigned constr : constraints) {
218 return [loc, parentOp] {
223 if (loc != parentOp->getLoc())
224 diag.attachNote(parentOp->getLoc()).append(
"see the operation");
229 if (blockCount.has_value() && *blockCount != region.
getBlocks().size()) {
232 << *blockCount <<
" block(s) but got " << region.
getBlocks().size();
235 if (argumentConstraints.has_value()) {
237 if (actualArgs.size() != argumentConstraints->size()) {
239 actualArgs.empty() ? region.
getLoc() : actualArgs.front().getLoc();
242 << argumentConstraints->size() <<
" arguments but got "
243 << actualArgs.size();
246 for (
auto [arg, constraint] : llvm::zip(actualArgs, *argumentConstraints)) {
static std::string diag(const llvm::Value &value)
StringRef getName() const
Return the unique name representing the type.
StringRef getName() const
Return the unique name representing the type.
Attributes are known-constant values of operations.
const AbstractTy & getAbstractAttribute() const
Return the abstract descriptor for this attribute.
TypeID getTypeID()
Return a unique identifier for the concrete attribute type.
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...
This class contains a list of basic blocks and a link to the parent operation it is attached to.
BlockArgListType getArguments()
unsigned getRegionNumber()
Return the number of this region in the parent operation.
Location getLoc()
Return a location for this region.
Operation * getParentOp()
Return the parent operation this region is attached to.
BlockListType & getBlocks()
Instances of the Type class are uniqued, have an immutable identifier and an optional mutable compone...
const AbstractTy & getAbstractType() const
Return the abstract type descriptor for this type.
TypeID getTypeID()
Return a unique identifier for the concrete type.
LogicalResult verify(function_ref< InFlightDiagnostic()> emitError, Attribute attr, ConstraintVerifier &context) const override
Check that an attribute is satisfying the constraint.
LogicalResult verify(function_ref< InFlightDiagnostic()> emitError, Attribute attr, ConstraintVerifier &context) const override
Check that an attribute is satisfying the constraint.
LogicalResult verify(function_ref< InFlightDiagnostic()> emitError, Attribute attr, ConstraintVerifier &context) const override
Check that an attribute is satisfying the constraint.
LogicalResult verify(function_ref< InFlightDiagnostic()> emitError, Attribute attr, ConstraintVerifier &context) const override
Check that an attribute is satisfying the constraint.
LogicalResult verify(function_ref< InFlightDiagnostic()> emitError, Attribute attr, ConstraintVerifier &context) const override
Check that an attribute is satisfying the constraint.
Provides context to the verification of constraints.
ConstraintVerifier(ArrayRef< std::unique_ptr< Constraint > > constraints)
LogicalResult verify(function_ref< InFlightDiagnostic()> emitError, Attribute attr, unsigned variable)
Check that a constraint is satisfied by an attribute.
LogicalResult verify(function_ref< InFlightDiagnostic()> emitError, Attribute attr, ConstraintVerifier &context) const override
Check that an attribute is satisfying the constraint.
LogicalResult verify(function_ref< InFlightDiagnostic()> emitError, Attribute attr, ConstraintVerifier &context) const override
Check that an attribute is satisfying the constraint.
LogicalResult verify(function_ref< InFlightDiagnostic()> emitError, Attribute attr, ConstraintVerifier &context) const override
Check that an attribute is satisfying the constraint.
Include the generated interface declarations.
InFlightDiagnostic emitError(Location loc)
Utility method to emit an error message using this location.
llvm::function_ref< Fn > function_ref
LogicalResult verify(mlir::Region ®ion, ConstraintVerifier &constraintContext)
Check that the region satisfies the constraint.