pub trait RewritePattern: Pattern {
// Required method
fn match_and_rewrite(
&self,
op: OperationRef,
rewriter: &mut dyn Rewriter,
) -> Result<bool, Report>;
}Expand description
A RewritePattern represents two things:
- A pattern which matches some IR that we’re interested in, typically to replace with something else.
- A rewrite which replaces IR that maches the pattern, with new IR, i.e. a DAG-to-DAG replacement
Required Methods§
Sourcefn match_and_rewrite(
&self,
op: OperationRef,
rewriter: &mut dyn Rewriter,
) -> Result<bool, Report>
fn match_and_rewrite( &self, op: OperationRef, rewriter: &mut dyn Rewriter, ) -> Result<bool, Report>
Attempt to match this pattern against the IR rooted at the specified operation, and rewrite it if the match is successful.
If applied, this rewrites the IR rooted at the matched operation, using the provided Rewriter to generate new blocks and/or operations, or apply any modifications.
If an unexpected error is encountered, i.e. an internal compiler error, it is emitted through the normal diagnostic system, and the IR is left in a valid state.