[Mlir-commits] [mlir] 2d8f793 - Revert "[mlir] Add a postprocessing parameter in Pattern"
Mehdi Amini
llvmlistbot at llvm.org
Tue Aug 15 15:51:29 PDT 2023
Author: Mehdi Amini
Date: 2023-08-15T15:50:29-07:00
New Revision: 2d8f793b32bc1c7cff54a7a5f372e4c785a0b8dc
URL: https://github.com/llvm/llvm-project/commit/2d8f793b32bc1c7cff54a7a5f372e4c785a0b8dc
DIFF: https://github.com/llvm/llvm-project/commit/2d8f793b32bc1c7cff54a7a5f372e4c785a0b8dc.diff
LOG: Revert "[mlir] Add a postprocessing parameter in Pattern"
This reverts commit 02596693fac55f550e85620f5184547c80c8f930.
This reverts commit 3c5b4dabdc06dd380391ac965b16961610c0db77.
The build is broken:
mlir/test/lib/Dialect/Test/TestOps.td:988:7: error: Value specified for template argument 'Pat:supplemental_results' is of type dag; expected type list<dag>: (addBenefit 10)
def : Pat<(OpD $input), (OpF $input), [], (addBenefit 10)>;
^
Added:
Modified:
mlir/docs/DeclarativeRewrites.md
mlir/include/mlir/IR/PatternBase.td
mlir/include/mlir/TableGen/Pattern.h
mlir/lib/TableGen/Pattern.cpp
mlir/tools/mlir-tblgen/RewriterGen.cpp
Removed:
################################################################################
diff --git a/mlir/docs/DeclarativeRewrites.md b/mlir/docs/DeclarativeRewrites.md
index dd996baf3cd957..6a9016a47cf463 100644
--- a/mlir/docs/DeclarativeRewrites.md
+++ b/mlir/docs/DeclarativeRewrites.md
@@ -59,13 +59,12 @@ features:
## Rule Definition
The core construct for defining a rewrite rule is defined in
-[`PatternBase.td`][PatternBase] as
+[`OpBase.td`][OpBase] as
```tablegen
class Pattern<
dag sourcePattern, list<dag> resultPatterns,
list<dag> additionalConstraints = [],
- list<dag> supplementalPatterns = [],
dag benefitsAdded = (addBenefit 0)>;
```
@@ -679,36 +678,6 @@ You can
* Apply constraints on multiple bound symbols (`$input` and `TwoResultOp`'s
first result must have the same element type).
-### Supplying additional result patterns
-
-Sometimes we need to add additional code after the result patterns, e.g. coping
-the attributes of the source op to the result ops. These can be specified via
-`SupplementalPatterns` parameter. Similar to auxiliary patterns, they are not
-for replacing results in the source pattern.
-
-For example, we can write
-
-```tablegen
-def GetOwner: NativeCodeCall<"$0.getOwner()">;
-
-def CopyAttrFoo: NativeCodeCallVoid<
- "$1->setAttr($_builder.getStringAttr(\"foo\"), $0->getAttr(\"foo\"))">;
-
-def CopyAttrBar: NativeCodeCallVoid<
- "$1->setAttr($_builder.getStringAttr(\"bar\"), $0->getAttr(\"bar\"))">;
-
-
-def : Pattern<
- (ThreeResultOp:$src ...),
- [(ZeroResultOp:$dest1 ...), (ThreeResultOp:$dest2 ...)],
- [(CopyAttrFoo (GetOwner $src), $dest1),
- (CopyAttrBar (GetOwner $src), (GetOwner $dest2))]>;
-```
-
-This will copy the attribute `foo` and `bar` of `ThreeResultOp` in the source
-pattern to `ZeroResultOp` and `ThreeResultOp` in the result patterns respectively.
-The patterns are executed in specified order.
-
### Adjusting benefits
The benefit of a `Pattern` is an integer value indicating the benefit of
diff --git a/mlir/include/mlir/IR/PatternBase.td b/mlir/include/mlir/IR/PatternBase.td
index 919fb884adb0e9..c6ab1b5a91b58b 100644
--- a/mlir/include/mlir/IR/PatternBase.td
+++ b/mlir/include/mlir/IR/PatternBase.td
@@ -90,7 +90,6 @@ def addBenefit;
// * `FiveResultOp`#3: `TwoResultOp2`#1
// * `FiveResultOp`#4: `TwoResultOp2`#1
class Pattern<dag source, list<dag> results, list<dag> preds = [],
- list<dag> supplemental_results = [],
dag benefitAdded = (addBenefit 0)> {
dag sourcePattern = source;
// Result patterns. Each result pattern is expected to replace one result
@@ -104,11 +103,6 @@ class Pattern<dag source, list<dag> results, list<dag> preds = [],
// matched in source pattern and places further constraints on them as a
// whole.
list<dag> constraints = preds;
- // Optional patterns that are executed after the result patterns. Similar to
- // auxiliary patterns, they are not used for replacement. These patterns can
- // be used to invoke additional code after the result patterns, e.g. copy
- // the attributes from the source op to the result ops.
- list<dag> supplementalPatterns = supplemental_results;
// The delta value added to the default benefit value. The default value is
// the number of ops in the source pattern. The rule with the highest final
// benefit value will be applied first if there are multiple rules matches.
@@ -118,9 +112,8 @@ class Pattern<dag source, list<dag> results, list<dag> preds = [],
// Form of a pattern which produces a single result.
class Pat<dag pattern, dag result, list<dag> preds = [],
- list<dag> supplemental_results = [],
dag benefitAdded = (addBenefit 0)> :
- Pattern<pattern, [result], preds, supplemental_results, benefitAdded>;
+ Pattern<pattern, [result], preds, benefitAdded>;
// Native code call wrapper. This allows invoking an arbitrary C++ expression
// to create an op operand/attribute or replace an op result.
diff --git a/mlir/include/mlir/TableGen/Pattern.h b/mlir/include/mlir/TableGen/Pattern.h
index 4511ba7dd833ef..b17932095f9620 100644
--- a/mlir/include/mlir/TableGen/Pattern.h
+++ b/mlir/include/mlir/TableGen/Pattern.h
@@ -482,14 +482,6 @@ class Pattern {
// Returns the constraints.
std::vector<AppliedConstraint> getConstraints() const;
- // Returns the number of supplemental auxiliary patterns generated by applying
- // this rewrite rule.
- int getNumSupplementalPatterns() const;
-
- // Returns the DAG tree root node of the `index`-th supplemental result
- // pattern.
- DagNode getSupplementalPattern(unsigned index) const;
-
// Returns the benefit score of the pattern.
int getBenefit() const;
diff --git a/mlir/lib/TableGen/Pattern.cpp b/mlir/lib/TableGen/Pattern.cpp
index d9e1d6c7f89152..e8625b2e6b7102 100644
--- a/mlir/lib/TableGen/Pattern.cpp
+++ b/mlir/lib/TableGen/Pattern.cpp
@@ -675,16 +675,6 @@ std::vector<AppliedConstraint> Pattern::getConstraints() const {
return ret;
}
-int Pattern::getNumSupplementalPatterns() const {
- auto *results = def.getValueAsListInit("supplementalPatterns");
- return results->size();
-}
-
-DagNode Pattern::getSupplementalPattern(unsigned index) const {
- auto *results = def.getValueAsListInit("supplementalPatterns");
- return DagNode(cast<llvm::DagInit>(results->getElement(index)));
-}
-
int Pattern::getBenefit() const {
// The initial benefit value is a heuristic with number of ops in the source
// pattern.
diff --git a/mlir/tools/mlir-tblgen/RewriterGen.cpp b/mlir/tools/mlir-tblgen/RewriterGen.cpp
index 8b5ef5c6e01829..9cd4414bf99d7e 100644
--- a/mlir/tools/mlir-tblgen/RewriterGen.cpp
+++ b/mlir/tools/mlir-tblgen/RewriterGen.cpp
@@ -1105,17 +1105,6 @@ void PatternEmitter::emitRewriteLogic() {
os << "\nrewriter.replaceOp(op0, tblgen_repl_values);\n";
}
- // Process supplemtal patterns.
- int numSupplementalPatterns = pattern.getNumSupplementalPatterns();
- for (int i = 0, offset = -numSupplementalPatterns;
- i < numSupplementalPatterns; ++i) {
- DagNode resultTree = pattern.getSupplementalPattern(i);
- auto val = handleResultPattern(resultTree, offset++, 0);
- if (resultTree.isNativeCodeCall() &&
- resultTree.getNumReturnsOfNativeCode() == 0)
- os << val << ";\n";
- }
-
LLVM_DEBUG(llvm::dbgs() << "--- done emitting rewrite logic ---\n");
}
More information about the Mlir-commits
mailing list