From b52d6e9148c6386eabd32858e299ea77a6db5ba0 Mon Sep 17 00:00:00 2001 From: Ashwin Murthy Date: Sat, 4 May 2019 01:00:25 -0700 Subject: [PATCH] [TableGen] Couple of small updates to OpBase Added a definition for the newly added None type. Fix TCopVTEtAreSameAt to be a Predicate rather than a PredOpTrait. This makes it more of a primitive and allows flexible composition. -- PiperOrigin-RevId: 246631975 --- mlir/include/mlir/IR/OpBase.td | 15 ++++++++------- mlir/test/mlir-tblgen/predicate.td | 5 +++-- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/mlir/include/mlir/IR/OpBase.td b/mlir/include/mlir/IR/OpBase.td index 7b2349f..a2b3ca3 100644 --- a/mlir/include/mlir/IR/OpBase.td +++ b/mlir/include/mlir/IR/OpBase.td @@ -250,6 +250,9 @@ class BuildableType { // Any type at all. def AnyType : Type, "any type">; +// None type +def NoneType : Type()">, "none type">; + // Any type from the given list class AnyTypeOf allowedTypes, string description> : Type< // Satisfy any of the allowed type's condition @@ -262,6 +265,7 @@ class AnyTypeOf allowedTypes, string description> : Type< // Otherwise use the provided one description)>; + // Integer types. class IntegerBase : Type; @@ -964,22 +968,19 @@ class TCresVTEtIsSameAsOp : AllOf<[ "getElementType() == $_op.getOperand(" # j # ")->getType()." "cast().getElementType()">]>; -// Predicate OpTrait to verify that all the operands at the given `indices` +// Predicate to verify that all the operands at the given `indices` // have the same element type. // Type Constraint operands' Vector or Tensor Element type are all Same At // the given `indices`. -// +// We query the operands' types into a list and check they are all the same. // Precondition: // 1) all operands involved are of vector or tensor type and // 2) the indices are not out of range. -class TCopVTEtAreSameAt indices = []> : PredOpTrait< - "operands indexed at " # Stringify.result # - " should all have the same type", - // We query the operands' types into a list and check they are all the same. +class TCopVTEtAreSameAt indices> : CPred<"llvm::is_splat(mlir::functional::map(" "[this](unsigned i) { return this->getOperand(i)->getType()" ".cast().getElementType(); }, " - "llvm::ArrayRef({" # Stringify.result # "})))">>; + "llvm::ArrayRef({" # Stringify.result # "})))">; //===----------------------------------------------------------------------===// // Pattern definitions diff --git a/mlir/test/mlir-tblgen/predicate.td b/mlir/test/mlir-tblgen/predicate.td index 8869e5d..e087eea 100644 --- a/mlir/test/mlir-tblgen/predicate.td +++ b/mlir/test/mlir-tblgen/predicate.td @@ -93,8 +93,9 @@ def OpI: NS_Op<"op_for_arr_min_value_at_index", []> { // CHECK: (((tblgen_attr.cast().size() > 0)) && ((tblgen_attr.cast().getValue()[0].cast().getInt() >= 8))))) // CHECK-SAME: return emitOpError("attribute 'attr' failed to satisfy constraint: array attribute whose 0-th element must be at least 8"); -def OpJ: NS_Op<"op_for_TCopVTEtAreSameAt", - [TCopVTEtAreSameAt<[0, 2, 3]>]> { +def OpJ: NS_Op<"op_for_TCopVTEtAreSameAt", [ + PredOpTrait<"operands indexed at 0, 2, 3 should all have " + "the same type", TCopVTEtAreSameAt<[0, 2, 3]>>]> { let arguments = (ins Tensor:$a, Tensor:$b, -- 2.7.4