-
Notifications
You must be signed in to change notification settings - Fork 72
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Canonicalizers and Declarative Rewrite Patterns (#19)
* slight formatting changes * Add empty canonicalizers to poly binops * dyn_cast -> dyn_cast_or_null * Canonicalize a difference of squares * upgrade eval to accept complex inputs * Add tablegen pattern to lift conj through eval * add generated patterns to eval canonicalizer * rewrite DifferenceOfSquares in tablegen
- Loading branch information
Showing
6 changed files
with
138 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#ifndef LIB_DIALECT_POLY_POLYPATTERNS_TD_ | ||
#define LIB_DIALECT_POLY_POLYPATTERNS_TD_ | ||
|
||
include "PolyOps.td" | ||
include "mlir/Dialect/Complex/IR/ComplexOps.td" | ||
include "mlir/IR/PatternBase.td" | ||
|
||
def LiftConjThroughEval : Pat< | ||
(Poly_EvalOp $f, (ConjOp $z)), | ||
(ConjOp (Poly_EvalOp $f, $z)) | ||
>; | ||
|
||
def HasOneUse: Constraint<CPred<"$_self.hasOneUse()">, "has one use">; | ||
|
||
// Rewrites (x^2 - y^2) as (x+y)(x-y) if x^2 and y^2 have no other uses. | ||
def DifferenceOfSquares : Pattern< | ||
(Poly_SubOp (Poly_MulOp:$lhs $x, $x), (Poly_MulOp:$rhs $y, $y)), | ||
[ | ||
(Poly_AddOp:$sum $x, $y), | ||
(Poly_SubOp:$diff $x, $y), | ||
(Poly_MulOp:$res $sum, $diff), | ||
], | ||
[(HasOneUse:$lhs), (HasOneUse:$rhs)] | ||
>; | ||
|
||
#endif // LIB_DIALECT_POLY_POLYPATTERNS_TD_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters