brintos

brintos / llvm-project-archived public Read only

0
0
Text · 6.1 KiB · 7cc9633 Raw
109 lines · plain
1// RUN: mlir-tblgen -gen-op-defs -I %S/../../include %s | FileCheck %s2 3include "mlir/IR/Constraints.td"4include "mlir/IR/EnumAttr.td"5include "mlir/IR/OpBase.td"6include "mlir/IR/Properties.td"7 8def Test_Dialect : Dialect {9  let name = "test";10  let cppNamespace = "foobar";11}12class NS_Op<string mnemonic, list<Trait> traits = []> :13    Op<Test_Dialect, mnemonic, traits>;14 15def NonNegativeI64Prop : ConfinedProp<I64Prop,16  CPred<"$_self >= 0">, "non-negative int64_t">;17 18class NonEmptyArray<Property p> : ConfinedProp19    <ArrayProp<p>, Neg<CPred<"$_self.empty()">>,20    "non-empty array of " # p.summary>;21 22def OpWithPredicates : NS_Op<"op_with_predicates"> {23  let arguments = (ins24    NonNegativeI64Prop:$scalar,25    OptionalProp<NonNegativeI64Prop>:$optional,26    DefaultValuedProp<NonNegativeI64Prop, "0">:$defaulted,27    ConfinedProp<NonNegativeI64Prop,28      CPred<"$_self <= 5">, "between 0 and 5">:$moreConstrained,29    ArrayProp<NonNegativeI64Prop>:$array,30    NonEmptyArray<I64Prop>:$non_empty_unconstrained,31    NonEmptyArray<NonNegativeI64Prop>:$non_empty_constrained,32    // Test applying predicates when the fromStorage() on the optional<> isn't trivial.33    OptionalProp<NonEmptyArray<NonNegativeI64Prop>>:$non_empty_optional,34    I64Prop:$unconstrained35  );36}37 38// CHECK-LABEL: static ::llvm::LogicalResult __mlir_ods_local_prop_constraint_op2Dproperties2Dpredicates139// CHECK-NEXT: int64_t prop40// CHECK-NEXT: if (!((prop >= 0)))41// CHECK: failed to satisfy constraint: non-negative int64_t42 43// CHECK-LABEL: static ::llvm::LogicalResult __mlir_ods_local_prop_constraint_op2Dproperties2Dpredicates244// CHECK-NEXT: std::optional<int64_t> prop45// CHECK-NEXT: if (!(((!prop.has_value())) || (((*(prop)) >= 0))))46// CHECK: failed to satisfy constraint: optional non-negative int64_t47 48// CHECK-LABEL: static ::llvm::LogicalResult __mlir_ods_local_prop_constraint_op2Dproperties2Dpredicates349// CHECK-NEXT: int64_t prop50// CHECK-NEXT: if (!(((prop >= 0)) && ((prop <= 5))))51// CHECK: failed to satisfy constraint: between 0 and 552 53// CHECK-LABEL: static ::llvm::LogicalResult __mlir_ods_local_prop_constraint_op2Dproperties2Dpredicates454// CHECK-NEXT: ::llvm::ArrayRef<int64_t> prop55// CHECK-NEXT: (!(::llvm::all_of(prop, [](const int64_t& baseStore) -> bool { return [](int64_t baseIface) -> bool { return ((baseIface >= 0)); }(baseStore); })))56// CHECK: failed to satisfy constraint: array of non-negative int64_t57 58// CHECK-LABEL: static ::llvm::LogicalResult __mlir_ods_local_prop_constraint_op2Dproperties2Dpredicates559// CHECK-NEXT: ::llvm::ArrayRef<int64_t> prop60// CHECK-NEXT: if (!(!((prop.empty()))))61// CHECK: failed to satisfy constraint: non-empty array of int64_t62 63// CHECK-LABEL: static ::llvm::LogicalResult __mlir_ods_local_prop_constraint_op2Dproperties2Dpredicates664// CHECK-NEXT: ::llvm::ArrayRef<int64_t> prop65// CHECX-NEXT: if (!((::llvm::all_of(prop, [](const int64_t& baseStore) -> bool { return [](int64_t baseIface) -> bool { return ((baseIface >= 0)); }(baseStore); })) && (!((prop.empty())))))66// CHECK: failed to satisfy constraint: non-empty array of non-negative int64_t67 68// CHECK-LABEL: static ::llvm::LogicalResult __mlir_ods_local_prop_constraint_op2Dproperties2Dpredicates769// CHECK-NEXT: std::optional<::llvm::ArrayRef<int64_t>> prop70// CHECK-NEXT: if (!(((!prop.has_value())) || ((::llvm::all_of((*(prop)), [](const int64_t& baseStore) -> bool { return [](int64_t baseIface) -> bool { return ((baseIface >= 0)); }(baseStore); })) && (!(((*(prop)).empty()))))))71// CHECK: failed to satisfy constraint: optional non-empty array of non-negative int64_72 73// CHECK-LABEL: ::llvm::LogicalResult OpWithPredicatesAdaptor::verify74// Note: comprehensive emission of verifiers is tested in verifyINvariantsImpl() below75// CHECK: int64_t tblgen_scalar = this->getScalar();76// CHECK: if (!((tblgen_scalar >= 0)))77// CHECK: return emitError(loc, "'test.op_with_predicates' op property 'scalar' failed to satisfy constraint: non-negative int64_t");78 79// CHECK-LABEL: OpWithPredicates::verifyInvariantsImpl()80// Note: for test readability, we capture [[maybe_unused]] into the variable maybe_unused81// CHECK: [[maybe_unused:\[\[maybe_unused\]\]]] int64_t tblgen_scalar = this->getScalar();82// CHECK: if (::mlir::failed(__mlir_ods_local_prop_constraint_op2Dproperties2Dpredicates1(*this, tblgen_scalar, "scalar")))83// CHECK-NEXT:  return ::mlir::failure()84 85// CHECK: [[maybe_unused]] std::optional<int64_t> tblgen_optional = this->getOptional();86// CHECK: if (::mlir::failed(__mlir_ods_local_prop_constraint_op2Dproperties2Dpredicates2(*this, tblgen_optional, "optional")))87 88// COM: The predicates for "scalar" and "defaulted" are uniqued89// CHECK: [[maybe_unused]] int64_t tblgen_defaulted = this->getDefaulted();90// CHECK: if (::mlir::failed(__mlir_ods_local_prop_constraint_op2Dproperties2Dpredicates1(*this, tblgen_defaulted, "defaulted")))91 92// CHECK: [[maybe_unused]] int64_t tblgen_moreConstrained = this->getMoreConstrained();93// CHECK: if (::mlir::failed(__mlir_ods_local_prop_constraint_op2Dproperties2Dpredicates3(*this, tblgen_moreConstrained, "moreConstrained")))94 95// CHECK: [[maybe_unused]] ::llvm::ArrayRef<int64_t> tblgen_array = this->getArray();96// CHECK: if (::mlir::failed(__mlir_ods_local_prop_constraint_op2Dproperties2Dpredicates4(*this, tblgen_array, "array")))97 98// CHECK: [[maybe_unused]] ::llvm::ArrayRef<int64_t> tblgen_nonEmptyUnconstrained = this->getNonEmptyUnconstrained();99// CHECK: if (::mlir::failed(__mlir_ods_local_prop_constraint_op2Dproperties2Dpredicates5(*this, tblgen_nonEmptyUnconstrained, "non_empty_unconstrained")))100 101// CHECK: [[maybe_unused]] ::llvm::ArrayRef<int64_t> tblgen_nonEmptyConstrained = this->getNonEmptyConstrained();102// CHECK: if (::mlir::failed(__mlir_ods_local_prop_constraint_op2Dproperties2Dpredicates6(*this, tblgen_nonEmptyConstrained, "non_empty_constrained")))103 104// CHECK: [[maybe_unused]] std::optional<::llvm::ArrayRef<int64_t>> tblgen_nonEmptyOptional = this->getNonEmptyOptional();105// CHECK: if (::mlir::failed(__mlir_ods_local_prop_constraint_op2Dproperties2Dpredicates7(*this, tblgen_nonEmptyOptional, "non_empty_optional")))106 107// CHECK-NOT: int64_t tblgen_unconstrained108// CHECK: return ::mlir::success();109