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>

source

pub fn name() -> &'static str

Returns a name.

source

pub fn as_operation(&self) -> &Operation<'c>

Returns a generic operation.

source

pub fn builder( context: &'c Context, location: Location<'c> ) -> RewriteOperationBuilder<'c, Unset, Unset>

Creates a builder.

source

pub fn root(&self) -> Result<Value<'c, '_>, Error>

source

pub fn external_args( &self ) -> Result<impl Iterator<Item = Value<'c, '_>>, Error>

source

pub fn body_region(&self) -> Result<RegionRef<'c, '_>, Error>

source

pub fn _name(&self) -> Result<StringAttribute<'c>, Error>

source

pub fn set_name(&mut self, value: StringAttribute<'c>)

source

pub fn remove_name(&mut self) -> Result<(), Error>

Trait Implementations§

source§

impl<'c> From<RewriteOperation<'c>> for Operation<'c>

source§

fn from(operation: RewriteOperation<'c>) -> Self

Converts to this type from the input type.
source§

impl<'c> TryFrom<Operation<'c>> for RewriteOperation<'c>

§

type Error = Error

The type returned in the event of a conversion error.
source§

fn try_from(operation: Operation<'c>) -> Result<Self, Self::Error>

Performs the conversion.

Auto Trait Implementations§

§

impl<'c> RefUnwindSafe for RewriteOperation<'c>

§

impl<'c> !Send for RewriteOperation<'c>

§

impl<'c> !Sync for RewriteOperation<'c>

§

impl<'c> Unpin for RewriteOperation<'c>

§

impl<'c> UnwindSafe for RewriteOperation<'c>

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.