2019-03-21 08:25:34 +08:00
|
|
|
// RUN: mlir-tblgen -gen-op-defs -I %S/../../include %s | FileCheck %s
|
2019-02-25 20:03:02 +08:00
|
|
|
|
2019-03-02 05:48:24 +08:00
|
|
|
include "mlir/IR/OpBase.td"
|
2019-02-25 20:03:02 +08:00
|
|
|
|
2019-04-30 00:24:09 +08:00
|
|
|
def Test_Dialect : Dialect {
|
|
|
|
let name = "test";
|
|
|
|
}
|
|
|
|
class NS_Op<string mnemonic, list<OpTrait> traits> :
|
|
|
|
Op<Test_Dialect, mnemonic, traits>;
|
|
|
|
|
2019-04-12 21:05:49 +08:00
|
|
|
def I32OrF32 : Type<CPred<"$_self.isInteger(32) || $_self.isF32()">,
|
2019-02-25 20:03:02 +08:00
|
|
|
"32-bit integer or floating-point type">;
|
|
|
|
|
2019-04-30 00:24:09 +08:00
|
|
|
def OpA : NS_Op<"op_for_CPred_containing_multiple_same_placeholder", []> {
|
2019-04-04 19:29:58 +08:00
|
|
|
let arguments = (ins I32OrF32:$x);
|
2019-03-25 10:35:20 +08:00
|
|
|
}
|
|
|
|
|
2019-04-04 19:29:58 +08:00
|
|
|
// CHECK-LABEL: OpA::verify
|
|
|
|
// CHECK: if (!((this->getOperation()->getOperand(0)->getType().isInteger(32) || this->getOperation()->getOperand(0)->getType().isF32())))
|
2019-03-29 10:49:31 +08:00
|
|
|
|
2019-04-30 00:24:09 +08:00
|
|
|
def OpB : NS_Op<"op_for_AllOf_PredOpTrait", [
|
2019-04-04 19:29:58 +08:00
|
|
|
PredOpTrait<"both first and second holds",
|
|
|
|
AllOf<[CPred<"first">, CPred<"second">]>>]> {
|
2019-02-25 20:03:02 +08:00
|
|
|
}
|
|
|
|
|
2019-04-04 19:29:58 +08:00
|
|
|
// CHECK-LABEL: OpB::verify
|
|
|
|
// CHECK: if (!(((first)) && ((second))))
|
|
|
|
|
2019-04-30 00:24:09 +08:00
|
|
|
def OpC : NS_Op<"op_for_TCopVTEtIs", [
|
2019-04-04 19:29:58 +08:00
|
|
|
PredOpTrait<"first operand has i32 element type",
|
|
|
|
TCopVTEtIs<0, I32>>]> {
|
2019-03-23 06:26:05 +08:00
|
|
|
let arguments = (ins Tensor:$x);
|
|
|
|
}
|
|
|
|
|
2019-04-04 19:29:58 +08:00
|
|
|
// CHECK-LABEL: OpC::verify
|
|
|
|
// CHECK: if (!((((*this->getOperation()).getNumOperands() > 0)) && (((*this->getOperation()).getOperand(0)->getType().isa<VectorOrTensorType>())) && (((*this->getOperation()).getOperand(0)->getType().cast<VectorOrTensorType>().getElementType().isInteger(32)))))
|
|
|
|
|
|
|
|
|
2019-04-30 00:24:09 +08:00
|
|
|
def OpD : NS_Op<"op_for_TCOpVTEtIsSameAs", [
|
2019-04-04 19:29:58 +08:00
|
|
|
PredOpTrait<"first operand is a vector or tensor with the same "
|
|
|
|
"elemental type as itself",
|
|
|
|
TCopVTEtIsSameAs<0, 0>>]> {
|
|
|
|
let arguments = (ins Tensor:$x);
|
|
|
|
}
|
2019-03-25 10:35:20 +08:00
|
|
|
|
2019-04-04 19:29:58 +08:00
|
|
|
// CHECK-LABEL: OpD::verify
|
2019-03-27 08:05:09 +08:00
|
|
|
// CHECK: if (!((((*this->getOperation()).getNumOperands() > std::max(0,0))) && (((*this->getOperation()).getOperand(0)->getType().isa<VectorOrTensorType>())) && (((*this->getOperation()).getOperand(0)->getType().isa<VectorOrTensorType>())) && (((*this->getOperation()).getOperand(0)->getType().cast<VectorOrTensorType>().getElementType() == (*this->getOperation()).getOperand(0)->getType().cast<VectorOrTensorType>().getElementType()))))
|
2019-03-23 06:26:05 +08:00
|
|
|
// CHECK-NEXT: return emitOpError("failed to verify that first operand is a vector or tensor with the same elemental type as itself");
|
2019-04-04 19:29:58 +08:00
|
|
|
|
|
|
|
|
2019-04-30 00:24:09 +08:00
|
|
|
def OpE : NS_Op<"op_for_TCresVTEtIsSameAsOp", [
|
2019-04-04 19:29:58 +08:00
|
|
|
PredOpTrait<"first operand is a vector or tensor with the same "
|
|
|
|
"elemental type as first result",
|
|
|
|
TCresVTEtIsSameAsOp<0, 0>>]> {
|
|
|
|
let arguments = (ins Tensor:$x);
|
|
|
|
let results = (outs Tensor:$y);
|
|
|
|
}
|
|
|
|
|
|
|
|
// CHECK-LABEL: OpE::verify
|
2019-03-29 10:49:31 +08:00
|
|
|
// CHECK: if (!((((*this->getOperation()).getNumResults() > 0)) && (((*this->getOperation()).getNumOperands() > 0)) && (((*this->getOperation()).getResult(0)->getType().isa<VectorOrTensorType>())) && (((*this->getOperation()).getOperand(0)->getType().isa<VectorOrTensorType>())) && (((*this->getOperation()).getResult(0)->getType().cast<VectorOrTensorType>().getElementType() == (*this->getOperation()).getOperand(0)->getType().cast<VectorOrTensorType>().getElementType()))))
|
|
|
|
// CHECK-NEXT: return emitOpError("failed to verify that first operand is a vector or tensor with the same elemental type as first result");
|
2019-03-23 06:26:05 +08:00
|
|
|
|
2019-04-02 08:40:58 +08:00
|
|
|
|
2019-04-30 00:24:09 +08:00
|
|
|
def OpF : NS_Op<"op_for_int_min_val", []> {
|
2019-04-02 08:40:58 +08:00
|
|
|
let arguments = (ins Confined<I32Attr, [IntMinValue<10>]>:$attr);
|
|
|
|
}
|
|
|
|
|
2019-04-04 19:29:58 +08:00
|
|
|
// CHECK-LABEL: OpF::verify()
|
|
|
|
// CHECK: (tblgen_attr.cast<IntegerAttr>().getInt() >= 10)
|
2019-04-05 00:25:38 +08:00
|
|
|
// CHECK-SAME: return emitOpError("attribute 'attr' failed to satisfy constraint: 32-bit integer attribute whose minimal value is 10");
|
2019-04-02 08:40:58 +08:00
|
|
|
|
2019-04-30 00:24:09 +08:00
|
|
|
def OpG : NS_Op<"op_for_arr_min_count", []> {
|
2019-04-02 08:40:58 +08:00
|
|
|
let arguments = (ins Confined<ArrayAttr, [ArrayMinCount<8>]>:$attr);
|
|
|
|
}
|
|
|
|
|
2019-04-04 19:29:58 +08:00
|
|
|
// CHECK-LABEL: OpG::verify()
|
|
|
|
// CHECK: (tblgen_attr.cast<ArrayAttr>().size() >= 8)
|
2019-04-05 00:25:38 +08:00
|
|
|
// CHECK-SAME: return emitOpError("attribute 'attr' failed to satisfy constraint: array attribute with at least 8 elements");
|
2019-04-06 06:51:47 +08:00
|
|
|
|
2019-04-30 00:24:09 +08:00
|
|
|
def OpH : NS_Op<"op_for_arr_value_at_index", []> {
|
2019-04-06 06:51:47 +08:00
|
|
|
let arguments = (ins Confined<ArrayAttr, [IntArrayNthElemEq<0, 8>]>:$attr);
|
|
|
|
}
|
|
|
|
|
|
|
|
// CHECK-LABEL: OpH::verify()
|
|
|
|
// CHECK: (((tblgen_attr.cast<ArrayAttr>().size() > 0)) && ((tblgen_attr.cast<ArrayAttr>().getValue()[0].cast<IntegerAttr>().getInt() == 8)))))
|
|
|
|
// CHECK-SAME: return emitOpError("attribute 'attr' failed to satisfy constraint: array attribute whose 0-th element must be 8");
|
|
|
|
|
2019-04-30 00:24:09 +08:00
|
|
|
def OpI: NS_Op<"op_for_arr_min_value_at_index", []> {
|
2019-04-06 06:51:47 +08:00
|
|
|
let arguments = (ins Confined<ArrayAttr, [IntArrayNthElemMinValue<0, 8>]>:$attr);
|
|
|
|
}
|
|
|
|
|
|
|
|
// CHECK-LABEL: OpI::verify()
|
|
|
|
// CHECK: (((tblgen_attr.cast<ArrayAttr>().size() > 0)) && ((tblgen_attr.cast<ArrayAttr>().getValue()[0].cast<IntegerAttr>().getInt() >= 8)))))
|
|
|
|
// CHECK-SAME: return emitOpError("attribute 'attr' failed to satisfy constraint: array attribute whose 0-th element must be at least 8");
|