22 #include "llvm/Support/FormatVariadic.h"
28 ArrayRef<std::unique_ptr<Constraint>> constraints)
29 : constraints(constraints), assigned() {
30 assigned.resize(this->constraints.size());
37 assert(variable < constraints.size() &&
"invalid constraint variable");
40 if (assigned[variable].has_value()) {
41 if (attr == assigned[variable].value()) {
45 return emitError() <<
"expected '" << assigned[variable].value()
46 <<
"' but got '" << attr <<
"'";
51 LogicalResult result = constraints[variable]->verify(
emitError, attr, *
this);
52 if (succeeded(result))
53 assigned[variable] = attr;
61 if (attr == expectedAttribute)
65 return emitError() <<
"expected '" << expectedAttribute <<
"' but got '"
77 return emitError() <<
"expected base attribute '" << baseName
86 auto typeAttr = dyn_cast<TypeAttr>(attr);
89 return emitError() <<
"expected type, got attribute '" << attr;
93 Type type = typeAttr.getValue();
98 return emitError() <<
"expected base type '" << baseName <<
"' but got '"
108 auto dynAttr = dyn_cast<DynamicAttr>(attr);
109 if (!dynAttr || dynAttr.getAttrDef() != attrDef) {
112 StringRef attrName = attrDef->
getName();
113 return emitError() <<
"expected base attribute '" << attrName <<
'.'
114 << dialectName <<
"' but got '" << attr <<
"'";
121 if (params.size() != constraints.size()) {
124 StringRef attrName = attrDef->
getName();
125 emitError() <<
"attribute '" << dialectName <<
"." << attrName
126 <<
"' expects " << params.size() <<
" parameters but got "
127 << constraints.size();
132 for (
size_t i = 0, s = params.size(); i < s; i++)
143 auto typeAttr = dyn_cast<TypeAttr>(attr);
146 return emitError() <<
"expected type, got attribute '" << attr;
151 auto dynType = dyn_cast<DynamicType>(typeAttr.getValue());
152 if (!dynType || dynType.getTypeDef() != typeDef) {
155 StringRef attrName = typeDef->
getName();
156 return emitError() <<
"expected base type '" << dialectName <<
'.'
157 << attrName <<
"' but got '" << attr <<
"'";
164 if (params.size() != constraints.size()) {
167 StringRef attrName = typeDef->
getName();
168 emitError() <<
"attribute '" << dialectName <<
"." << attrName
169 <<
"' expects " << params.size() <<
" parameters but got "
170 << constraints.size();
175 for (
size_t i = 0, s = params.size(); i < s; i++)
185 for (
unsigned constr : constraints) {
188 if (succeeded(context.
verify({}, attr, constr))) {
194 return emitError() <<
"'" << attr <<
"' does not satisfy the constraint";
201 for (
unsigned constr : constraints) {
220 return [loc, parentOp] {
225 if (loc != parentOp->getLoc())
226 diag.attachNote(parentOp->getLoc()).append(
"see the operation");
231 if (blockCount.has_value() && *blockCount != region.
getBlocks().size()) {
234 << *blockCount <<
" block(s) but got " << region.
getBlocks().size();
237 if (argumentConstraints.has_value()) {
239 if (actualArgs.size() != argumentConstraints->size()) {
241 actualArgs.empty() ? region.
getLoc() : actualArgs.front().getLoc();
244 << argumentConstraints->size() <<
" arguments but got "
245 << actualArgs.size();
248 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.
StringRef getNamespace() const
ExtensibleDialect * getDialect() const
Return the dialect defining the attribute.
StringRef getName() const
Return the name of the attribute, in the format 'attrname' and not 'dialectname.attrname'.
StringRef getName() const
Return the name of the type, in the format 'typename' and not 'dialectname.typename'.
ExtensibleDialect * getDialect() const
Return the dialect defining the 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.
Operation * getParentOp()
Return the parent operation this region is attached to.
BlockListType & getBlocks()
Location getLoc()
Return a location for this region.
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.
auto get(MLIRContext *context, Ts &&...params)
Helper method that injects context only if needed, this helps unify some of the attribute constructio...
LogicalResult verify(mlir::Region ®ion, ConstraintVerifier &constraintContext)
Check that the region satisfies the constraint.