mirror of
https://github.com/capstone-engine/llvm-capstone.git
synced 2024-12-01 01:31:26 +00:00
Revert "[mlir] Add a postprocessing parameter in Pattern"
This reverts commit02596693fa
. This reverts commit3c5b4dabdc
. 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)>; ^
This commit is contained in:
parent
5d16957207
commit
2d8f793b32
@ -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
|
||||
|
@ -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.
|
||||
|
@ -482,14 +482,6 @@ public:
|
||||
// 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;
|
||||
|
||||
|
@ -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.
|
||||
|
@ -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");
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user