pub struct RewriteOperation<'c> { /* private fields */ }
Expand description
A rewrite
operation. Specify the rewrite of a matched pattern.
pdl.rewrite
operations terminate the region of a pdl.pattern
and specify
the main rewrite of a pdl.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 to pdl.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
}
Implementations§
source§impl<'c> RewriteOperation<'c>
impl<'c> RewriteOperation<'c>
sourcepub fn as_operation(&self) -> &Operation<'c>
pub fn as_operation(&self) -> &Operation<'c>
Returns a generic operation.
sourcepub fn builder(
context: &'c Context,
location: Location<'c>
) -> RewriteOperationBuilder<'c, Unset, Unset>
pub fn builder( context: &'c Context, location: Location<'c> ) -> RewriteOperationBuilder<'c, Unset, Unset>
Creates a builder.