[Mlir-commits] [mlir] [mlir] NFC: Abstract NamedTypeSatisfiesPred and reuse TypeIsPred (PR #201814)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Fri Jun 5 04:39:20 PDT 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-mlir
Author: ConvolutedDog
<details>
<summary>Changes</summary>
Abstract NamedTypeSatisfiesPred to encapsulate checking a named
operand/result's type against an arbitrary Pred.
---
Full diff: https://github.com/llvm/llvm-project/pull/201814.diff
2 Files Affected:
- (modified) mlir/include/mlir/Dialect/Arith/IR/ArithOps.td (+2-2)
- (modified) mlir/include/mlir/IR/OpBase.td (+15-12)
``````````diff
diff --git a/mlir/include/mlir/Dialect/Arith/IR/ArithOps.td b/mlir/include/mlir/Dialect/Arith/IR/ArithOps.td
index 1f8b07aed3f0d..94c7699fd43da 100644
--- a/mlir/include/mlir/Dialect/Arith/IR/ArithOps.td
+++ b/mlir/include/mlir/Dialect/Arith/IR/ArithOps.td
@@ -2008,8 +2008,8 @@ class BooleanConditionOrMatchingShape<string condition, string result> :
PredOpTrait<
condition # " is signless i1 or has matching shape",
Or<[TypeIsPred<condition, I1>,
- And<[SubstLeaves<"$_self", "$" # condition # ".getType()", IsShapedTypePred>,
- SubstLeaves<"$_self", "$" # result # ".getType()", IsShapedTypePred>,
+ And<[NamedTypeSatisfiesPred<condition, IsShapedTypePred>,
+ NamedTypeSatisfiesPred<result, IsShapedTypePred>,
AllShapesMatch<[condition, result]>.predicate]>]>>;
def SelectOp : Arith_Op<"select", [Pure,
diff --git a/mlir/include/mlir/IR/OpBase.td b/mlir/include/mlir/IR/OpBase.td
index 0d0669e90c3f7..032242be768ac 100644
--- a/mlir/include/mlir/IR/OpBase.td
+++ b/mlir/include/mlir/IR/OpBase.td
@@ -633,14 +633,25 @@ class RangedTypesMatchWith<string summary, string lhsArg, string rhsArg,
string transform>
: TypesMatchWith<summary, lhsArg, rhsArg, transform, "llvm::equal">;
+// Predicate to verify that a named argument or result's type satisfies a given
+// predicate.
+class NamedTypeSatisfiesPred<string name, Pred pred> :
+ SubstLeaves<"$_self", "$" # name # ".getType()", pred>;
+
+// Predicate to verify that a named argument or result's type matches a given
+// type constraint.
+class TypeIsPred<string name, Type type> :
+ NamedTypeSatisfiesPred<name, type.predicate>;
+class TypeIs<string name, Type type> : PredOpTrait<
+ "'" # name # "' is " # type.summary, TypeIsPred<name, type>>;
+
// Checks that each inputArg has the same type as the corresponding entry
// in allowedTypes
class InputMatchesTypes<list<string> inputArgs, list<Type> allowedTypes> :
PredOpTrait<"operands {" # !interleave(inputArgs, ", ") # "} match expected types",
!foldl(TruePred, !range(!size(inputArgs)), acc, i,
And<[acc,
- SubstLeaves<"$_self", "$" # inputArgs[i] # ".getType()",
- allowedTypes[i].predicate>
+ TypeIsPred<inputArgs[i], allowedTypes[i]>
]>)> {
assert !eq(!size(inputArgs), !size(allowedTypes)),
"inputArgs and allowedTypes lists must have the same length";
@@ -661,8 +672,7 @@ class InputAddressIsCombinationOf<list<string> inputArgs,
Or<!foreach(combination, allowedCombinations,
!foldl(TruePred, !range(!size(inputArgs)), acc, i,
And<[acc,
- SubstLeaves<"$_self", "$" # inputArgs[i] # ".getType()",
- combination[i].predicate>
+ TypeIsPred<inputArgs[i], combination[i]>
]>))>> {
assert !gt(!size(allowedCombinations), 0),
"allowedCombinations must not be empty";
@@ -686,17 +696,10 @@ class TCopVTEtIs<int idx, Type type> : And<[
SubstLeaves<"$_self", "getElementTypeOrSelf($_op.getOperand(" # idx # "))",
type.predicate>]>;
-// Predicate to verify that a named argument or result's element type matches a
-// given type.
-class TypeIsPred<string name, Type type> :
- SubstLeaves<"$_self", "$" # name # ".getType()", type.predicate>;
-class TypeIs<string name, Type type> : PredOpTrait<
- "'" # name # "' is " # type.summary, TypeIsPred<name, type>>;
-
// Predicate to verify that a named argument or result's element type matches a
// given type.
class ElementTypeIsPred<string name, Type type> : And<[
- SubstLeaves<"$_self", "$" # name # ".getType()", IsShapedTypePred>,
+ NamedTypeSatisfiesPred<name, IsShapedTypePred>,
SubstLeaves<"$_self", "getElementTypeOrSelf($" # name # ")",
type.predicate>]>;
class ElementTypeIs<string name, Type type> : PredOpTrait<
``````````
</details>
https://github.com/llvm/llvm-project/pull/201814
More information about the Mlir-commits
mailing list