[Mlir-commits] [mlir] [MLIR][Transform] Add attribute in MatchOp to filter by operand type (PR #67994)
Matthias Springer
llvmlistbot at llvm.org
Mon Dec 4 16:01:28 PST 2023
================
@@ -1180,12 +1181,47 @@ transform::MatchOp::apply(transform::TransformRewriter &rewriter,
return;
}
+ if (getFilterOperandTypes().has_value()) {
+ mlir::ArrayAttr types = getFilterOperandTypes().value();
+ auto operandTypes = op->getOperandTypes();
+
+ if (types.size() == 1) {
+ // All the operands must must be equal to the specified type
+ auto typeattr =
+ dyn_cast<mlir::TypeAttr>(getFilterOperandTypes().value()[0]);
+ Type t = typeattr.getValue().cast<::mlir::Type>();
+ if (!llvm::all_of(op->getOperandTypes(),
+ [&](Type operandType) { return operandType == t; }))
+ return;
+ } else {
+ // The operand types must match all the types in the list (in the same
+ // order in with they are specified)
+ if (types.size() != operandTypes.size()) {
+ incorrectNumOperandTypes = true;
+ return;
+ }
+
+ for (auto [attr, operandType] :
+ llvm::zip_equal(getFilterOperandTypes().value(), operandTypes)) {
+ auto typeattr = dyn_cast<mlir::TypeAttr>(attr);
+ Type type = typeattr.getValue().cast<::mlir::Type>();
----------------
matthias-springer wrote:
Is the cast necessary? Also please write “cast<…>(x)”. the other syntax is deprecated.
https://github.com/llvm/llvm-project/pull/67994
More information about the Mlir-commits
mailing list