MLIR 22.0.0git
IRDLLoading.cpp File Reference

Go to the source code of this file.

Functions

static LogicalResult irdlAttrOrTypeVerifier (function_ref< InFlightDiagnostic()> emitError, ArrayRef< Attribute > params, ArrayRef< std::unique_ptr< Constraint > > constraints, ArrayRef< size_t > paramConstraints)
 Verify that the given list of parameters satisfy the given constraints.
LogicalResult getSegmentSizesFromAttr (Operation *op, StringRef elemName, StringRef attrName, unsigned numElements, ArrayRef< Variadicity > variadicities, SmallVectorImpl< int > &segmentSizes)
 Get the operand segment sizes from the attribute dictionary.
LogicalResult getSegmentSizes (Operation *op, StringRef elemName, StringRef attrName, unsigned numElements, ArrayRef< Variadicity > variadicities, SmallVectorImpl< int > &segmentSizes)
 Compute the segment sizes of the given element (operands, results).
LogicalResult getOperandSegmentSizes (Operation *op, ArrayRef< Variadicity > variadicities, SmallVectorImpl< int > &segmentSizes)
 Compute the segment sizes of the given operands.
LogicalResult getResultSegmentSizes (Operation *op, ArrayRef< Variadicity > variadicities, SmallVectorImpl< int > &segmentSizes)
 Compute the segment sizes of the given results.
static LogicalResult irdlOpVerifier (Operation *op, ConstraintVerifier &verifier, ArrayRef< size_t > operandConstrs, ArrayRef< Variadicity > operandVariadicity, ArrayRef< size_t > resultConstrs, ArrayRef< Variadicity > resultVariadicity, const DenseMap< StringAttr, size_t > &attributeConstrs)
 Verify that the given operation satisfies the given constraints.
static LogicalResult irdlRegionVerifier (Operation *op, ConstraintVerifier &verifier, ArrayRef< std::unique_ptr< RegionConstraint > > regionsConstraints)
static WalkResult loadOperation (OperationOp op, ExtensibleDialect *dialect, const DenseMap< TypeOp, std::unique_ptr< DynamicTypeDefinition > > &types, const DenseMap< AttributeOp, std::unique_ptr< DynamicAttrDefinition > > &attrs)
 Define and load an operation represented by a irdl.operation operation.
static DynamicAttrDefinition::VerifierFn getAttrOrTypeVerifier (Operation *attrOrTypeDef, ExtensibleDialect *dialect, DenseMap< TypeOp, std::unique_ptr< DynamicTypeDefinition > > &types, DenseMap< AttributeOp, std::unique_ptr< DynamicAttrDefinition > > &attrs)
 Get the verifier of a type or attribute definition.
static bool getBases (Operation *op, SmallPtrSet< TypeID, 4 > &paramIds, SmallPtrSet< Operation *, 4 > &paramIrdlOps, SmallPtrSet< TypeID, 4 > &isIds)
 Get the possible bases of a constraint.
static LogicalResult checkCorrectAnyOf (AnyOfOp anyOf)
 Check that an any_of is in the subset IRDL can handle.
static DenseMap< DialectOp, ExtensibleDialect * > loadEmptyDialects (ModuleOp op)
 Load all dialects in the given module, without loading any operation, type or attribute definitions.
static DenseMap< TypeOp, std::unique_ptr< DynamicTypeDefinition > > preallocateTypeDefs (ModuleOp op, DenseMap< DialectOp, ExtensibleDialect * > dialects)
 Preallocate type definitions objects with empty verifiers.
static DenseMap< AttributeOp, std::unique_ptr< DynamicAttrDefinition > > preallocateAttrDefs (ModuleOp op, DenseMap< DialectOp, ExtensibleDialect * > dialects)
 Preallocate attribute definitions objects with empty verifiers.

Function Documentation

◆ checkCorrectAnyOf()

LogicalResult checkCorrectAnyOf ( AnyOfOp anyOf)
static

Check that an any_of is in the subset IRDL can handle.

IRDL uses a greedy algorithm to match constraints. This means that if we encounter an any_of with multiple constraints, we will match the first constraint that is satisfied. Thus, the order of constraints matter in any_of with our current algorithm. In order to make the order of constraints irrelevant, we require that all any_of constraint parameters are disjoint. For this, we check that the base parameters are all disjoints between parametric operations, and that they are disjoint between parametric and is operations. This restriction will be relaxed in the future, when we will change our algorithm to be non-greedy.

