Expand description
pdl
dialect.
PDL presents a high level abstraction for the rewrite pattern infrastructure available in MLIR. This abstraction allows for representing patterns transforming MLIR, as MLIR. This allows for applying all of the benefits that the general MLIR infrastructure provides, to the infrastructure itself. This means that pattern matching can be more easily verified for correctness, targeted by frontends, and optimized.
PDL abstracts over various different aspects of patterns and core MLIR data
structures. Patterns are specified via a pdl.pattern
operation. These
operations contain a region body for the “matcher” code, and terminate with
a pdl.rewrite
that either dispatches to an external rewriter or contains
a region for the rewrite specified via pdl
. The types of values in pdl
are handle types to MLIR C++ types, with !pdl.attribute
, !pdl.operation
,
!pdl.value
, and !pdl.type
directly mapping to mlir::Attribute
,
mlir::Operation*
, mlir::Value
, and mlir::Type
respectively.
An example pattern is shown below:
// pdl.pattern contains metadata similarly to a `RewritePattern`.
pdl.pattern : benefit(1) {
// External input operand values are specified via `pdl.operand` operations.
// Result types are constrainted via `pdl.type` operations.
%resultType = pdl.type
%inputOperand = pdl.operand
%root = pdl.operation "foo.op"(%inputOperand) -> %resultType
pdl.rewrite %root {
pdl.replace %root with (%inputOperand)
}
}
The above pattern simply replaces an operation with its first operand. Note how the input operation is specified structurally, similarly to how it would look in memory. This is a simple example and pdl provides support for many other features such as applying external constraints or external generator methods. These features and more are detailed below.
Structs§
- An
apply_native_constraint
operation. Apply a native constraint to a set of provided entities. - A builder for an
apply_native_constraint
operation. - An
apply_native_rewrite
operation. Apply a native rewrite method inside of pdl.rewrite region. - A builder for an
apply_native_rewrite
operation. - An
attribute
operation. Define an input attribute in a pattern. - A builder for an
attribute
operation. - An
erase
operation. Mark an input operation aserased
. - A builder for an
erase
operation. - An
operand
operation. Define an external input operand in a pattern. - A builder for an
operand
operation. - An
operands
operation. Define a range of input operands in a pattern. - A builder for an
operands
operation. - An
operation
operation. Define an operation within a pattern. - A builder for an
operation
operation. - A
pattern
operation. Define a rewrite pattern. - A builder for a
pattern
operation. - A
range
operation. Construct a range of pdl entities. - A builder for a
range
operation. - A
replace
operation. Mark an input operation asreplaced
. - A builder for a
replace
operation. - A
result
operation. Extract a result from an operation. - A builder for a
result
operation. - A
results
operation. Extract a result group from an operation. - A builder for a
results
operation. - A
rewrite
operation. Specify the rewrite of a matched pattern. - A builder for a
rewrite
operation. - A
type
operation. Define a type handle within a pattern. - A builder for a
type
operation. - A
types
operation. Define a range of type handles within a pattern. - A builder for a
types
operation.
Functions§
- Creates an
operation
operation. - Creates an
apply_native_constraint
operation. - Creates an
apply_native_rewrite
operation. - Creates an
attribute
operation. - Creates an
erase
operation. - Creates an
operand
operation. - Creates an
operands
operation. - Creates a
pattern
operation. - Creates a
range
operation. - Creates a
replace
operation. - Creates a
result
operation. - Creates a
results
operation. - Creates a
rewrite
operation. - Creates a
type
operation. - Creates a
types
operation.