MLIR  19.0.0git
Functions
IRDLLoading.cpp File Reference
#include "mlir/Dialect/IRDL/IRDLLoading.h"
#include "mlir/Dialect/IRDL/IR/IRDL.h"
#include "mlir/Dialect/IRDL/IR/IRDLInterfaces.h"
#include "mlir/Dialect/IRDL/IRDLVerifiers.h"
#include "mlir/IR/Attributes.h"
#include "mlir/IR/BuiltinOps.h"
#include "mlir/IR/ExtensibleDialect.h"
#include "mlir/IR/OperationSupport.h"
#include "mlir/Support/LogicalResult.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/SmallPtrSet.h"
#include "llvm/Support/SMLoc.h"
#include <numeric>

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. More...
 
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. More...
 
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). More...
 
LogicalResult getOperandSegmentSizes (Operation *op, ArrayRef< Variadicity > variadicities, SmallVectorImpl< int > &segmentSizes)
 Compute the segment sizes of the given operands. More...
 
LogicalResult getResultSegmentSizes (Operation *op, ArrayRef< Variadicity > variadicities, SmallVectorImpl< int > &segmentSizes)
 Compute the segment sizes of the given results. More...
 
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. More...
 
static LogicalResult irdlRegionVerifier (Operation *op, ConstraintVerifier &verifier, ArrayRef< std::unique_ptr< RegionConstraint >> regionsConstraints)
 
static WalkResult loadOperation (OperationOp op, ExtensibleDialect *dialect, DenseMap< TypeOp, std::unique_ptr< DynamicTypeDefinition >> &types, DenseMap< AttributeOp, std::unique_ptr< DynamicAttrDefinition >> &attrs)
 Define and load an operation represented by a irdl.operation operation. More...
 
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. More...
 
static bool getBases (Operation *op, SmallPtrSet< TypeID, 4 > &paramIds, SmallPtrSet< Operation *, 4 > &paramIrdlOps, SmallPtrSet< TypeID, 4 > &isIds)
 Get the possible bases of a constraint. More...
 
static LogicalResult checkCorrectAnyOf (AnyOfOp anyOf)
 Check that an any_of is in the subset IRDL can handle. More...
 
static DenseMap< DialectOp, ExtensibleDialect * > loadEmptyDialects (ModuleOp op)
 Load all dialects in the given module, without loading any operation, type or attribute definitions. More...
 
static DenseMap< TypeOp, std::unique_ptr< DynamicTypeDefinition > > preallocateTypeDefs (ModuleOp op, DenseMap< DialectOp, ExtensibleDialect * > dialects)
 Preallocate type definitions objects with empty verifiers. More...
 
static DenseMap< AttributeOp, std::unique_ptr< DynamicAttrDefinition > > preallocateAttrDefs (ModuleOp op, DenseMap< DialectOp, ExtensibleDialect * > dialects)
 Preallocate attribute definitions objects with empty verifiers. More...
 

Function Documentation

◆ checkCorrectAnyOf()

static 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 541 of file IRDLLoading.cpp.

References mlir::failure(), and getBases().

◆ getAttrOrTypeVerifier()

static 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 417 of file IRDLLoading.cpp.

◆ getBases()

static 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 489 of file IRDLLoading.cpp.

Referenced by checkCorrectAnyOf().

◆ 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 172 of file IRDLLoading.cpp.

◆ 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 183 of file IRDLLoading.cpp.

◆ 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 114 of file IRDLLoading.cpp.

◆ 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 55 of file IRDLLoading.cpp.

◆ irdlAttrOrTypeVerifier()

static 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 34 of file IRDLLoading.cpp.

References mlir::emitError(), mlir::detail::enumerate(), mlir::failed(), mlir::failure(), mlir::success(), and mlir::irdl::ConstraintVerifier::verify().

◆ irdlOpVerifier()

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 
)
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 193 of file IRDLLoading.cpp.

◆ irdlRegionVerifier()

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

Definition at line 256 of file IRDLLoading.cpp.

◆ loadEmptyDialects()

static 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 592 of file IRDLLoading.cpp.

◆ loadOperation()

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

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

Definition at line 275 of file IRDLLoading.cpp.

◆ preallocateAttrDefs()

static 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 627 of file IRDLLoading.cpp.

◆ preallocateTypeDefs()

static 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 609 of file IRDLLoading.cpp.