23 #include "llvm/Support/FormatVariadic.h"
29 ArrayRef<std::unique_ptr<Constraint>> constraints)
30 : constraints(constraints), assigned() {
31 assigned.resize(this->constraints.size());
38 assert(variable < constraints.size() &&
"invalid constraint variable");
41 if (assigned[variable].has_value()) {
42 if (attr == assigned[variable].value()) {
46 return emitError() <<
"expected '" << assigned[variable].value()
47 <<
"' but got '" << attr <<
"'";
54 assigned[variable] = attr;
62 if (attr == expectedAttribute)
66 return emitError() <<
"expected '" << expectedAttribute <<
"' but got '"
78 return emitError() <<
"expected base attribute '" << baseName
87 auto typeAttr = dyn_cast<TypeAttr>(attr);
90 return emitError() <<
"expected type, got attribute '" << attr;
94 Type type = typeAttr.getValue();
99 return emitError() <<
"expected base type '" << baseName <<
"' but got '"
109 auto dynAttr = dyn_cast<DynamicAttr>(attr);
110 if (!dynAttr || dynAttr.getAttrDef() != attrDef) {
113 StringRef attrName = attrDef->
getName();
114 return emitError() <<
"expected base attribute '" << attrName <<
'.'
115 << dialectName <<
"' but got '" << attr <<
"'";
122 if (params.size() != constraints.size()) {
125 StringRef attrName = attrDef->
getName();
126 emitError() <<
"attribute '" << dialectName <<
"." << attrName
127 <<
"' expects " << params.size() <<
" parameters but got "
128 << constraints.size();
133 for (
size_t i = 0, s = params.size(); i < s; i++)
144 auto typeAttr = dyn_cast<TypeAttr>(attr);
147 return emitError() <<
"expected type, got attribute '" << attr;
152 auto dynType = dyn_cast<DynamicType>(typeAttr.getValue());
153 if (!dynType || dynType.getTypeDef() != typeDef) {
156 StringRef attrName = typeDef->
getName();
157 return emitError() <<
"expected base type '" << dialectName <<
'.'
158 << attrName <<
"' but got '" << attr <<
"'";
165 if (params.size() != constraints.size()) {
168 StringRef attrName = typeDef->
getName();
169 emitError() <<
"attribute '" << dialectName <<
"." << attrName
170 <<
"' expects " << params.size() <<
" parameters but got "
171 << constraints.size();
176 for (
size_t i = 0, s = params.size(); i < s; i++)
186 for (
unsigned constr : constraints) {
195 return emitError() <<
"'" << attr <<
"' does not satisfy the constraint";
202 for (
unsigned constr : constraints) {
221 return [loc, parentOp] {
226 if (loc != parentOp->getLoc())
227 diag.attachNote(parentOp->getLoc()).append(
"see the operation");
232 if (blockCount.has_value() && *blockCount != region.
getBlocks().size()) {
235 << *blockCount <<
" block(s) but got " << region.
getBlocks().size();
238 if (argumentConstraints.has_value()) {
240 if (actualArgs.size() != argumentConstraints->size()) {
242 actualArgs.empty() ? region.
getLoc() : actualArgs.front().getLoc();
245 << argumentConstraints->size() <<
" arguments but got "
246 << actualArgs.size();
249 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.
LogicalResult failure(bool isFailure=true)
Utility function to generate a LogicalResult.
InFlightDiagnostic emitError(Location loc)
Utility method to emit an error message using this location.
bool succeeded(LogicalResult result)
Utility function that returns true if the provided LogicalResult corresponds to a success value.
LogicalResult success(bool isSuccess=true)
Utility function to generate a LogicalResult.
auto get(MLIRContext *context, Ts &&...params)
Helper method that injects context only if needed, this helps unify some of the attribute constructio...
bool failed(LogicalResult result)
Utility function that returns true if the provided LogicalResult corresponds to a failure value.
This class represents an efficient way to signal success or failure.
LogicalResult verify(mlir::Region ®ion, ConstraintVerifier &constraintContext)
Check that the region satisfies the constraint.