mlir.dialects._pdl_ops_gen¶
Attributes¶
Classes¶
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Functions¶
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Module Contents¶
- mlir.dialects._pdl_ops_gen._ods_ir¶
- class mlir.dialects._pdl_ops_gen._Dialect(descriptor: object)¶
Bases:
_ods_ir- DIALECT_NAMESPACE = 'pdl'¶
- class mlir.dialects._pdl_ops_gen.ApplyNativeConstraintOp(results_, name, args, *, isNegated=None, loc=None, ip=None)¶
Bases:
_ods_irpdl.apply_native_constraintoperations apply a native C++ constraint, that has been registered externally with the consumer of PDL, to a given set of entities and optionally return a number of values.Example:
// Apply `myConstraint` to the entities defined by `input`, `attr`, and `op`. pdl.apply_native_constraint "myConstraint"(%input, %attr, %op : !pdl.value, !pdl.attribute, !pdl.operation) // Apply constraint `with_result` to `root`. This constraint returns an attribute. %attr = pdl.apply_native_constraint "with_result"(%root : !pdl.operation) : !pdl.attribute
- OPERATION_NAME = 'pdl.apply_native_constraint'¶
- _ODS_REGIONS = (0, True)¶
- args() _ods_ir¶
- name() _ods_ir¶
Returns the fully qualified name of the operation.
- isNegated() _ods_ir¶
- results_() _ods_ir¶
- mlir.dialects._pdl_ops_gen.apply_native_constraint(results_, name, args, *, is_negated=None, loc=None, ip=None) _ods_ir | _ods_ir | ApplyNativeConstraintOp¶
- class mlir.dialects._pdl_ops_gen.ApplyNativeRewriteOp(results_, name, args, *, loc=None, ip=None)¶
Bases:
_ods_irpdl.apply_native_rewriteoperations apply a native C++ function, that has been registered externally with the consumer of PDL, to perform a rewrite and optionally return a number of values. The native function may accept any number of arguments. This operation is used within a pdl.rewrite region to enable the interleaving of native rewrite methods with other pdl constructs.Example:
// Apply a native rewrite method that returns an attribute. %ret = pdl.apply_native_rewrite "myNativeFunc"(%arg0, %attr1) : !pdl.attribute
// The native rewrite as defined in C++: static Attribute myNativeFunc(PatternRewriter &rewriter, Value arg0, Attribute arg1) { // Just return the second arg. return arg1; } void registerNativeRewrite(PDLPatternModule &pdlModule) { pdlModule.registerRewriteFunction("myNativeFunc", myNativeFunc); }
- OPERATION_NAME = 'pdl.apply_native_rewrite'¶
- _ODS_REGIONS = (0, True)¶
- args() _ods_ir¶
- name() _ods_ir¶
Returns the fully qualified name of the operation.
- results_() _ods_ir¶
- mlir.dialects._pdl_ops_gen.apply_native_rewrite(results_, name, args, *, loc=None, ip=None) _ods_ir | _ods_ir | ApplyNativeRewriteOp¶
- class mlir.dialects._pdl_ops_gen.AttributeOp(attr, *, valueType=None, value=None, loc=None, ip=None)¶
Bases:
_ods_irpdl.attributeoperations capture named attribute edges into an operation. Instances of this operation define, and partially constrain, attributes of a given operation. Apdl.attributemay partially constrain the input by specifying an expected attribute value type (via apdl.typeoperation), or a constant value for the attribute (viaval). Only one of these may be set for a given input, as the type of the constant value provides the type. When defined within apdl.rewriteregion, the constant value must be specified.Example:
// Define an attribute: %attr = pdl.attribute // Define an attribute with an expected type: %type = pdl.type : i32 %attr = pdl.attribute : %type // Define an attribute with a constant value: %attr = pdl.attribute = "hello"
- OPERATION_NAME = 'pdl.attribute'¶
- _ODS_REGIONS = (0, True)¶
- valueType() _ods_ir | None¶
- value() _ods_ir | None¶
- attr() _ods_ir¶
- mlir.dialects._pdl_ops_gen.attribute(attr, *, value_type=None, value=None, loc=None, ip=None) _ods_ir¶
- class mlir.dialects._pdl_ops_gen.EraseOp(opValue, *, loc=None, ip=None)¶
Bases:
_ods_irpdl.eraseoperations are used withinpdl.rewriteregions to specify that an input operation should be marked as erased. The semantics of this operation correspond with theeraseOpmethod on aPatternRewriter.Example:
pdl.erase %root
- OPERATION_NAME = 'pdl.erase'¶
- _ODS_REGIONS = (0, True)¶
- opValue() _ods_ir¶
- class mlir.dialects._pdl_ops_gen.OperandOp(value, *, valueType=None, loc=None, ip=None)¶
Bases:
_ods_irpdl.operandoperations capture external operand edges into an operation node that originate from operations or block arguments not otherwise specified within the pattern (i.e. viapdl.resultorpdl.results). These operations define individual operands of a given operation. Apdl.operandmay partially constrain an operand by specifying an expected value type (via apdl.typeoperation).Example:
// Define an external operand: %operand = pdl.operand // Define an external operand with an expected type: %type = pdl.type : i32 %operand = pdl.operand : %type
- OPERATION_NAME = 'pdl.operand'¶
- _ODS_REGIONS = (0, True)¶
- valueType() _ods_ir | None¶
- value() _ods_ir¶
- mlir.dialects._pdl_ops_gen.operand(value, *, value_type=None, loc=None, ip=None) _ods_ir¶
- class mlir.dialects._pdl_ops_gen.OperandsOp(value, *, valueType=None, loc=None, ip=None)¶
Bases:
_ods_irpdl.operandsoperations capture external operand range edges into an operation node that originate from operations or block arguments not otherwise specified within the pattern (i.e. viapdl.resultorpdl.results). These operations define groups of input operands into a given operation. Apdl.operandsmay partially constrain a set of input operands by specifying expected value types (viapdl.typesoperations).Example:
// Define a range of input operands: %operands = pdl.operands // Define a range of input operands with expected types: %types = pdl.types : [i32, i64, i32] %typed_operands = pdl.operands : %types
- OPERATION_NAME = 'pdl.operands'¶
- _ODS_REGIONS = (0, True)¶
- valueType() _ods_ir | None¶
- value() _ods_ir¶
- mlir.dialects._pdl_ops_gen.operands_(value, *, value_type=None, loc=None, ip=None) _ods_ir¶
- class mlir.dialects._pdl_ops_gen.OperationOp(op, operandValues, attributeValues, attributeValueNames, typeValues, *, opName=None, loc=None, ip=None)¶
Bases:
_ods_irpdl.operationoperations define operation nodes within a pattern. Within a match sequence, i.e. when directly nested within apdl.pattern, these operations correspond to input operations, or those that already existing within the MLIR module. Inside of apdl.rewrite, these operations correspond to operations that should be created as part of the replacement sequence.pdl.operation``s are composed of a name, and a set of attribute, operand, and result type values, that map to what those that would be on a constructed instance of that operation. The results of a ``pdl.operationare a handle to the operation itself. Handles to the results of the operation can be extracted viapdl.result.Example:
// Define an instance of a `foo.op` operation. %op = pdl.operation "foo.op"(%arg0, %arg1 : !pdl.value, !pdl.value) {"attrA" = %attr0} -> (%type, %type : !pdl.type, !pdl.type)
When used within a matching context, the name of the operation may be omitted.
When used within a rewriting context, i.e. when defined within a
pdl.rewrite, all of the result types must be “inferable”. This means that the type must be attributable to either a constant type value or the result type of another entity, such as an attribute, the result of aapply_native_rewrite, or the result type of another operation. If the result type value does not meet any of these criteria, the operation must override theInferTypeOpInterfaceto ensure that the result types can be inferred.The operands of the operation are interpreted in the following ways:
A single !pdl.range:
In this case, the single range is treated as all of the operands of the operation.
// Define an instance with single range of operands. %op = pdl.operation "func.return"(%allArgs : !pdl.range<value>)
A variadic number of either !pdl.value or !pdl.range:
In this case, the inputs are expected to correspond with the operand groups defined on the operation in ODS.
// Given the following operation definition in ODS: def MyIndirectCallOp { let results = (outs FunctionType:$call, Variadic<AnyType>:$args); }// We can match the operands as so: %op = pdl.operation "my.indirect_call"(%call, %args : !pdl.value, !pdl.range<value>)
The results of the operation are interpreted in the following ways:
A single !pdl.range:
In this case, the single range is treated as all of the result types of the operation.
// Define an instance with single range of types. %allResultTypes = pdl.types %op = pdl.operation "builtin.unrealized_conversion_cast" -> (%allResultTypes : !pdl.types)
A variadic number of either !pdl.type or !pdl.range:
In this case, the inputs are expected to correspond with the result groups defined on the operation in ODS.
// Given the following operation definition in ODS: def MyOp { let results = (outs SomeType:$result, Variadic<SomeType>:$otherResults); }// We can match the results as so: %result = pdl.type %otherResults = pdl.types %op = pdl.operation "foo.op" -> (%result, %otherResults : !pdl.type, !pdl.range<type>)
- OPERATION_NAME = 'pdl.operation'¶
- _ODS_OPERAND_SEGMENTS¶
- _ODS_REGIONS = (0, True)¶
- operandValues() _ods_ir¶
- attributeValues() _ods_ir¶
- typeValues() _ods_ir¶
- opName() _ods_ir | None¶
- attributeValueNames() _ods_ir¶
- op() _ods_ir¶
- mlir.dialects._pdl_ops_gen.operation_(op, operand_values, attribute_values, attribute_value_names, type_values, *, op_name=None, loc=None, ip=None) _ods_ir¶
- class mlir.dialects._pdl_ops_gen.PatternOp(benefit, *, sym_name=None, loc=None, ip=None)¶
Bases:
_ods_irpdl.patternoperations provide a transformable representation for aRewritePattern. The attributes on this operation correspond to the various metadata on aRewritePattern, such as the benefit. The match section of the pattern is specified within the region body, with the rewrite provided by a terminatingpdl.rewrite.Example:
// Provide a pattern matching "foo.op" that replaces the root with its // operand. pdl.pattern : benefit(1) { %resultType = pdl.type %inputOperand = pdl.operand %root = pdl.operation "foo.op"(%inputOperand) -> (%resultType) pdl.rewrite %root { pdl.replace %root with (%inputOperand) } }
- OPERATION_NAME = 'pdl.pattern'¶
- _ODS_REGIONS = (1, True)¶
- benefit() _ods_ir¶
- sym_name() _ods_ir | None¶
- bodyRegion() _ods_ir¶
- class mlir.dialects._pdl_ops_gen.RangeOp(result, arguments, *, loc=None, ip=None)¶
Bases:
_ods_irpdl.rangeoperations construct a range from a given set of PDL entities, which all share the same underlying element type. For example, a!pdl.range<value>may be constructed from a list of!pdl.valueor!pdl.range<value>entities.Example:
// Construct a range of values. %valueRange = pdl.range %inputValue, %inputRange : !pdl.value, !pdl.range<value> // Construct a range of types. %typeRange = pdl.range %inputType, %inputRange : !pdl.type, !pdl.range<type> // Construct an empty range of types. %valueRange = pdl.range : !pdl.range<type>
TODO: Range construction is currently limited to rewrites, but it could be extended to constraints under certain circustances; i.e., if we can determine how to extract the underlying elements. If we can’t, e.g. if there are multiple sub ranges used for construction, we won’t be able to determine their sizes during constraint time.
- OPERATION_NAME = 'pdl.range'¶
- _ODS_REGIONS = (0, True)¶
- arguments() _ods_ir¶
- result() _ods_ir¶
Shortcut to get an op result if it has only one (throws an error otherwise).
- mlir.dialects._pdl_ops_gen.range(result, arguments, *, loc=None, ip=None) _ods_ir¶
- class mlir.dialects._pdl_ops_gen.ReplaceOp(opValue, replValues, *, replOperation=None, loc=None, ip=None)¶
Bases:
_ods_irpdl.replaceoperations are used withinpdl.rewriteregions to specify that an input operation should be marked as replaced. The semantics of this operation correspond with thereplaceOpmethod on aPatternRewriter. The set of replacement values can be either:a single
Operation(replOperationshould be populated)The operation will be replaced with the results of this operation.
a set of
Value``s (``replValuesshould be populated)The operation will be replaced with these values.
Example:
// Replace root node with 2 values: pdl.replace %root with (%val0, %val1 : !pdl.value, !pdl.value) // Replace root node with a range of values: pdl.replace %root with (%vals : !pdl.range<value>) // Replace root with another operation: pdl.replace %root with %otherOp
- OPERATION_NAME = 'pdl.replace'¶
- _ODS_OPERAND_SEGMENTS¶
- _ODS_REGIONS = (0, True)¶
- opValue() _ods_ir¶
- replOperation() _ods_ir | None¶
- replValues() _ods_ir¶
- mlir.dialects._pdl_ops_gen.replace(op_value, repl_values, *, repl_operation=None, loc=None, ip=None) ReplaceOp¶
- class mlir.dialects._pdl_ops_gen.ResultOp(val, parent, index, *, loc=None, ip=None)¶
Bases:
_ods_irpdl.resultoperations extract result edges from an operation node within a pattern or rewrite region. The provided index is zero-based, and represents the concrete result to extract, i.e. this is not the result index as defined by the ODS definition of the operation.Example:
// Extract a result: %operation = pdl.operation ... %pdl_result = pdl.result 1 of %operation // Imagine the following IR being matched: %result_0, %result_1 = foo.op ... // If the example pattern snippet above were matching against `foo.op` in // the IR snippet, `%pdl_result` would correspond to `%result_1`.
- OPERATION_NAME = 'pdl.result'¶
- _ODS_REGIONS = (0, True)¶
- parent() _ods_ir¶
Returns the parent operation, or
Noneif at top level.
- index() _ods_ir¶
- val() _ods_ir¶
- mlir.dialects._pdl_ops_gen.result(val, parent, index, *, loc=None, ip=None) _ods_ir¶
- class mlir.dialects._pdl_ops_gen.ResultsOp(val, parent, *, index=None, loc=None, ip=None)¶
Bases:
_ods_irpdl.resultsoperations extract a result group from an operation within a pattern or rewrite region. If an index is provided, this operation extracts a result group as defined by the ODS definition of the operation. In this case the result of this operation may be either a singlepdl.valueor apdl.range<value>, depending on the constraint of the result in ODS. If no index is provided, this operation extracts the full result range of the operation.Example:
// Extract all of the results of an operation: %operation = pdl.operation ... %results = pdl.results of %operation // Extract the results in the first result group of an operation, which is // variadic: %operation = pdl.operation ... %results = pdl.results 0 of %operation -> !pdl.range<value> // Extract the results in the second result group of an operation, which is // not variadic: %operation = pdl.operation ... %results = pdl.results 1 of %operation -> !pdl.value
- OPERATION_NAME = 'pdl.results'¶
- _ODS_REGIONS = (0, True)¶
- parent() _ods_ir¶
Returns the parent operation, or
Noneif at top level.
- index() _ods_ir | None¶
- val() _ods_ir¶
- mlir.dialects._pdl_ops_gen.results_(val, parent, *, index=None, loc=None, ip=None) _ods_ir¶
- class mlir.dialects._pdl_ops_gen.RewriteOp(externalArgs, *, root=None, name=None, loc=None, ip=None)¶
Bases:
_ods_irpdl.rewriteoperations terminate the region of apdl.patternand specify the main rewrite of apdl.pattern, on the optional root operation. The rewrite is specified either via a string name (name) to a native rewrite function, or via the region body. The rewrite region, if specified, must contain a single block. If the rewrite is external it functions similarly topdl.apply_native_rewrite, and takes a set of additional positional values defined within the matcher as arguments. If the rewrite is external, the root operation is passed to the native function as the leading arguments. The root operation, if provided, specifies the starting point in the pattern for the subgraph isomorphism search. Pattern matching will proceed from this node downward (towards the defining operation) or upward (towards the users) until all the operations in the pattern have been matched. If the root is omitted, the pdl_interp lowering will automatically select the best root of the pdl.rewrite among all the operations in the pattern.Example:
// Specify an external rewrite function: pdl.rewrite %root with "myExternalRewriter"(%value : !pdl.value) // Specify a rewrite inline using PDL with the given root: pdl.rewrite %root { %op = pdl.operation "foo.op"(%arg0, %arg1) pdl.replace %root with %op } // Specify a rewrite inline using PDL, automatically selecting root: pdl.rewrite { %op1 = pdl.operation "foo.op"(%arg0, %arg1) %op2 = pdl.operation "bar.op"(%arg0, %arg1) pdl.replace %root1 with %op1 pdl.replace %root2 with %op2 }
- OPERATION_NAME = 'pdl.rewrite'¶
- _ODS_OPERAND_SEGMENTS¶
- _ODS_REGIONS = (1, True)¶
- root() _ods_ir | None¶
- externalArgs() _ods_ir¶
- name() _ods_ir | None¶
Returns the fully qualified name of the operation.
- bodyRegion() _ods_ir¶
- mlir.dialects._pdl_ops_gen.rewrite(external_args, *, root=None, name=None, loc=None, ip=None) RewriteOp¶
- class mlir.dialects._pdl_ops_gen.TypeOp(result, *, constantType=None, loc=None, ip=None)¶
Bases:
_ods_irpdl.typeoperations capture result type constraints ofAttributes,Values, andOperations. Instances of this operation define, and partially constrain, results types of a given entity. Apdl.typemay partially constrain the result by specifying a constantType.Example:
// Define a type: %type = pdl.type // Define a type with a constant value: %type = pdl.type : i32
- OPERATION_NAME = 'pdl.type'¶
- _ODS_REGIONS = (0, True)¶
- constantType() _ods_ir | None¶
- result() _ods_ir¶
Shortcut to get an op result if it has only one (throws an error otherwise).
- mlir.dialects._pdl_ops_gen.type_(result, *, constant_type=None, loc=None, ip=None) _ods_ir¶
- class mlir.dialects._pdl_ops_gen.TypesOp(result, *, constantTypes=None, loc=None, ip=None)¶
Bases:
_ods_irpdl.typesoperations capture result type constraints ofValue``s, and ``Operation``s. Instances of this operation define results types of a given entity. A ``pdl.typesmay partially constrain the results by specifying an array of ``Type``s.Example:
// Define a range of types: %types = pdl.types // Define a range of types with a range of constant values: %types = pdl.types : [i32, i64, i32]
- OPERATION_NAME = 'pdl.types'¶
- _ODS_REGIONS = (0, True)¶
- constantTypes() _ods_ir | None¶
- result() _ods_ir¶
Shortcut to get an op result if it has only one (throws an error otherwise).
- mlir.dialects._pdl_ops_gen.types(result, *, constant_types=None, loc=None, ip=None) _ods_ir¶