forked from OSchip/llvm-project
Add a TypeIsPred.
Mostly one would use the type specification directly on the operand, but for cases where the type of the operand depends on other operand types, `TypeIs` attribute can be used to construct verification methods. PiperOrigin-RevId: 258411758
This commit is contained in:
parent
a6d2223584
commit
ffc0217bc7
|
@ -1170,6 +1170,13 @@ 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.description, 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<[
|
||||
|
|
|
@ -187,6 +187,15 @@ def OperandOneAndResultHaveSameType :
|
|||
let results = (outs AnyTensor:$res);
|
||||
}
|
||||
|
||||
def IfFirstOperandIsNoneThenSoIsSecond :
|
||||
TEST_Op<"if_first_operand_is_none_then_so_is_second", [PredOpTrait<
|
||||
"has either both none type operands or first is not none",
|
||||
Or<[
|
||||
And<[TypeIsPred<"x", NoneType>, TypeIsPred<"y", NoneType>]>,
|
||||
Neg<TypeIsPred<"x", NoneType>>]>>]> {
|
||||
let arguments = (ins AnyType:$x, AnyType:$y);
|
||||
}
|
||||
|
||||
//===----------------------------------------------------------------------===//
|
||||
// Test Patterns
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
|
|
@ -174,3 +174,11 @@ func @same_types_shape_mismatch(%arg0: tensor<1x2xi32>, %arg1: tensor<2x1xi32>)
|
|||
%0 = "test.operand_one_and_result_have_same_type"(%arg0, %arg1) : (tensor<1x2xi32>, tensor<2x1xi32>) -> tensor<2x1xi32>
|
||||
return
|
||||
}
|
||||
|
||||
// -----
|
||||
|
||||
func @does_not_have_i32(%arg0: tensor<1x2xi32>, %arg1: none) {
|
||||
// expected-error@+1 {{either both none type operands or first is not none}}
|
||||
"test.if_first_operand_is_none_then_so_is_second"(%arg1, %arg0) : (none, tensor<1x2xi32>) -> ()
|
||||
return
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue