[mlir][Linalg] Allow transformation filter to match by default.

The current setup of LinalgTransformationFilter allows a
transformation to trigger when either
1) The StringAttr is not set and no filter identifier is specified.
2) The StringAttr is set and its value matches (one of) the provided
identifier.
This misses the case where the transformation should trigger either
when the attribute is not set or its value matches (one of) the
provided identifier. Since `Identifier` does not allow empty strings,
add a boolean option to match when the attribute is not set. This
option is by default off.

Differential Revision: https://reviews.llvm.org/D113057
This commit is contained in:
MaheshRavishankar 2021-11-02 15:58:38 -07:00
parent ba7a6b314f
commit 3ecc2a63eb
2 changed files with 10 additions and 3 deletions

View File

@ -448,11 +448,18 @@ struct LinalgTransformationFilter {
return addFilter(
[](Operation *op) { return success(isa<OpTypes...>(op)); });
}
LinalgTransformationFilter &setMatchByDefault() {
matchByDefault = true;
return *this;
}
private:
SmallVector<FilterFunction> filters;
SmallVector<Identifier> matchDisjunction;
Optional<Identifier> replacement;
/// When set to true, if the attribute is not set, it will be treated as
/// a match. Default is false.
bool matchByDefault;
};
using TileSizeComputationFunction =

View File

@ -51,14 +51,14 @@ const StringLiteral mlir::linalg::LinalgTransforms::kLinalgTransformMarker =
mlir::linalg::LinalgTransformationFilter::LinalgTransformationFilter(
ArrayRef<Identifier> matchDisjunction, Optional<Identifier> replacement)
: matchDisjunction(matchDisjunction.begin(), matchDisjunction.end()),
replacement(replacement) {}
replacement(replacement), matchByDefault(false) {}
mlir::linalg::LinalgTransformationFilter::LinalgTransformationFilter(
FilterFunction f, ArrayRef<Identifier> matchDisjunction,
Optional<Identifier> replacement)
: filters(),
matchDisjunction(matchDisjunction.begin(), matchDisjunction.end()),
replacement(replacement) {
replacement(replacement), matchByDefault(false) {
if (f)
filters.push_back(f);
}
@ -74,7 +74,7 @@ LogicalResult mlir::linalg::LinalgTransformationFilter::checkAndNotify(
if (!attr) {
// 1. Has no filter case and matchDisjunction is empty.
if (matchDisjunction.empty())
if (matchDisjunction.empty() || matchByDefault)
return success();
// 2. Has no filter but was expecting a filter.