Definition at line 555 of file IRDLLoading.cpp.

References anyOf, getBases(), inserted(), and success().

Referenced by mlir::irdl::loadDialects().

◆ getAttrOrTypeVerifier()

DynamicAttrDefinition::VerifierFn getAttrOrTypeVerifier ( Operation * attrOrTypeDef,
ExtensibleDialect * dialect,
DenseMap< TypeOp, std::unique_ptr< DynamicTypeDefinition > > & types,
DenseMap< AttributeOp, std::unique_ptr< DynamicAttrDefinition > > & attrs )
static

Get the verifier of a type or attribute definition.

Return nullptr if the definition is invalid.

Definition at line 431 of file IRDLLoading.cpp.

References mlir::emitError(), mlir::Region::getOps(), mlir::Operation::getRegion(), and irdlAttrOrTypeVerifier().

Referenced by mlir::irdl::loadDialects().

◆ getBases()

bool getBases ( Operation * op,
SmallPtrSet< TypeID, 4 > & paramIds,
SmallPtrSet< Operation *, 4 > & paramIrdlOps,
SmallPtrSet< TypeID, 4 > & isIds )
static

Get the possible bases of a constraint.

Return true if all bases can potentially be matched. A base is a type or an attribute definition. For instance, the base of irdl.parametric "!builtin.complex"(...) is builtin.complex. This function returns the following information through arguments:

  • paramIds: the set of type or attribute IDs that are used as bases.
  • paramIrdlOps: the set of IRDL operations that are used as bases.
  • isIds: the set of type or attribute IDs that are used in irdl.is constraints.

Definition at line 503 of file IRDLLoading.cpp.

References allOf, anyOf, getBases(), mlir::Attribute::getTypeID(), and mlir::irdl::lookupSymbolNearDialect().

Referenced by checkCorrectAnyOf(), and getBases().

◆ getOperandSegmentSizes()

LogicalResult getOperandSegmentSizes ( Operation * op,
ArrayRef< Variadicity > variadicities,
SmallVectorImpl< int > & segmentSizes )

Compute the segment sizes of the given operands.

If the operation has more than two non-single operands (optional or variadic), then get the segment sizes from the attribute dictionary. Otherwise, compute the segment sizes from the number of operands.

Definition at line 169 of file IRDLLoading.cpp.

References mlir::Operation::getNumOperands(), and getSegmentSizes().

Referenced by irdlOpVerifier().

◆ getResultSegmentSizes()

LogicalResult getResultSegmentSizes ( Operation * op,
ArrayRef< Variadicity > variadicities,
SmallVectorImpl< int > & segmentSizes )

Compute the segment sizes of the given results.

If the operation has more than two non-single results (optional or variadic), then get the segment sizes from the attribute dictionary. Otherwise, compute the segment sizes from the number of results.

Definition at line 180 of file IRDLLoading.cpp.

References mlir::Operation::getNumResults(), and getSegmentSizes().

Referenced by irdlOpVerifier().

◆ getSegmentSizes()

LogicalResult getSegmentSizes ( Operation * op,
StringRef elemName,
StringRef attrName,
unsigned numElements,
ArrayRef< Variadicity > variadicities,
SmallVectorImpl< int > & segmentSizes )

Compute the segment sizes of the given element (operands, results).

If the operation has more than two non-single elements (optional or variadic), then get the segment sizes from the attribute dictionary. Otherwise, compute the segment sizes from the number of elements. elemName should be either "operand" or "result".

Definition at line 111 of file IRDLLoading.cpp.

References mlir::Operation::emitError(), getSegmentSizesFromAttr(), and success().

Referenced by getOperandSegmentSizes(), and getResultSegmentSizes().

◆ getSegmentSizesFromAttr()

LogicalResult getSegmentSizesFromAttr ( Operation * op,
StringRef elemName,
StringRef attrName,
unsigned numElements,
ArrayRef< Variadicity > variadicities,
SmallVectorImpl< int > & segmentSizes )

Get the operand segment sizes from the attribute dictionary.

Definition at line 52 of file IRDLLoading.cpp.

