85 lines · plain
1// RUN: mlir-irdl-to-cpp %s | FileCheck %s2 3// CHECK: class TestIrdlToCpp4irdl.dialect @test_irdl_to_cpp {5 6 // CHECK: class FooType7 irdl.type @foo8 9 // CHECK: class BarOp10 // CHECK: ::mlir::Value getRes()11 irdl.operation @bar {12 %0 = irdl.any13 irdl.results(res: %0)14 }15 16 // CHECK: class BeefOp17 // CHECK: ::mlir::Value getLhs()18 // CHECK: ::mlir::Value getRhs()19 // CHECK: ::mlir::Value getRes()20 irdl.operation @beef {21 %0 = irdl.any22 irdl.operands(lhs: %0, rhs: %0)23 irdl.results(res: %0)24 }25 26 // CHECK: class HashOp27 // CHECK: ::mlir::Value getLhs()28 // CHECK: ::mlir::Value getRhs()29 // CHECK: ::mlir::Value getRes()30 irdl.operation @hash {31 %0 = irdl.any32 irdl.operands(lhs: %0, rhs: %0)33 irdl.results(res: %0)34 }35 36 // CHECK: ConditionalOp declarations37 // CHECK: ConditionalOpGenericAdaptorBase38 // CHECK: ::mlir::Region &getCond() { return *getRegions()[0]; }39 // CHECK: ::mlir::Region &getThen() { return *getRegions()[1]; }40 // CHECK: ::mlir::Region &getElse() { return *getRegions()[2]; }41 //42 // CHECK: class ConditionalOp : public ::mlir::Op<ConditionalOp, ::mlir::OpTrait::NRegions<3>::Impl, ::mlir::OpTrait::OpInvariants>43 // CHECK: ::mlir::Region &getCond() { return (*this)->getRegion(0); }44 // CHECK: ::mlir::Region &getThen() { return (*this)->getRegion(1); }45 // CHECK: ::mlir::Region &getElse() { return (*this)->getRegion(2); }46 47 // CHECK: ConditionalOp definitions48 // CHECK: __mlir_irdl_local_region_constraint_ConditionalOp_cond49 // CHECK: if (!(region.getNumArguments() == 1)) {50 // CHECK: failed to verify constraint: region with 1 entry block argument(s)51 52 // CHECK: __mlir_irdl_local_region_constraint_ConditionalOp_then53 // CHECK: if (!(true)) {54 55 // CHECK: __mlir_irdl_local_region_constraint_ConditionalOp_else56 // CHECK: if (!(region.getNumArguments() == 0)) {57 // CHECK: failed to verify constraint: region with 0 entry block argument(s)58 59 // CHECK: ConditionalOp::build60 // CHECK: for (unsigned i = 0; i != 3; ++i)61 // CHECK-NEXT: (void)odsState.addRegion();62 63 // CHECK: ConditionalOp::verifyInvariantsImpl64 // CHECK: __mlir_irdl_local_region_constraint_ConditionalOp_cond65 // CHECK: failure66 // CHECK: __mlir_irdl_local_region_constraint_ConditionalOp_then67 // CHECK: failure68 // CHECK: __mlir_irdl_local_region_constraint_ConditionalOp_else69 // CHECK: failure70 // CHECK: success71 irdl.operation @conditional {72 %r0 = irdl.region // Unconstrained region73 %r1 = irdl.region() // Region with no entry block arguments74 75 // TODO(#161018): support irdl.is in irdl-to-cpp76 // %v0 = irdl.is i1 // Type constraint: i1 (boolean)77 %v0 = irdl.any78 %r2 = irdl.region(%v0) // Region with one i1 entry block argument79 irdl.regions(cond: %r2, then: %r0, else: %r1)80 81 %0 = irdl.any82 irdl.operands(input: %0)83 }84}85