brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.2 KiB · 23ab24e Raw
80 lines · plain
1// RUN: mlir-tblgen -gen-rewriters -I %S/../../include %s | FileCheck %s2 3include "mlir/IR/OpBase.td"4include "mlir/IR/PatternBase.td"5 6def Test_Dialect : Dialect {7  let name = "test";8}9class NS_Op<string mnemonic, list<Trait> traits> :10    Op<Test_Dialect, mnemonic, traits>;11 12def AOp : NS_Op<"a_op", []> {13  let arguments = (ins14    I32:$x,15    I32Attr:$y16  );17 18  let results = (outs I32:$z);19}20 21def BOp : NS_Op<"b_op", []> {22  let arguments = (ins23    I32Attr:$y24  );25 26  let results = (outs I32:$z);27}28 29def test1 : Pat<(AOp (BOp:$x $y), $_), (AOp $x, $y)>;30// CHECK-LABEL: struct test131// CHECK: ::llvm::LogicalResult matchAndRewrite32// CHECK-DAG: ::mlir::IntegerAttr y;33// CHECK-DAG: test::BOp x;34// CHECK-DAG: ::llvm::SmallVector<::mlir::Operation *, 4> tblgen_ops;35// CHECK: tblgen_ops.push_back(op0);36// CHECK: x = castedOp1;37// CHECK: tblgen_attr = castedOp1.getProperties().getY();38// CHECK: if (!(tblgen_attr))39// CHECK: y = tblgen_attr;40// CHECK: tblgen_ops.push_back(op1);41 42// CHECK: test::AOp tblgen_AOp_0;43// CHECK: ::llvm::SmallVector<::mlir::Value, 4> tblgen_values;44// CHECK: test::AOp::Properties tblgen_props;45// CHECK: tblgen_values.push_back((*x.getODSResults(0).begin()));46// CHECK: tblgen_props.y = ::llvm::dyn_cast_if_present<decltype(tblgen_props.y)>(y);47// CHECK: tblgen_AOp_0 = test::AOp::create(rewriter, odsLoc, tblgen_types, tblgen_values, tblgen_props);48 49// Note: These use strings to pick up a non-trivial storage/interface type50// difference.51def COp : NS_Op<"c_op", []> {52  let arguments = (ins53    I32:$x,54    StringProp:$y55  );56 57  let results = (outs I32:$z);58}59 60def DOp : NS_Op<"d_op", []> {61  let arguments = (ins62    StringProp:$y63  );64 65  let results = (outs I32:$z);66}67def test2 : Pat<(COp (DOp:$x $y), $_), (COp $x, $y)>;68// CHECK-LABEL: struct test269// CHECK: ::llvm::LogicalResult matchAndRewrite70// CHECK-DAG: ::llvm::StringRef y;71// CHECK-DAG: test::DOp x;72// CHECK-DAG: ::llvm::SmallVector<::mlir::Operation *, 4> tblgen_ops;73// CHECK: tblgen_ops.push_back(op0);74// CHECK: x = castedOp1;75// CHECK: tblgen_prop = castedOp1.getProperties().getY();76// CHECK: y = tblgen_prop;77// CHECK: tblgen_ops.push_back(op1);78// CHECK: test::COp::Properties tblgen_props;79// CHECK: tblgen_props.setY(y);80