References mlir::Operation::emitError(), mlir::Operation::getAttr(), and success().

Referenced by getSegmentSizes().

◆ irdlAttrOrTypeVerifier()

LogicalResult irdlAttrOrTypeVerifier ( function_ref< InFlightDiagnostic()> emitError,
ArrayRef< Attribute > params,
ArrayRef< std::unique_ptr< Constraint > > constraints,
ArrayRef< size_t > paramConstraints )
static

Verify that the given list of parameters satisfy the given constraints.

This encodes the logic of the verification method for attributes and types defined with IRDL.

Definition at line 31 of file IRDLLoading.cpp.

References mlir::emitError(), success(), and mlir::irdl::ConstraintVerifier::verify().

Referenced by getAttrOrTypeVerifier().

◆ irdlOpVerifier()

LogicalResult irdlOpVerifier ( Operation * op,
ConstraintVerifier & verifier,
ArrayRef< size_t > operandConstrs,
ArrayRef< Variadicity > operandVariadicity,
ArrayRef< size_t > resultConstrs,
ArrayRef< Variadicity > resultVariadicity,
const DenseMap< StringAttr, size_t > & attributeConstrs )
static

Verify that the given operation satisfies the given constraints.

This encodes the logic of the verification method for operations defined with IRDL.

Сheck that we have all needed attributes passed and they satisfy the constraints.

First, check if the attribute actually passed.

Then, check if the attribute value satisfies the constraint.

Definition at line 190 of file IRDLLoading.cpp.

References mlir::emitError(), mlir::Operation::emitError(), mlir::Operation::emitOpError(), mlir::Operation::getAttrDictionary(), getOperandSegmentSizes(), mlir::Operation::getOperandTypes(), getResultSegmentSizes(), mlir::Operation::getResultTypes(), success(), and mlir::irdl::ConstraintVerifier::verify().

Referenced by mlir::irdl::createVerifier().

◆ irdlRegionVerifier()

LogicalResult irdlRegionVerifier ( Operation * op,
ConstraintVerifier & verifier,
ArrayRef< std::unique_ptr< RegionConstraint > > regionsConstraints )
static

◆ loadEmptyDialects()

DenseMap< DialectOp, ExtensibleDialect * > loadEmptyDialects ( ModuleOp op)
static

Load all dialects in the given module, without loading any operation, type or attribute definitions.

Definition at line 606 of file IRDLLoading.cpp.

References mlir::MLIRContext::getOrLoadDynamicDialect().

Referenced by mlir::irdl::loadDialects().

◆ loadOperation()

WalkResult loadOperation ( OperationOp op,
ExtensibleDialect * dialect,
const DenseMap< TypeOp, std::unique_ptr< DynamicTypeDefinition > > & types,
const DenseMap< AttributeOp, std::unique_ptr< DynamicAttrDefinition > > & attrs )
static

Define and load an operation represented by a irdl.operation operation.

Definition at line 399 of file IRDLLoading.cpp.

References mlir::WalkResult::advance(), mlir::irdl::createVerifier(), mlir::DynamicOpDefinition::get(), mlir::WalkResult::interrupt(), mlir::ExtensibleDialect::registerDynamicOp(), and result.

Referenced by mlir::irdl::loadDialects().

◆ preallocateAttrDefs()

DenseMap< AttributeOp, std::unique_ptr< DynamicAttrDefinition > > preallocateAttrDefs ( ModuleOp op,
DenseMap< DialectOp, ExtensibleDialect * > dialects )
static

Preallocate attribute definitions objects with empty verifiers.

This in particular allocates a TypeID for each attribute definition.

Definition at line 641 of file IRDLLoading.cpp.

References mlir::DynamicAttrDefinition::get(), and success().

Referenced by mlir::irdl::loadDialects().

◆ preallocateTypeDefs()

DenseMap< TypeOp, std::unique_ptr< DynamicTypeDefinition > > preallocateTypeDefs ( ModuleOp op,
DenseMap< DialectOp, ExtensibleDialect * > dialects )
static

Preallocate type definitions objects with empty verifiers.

This in particular allocates a TypeID for each type definition.

Definition at line 623 of file IRDLLoading.cpp.

References mlir::DynamicTypeDefinition::get(), and success().

Referenced by mlir::irdl::loadDialects().