[Mlir-commits] [mlir] 281e0f3 - [mlir] Simplify DDR matching patterns with equal operands for operators where it's applicable. Added documentation.
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Wed Oct 21 14:32:19 PDT 2020
Author: rdzhabarov
Date: 2020-10-21T21:31:39Z
New Revision: 281e0f3636a3169df88965632579701b101be51f
URL: https://github.com/llvm/llvm-project/commit/281e0f3636a3169df88965632579701b101be51f
DIFF: https://github.com/llvm/llvm-project/commit/281e0f3636a3169df88965632579701b101be51f.diff
LOG: [mlir] Simplify DDR matching patterns with equal operands for operators where it's applicable. Added documentation.
This https://reviews.llvm.org/D89254 diff introduced implicit matching between same name operands.
Differential Revision: https://reviews.llvm.org/D89598
Added:
Modified:
mlir/docs/DeclarativeRewrites.md
mlir/include/mlir/IR/OpBase.td
mlir/lib/Dialect/Shape/IR/ShapeCanonicalization.td
Removed:
################################################################################
diff --git a/mlir/docs/DeclarativeRewrites.md b/mlir/docs/DeclarativeRewrites.md
index 7e4f675166ab..81a20f3c29f9 100644
--- a/mlir/docs/DeclarativeRewrites.md
+++ b/mlir/docs/DeclarativeRewrites.md
@@ -136,9 +136,11 @@ and `$attr` in result patterns and additional constraints.
The pattern is position-based: the symbol names used for capturing here do not
need to match with the op definition as shown in the above example. As another
-example, the pattern can be written as ` def : Pat<(AOp $a, F32Attr:$b), ...>;`
+example, the pattern can be written as `def : Pat<(AOp $a, F32Attr:$b), ...>;`
and use `$a` and `$b` to refer to the captured input and attribute. But using
-the ODS name directly in the pattern is also allowed.
+the ODS name directly in the pattern is also allowed. Operands in the source
+pattern can have the same name. This bounds one operand to the name while
+verifying the rest are all equal.
Also note that we only need to add `TypeConstraint` or `AttributeConstraint`
when we need to further limit the match criteria. If all valid cases to the op
diff --git a/mlir/include/mlir/IR/OpBase.td b/mlir/include/mlir/IR/OpBase.td
index 82ef2dffca06..48412e9229a1 100644
--- a/mlir/include/mlir/IR/OpBase.td
+++ b/mlir/include/mlir/IR/OpBase.td
@@ -2292,8 +2292,11 @@ def addBenefit;
//
// In the source pattern, `argN` can be used to specify matchers (e.g., using
// type/attribute type constraints, etc.) and bound to a name for later use.
-// We can also bound names to op instances to reference them later in
-// multi-entity constraints.
+// We can also bind names to op instances to reference them later in
+// multi-entity constraints. Operands in the source pattern can have
+// the same name. This bounds one operand to the name while verifying
+// the rest are all equal.
+//
//
// In the result pattern, `argN` can be used to refer to a previously bound
// name, with potential transformations (e.g., using tAttr, etc.). `argN` can
@@ -2303,16 +2306,18 @@ def addBenefit;
// For example,
//
// ```
-// def : Pattern<(OneResultOp1:$op1 $arg0, $arg1),
+// def : Pattern<(OneResultOp1:$op1 $arg0, $arg1, $arg0),
// [(OneResultOp2:$op2 $arg0, $arg1),
// (OneResultOp3 $op2 (OneResultOp4))],
// [(HasStaticShapePred $op1)]>;
// ```
//
-// `$argN` is bound to the `OneResultOp1`'s N-th argument and used later to
-// build `OneResultOp2`. `$op1` is bound to `OneResultOp1` and used to
-// check whether the result's shape is static. `$op2` is bound to
-// `OneResultOp2` and used to build `OneResultOp3`.
+// First `$arg0` and '$arg1' are bound to the `OneResultOp1`'s first
+// and second arguments and used later to build `OneResultOp2`. Second '$arg0'
+// is verified to be equal to the first '$arg0' operand.
+// `$op1` is bound to `OneResultOp1` and used to check whether the result's
+// shape is static. `$op2` is bound to `OneResultOp2` and used to
+// build `OneResultOp3`.
//
// ## Multi-result op
//
diff --git a/mlir/lib/Dialect/Shape/IR/ShapeCanonicalization.td b/mlir/lib/Dialect/Shape/IR/ShapeCanonicalization.td
index b03e51299907..c57ad8c8d17c 100644
--- a/mlir/lib/Dialect/Shape/IR/ShapeCanonicalization.td
+++ b/mlir/lib/Dialect/Shape/IR/ShapeCanonicalization.td
@@ -1,7 +1,5 @@
include "mlir/Dialect/Shape/IR/ShapeOps.td"
-def EqualBinaryOperands : Constraint<CPred<"$0 == $1">>;
-
def AllInputShapesEq : Constraint<CPred< [{
llvm::all_of($0, [&](mlir::Value val) {
return $0[0] == val;
@@ -10,9 +8,8 @@ def AllInputShapesEq : Constraint<CPred< [{
// Canonicalization patterns.
-def CstrBroadcastableEqOps : Pat<(Shape_CstrBroadcastableOp:$op $lhs, $rhs),
- (Shape_ConstWitnessOp ConstBoolAttrTrue),
- [(EqualBinaryOperands $lhs, $rhs)]>;
+def CstrBroadcastableEqOps : Pat<(Shape_CstrBroadcastableOp:$op $x, $x),
+ (Shape_ConstWitnessOp ConstBoolAttrTrue)>;
def CstrEqEqOps : Pat<(Shape_CstrEqOp:$op $shapes),
(Shape_ConstWitnessOp ConstBoolAttrTrue),
More information about the Mlir-commits
mailing list