1// RUN: mlir-opt -split-input-file %s | mlir-opt 2// Verify the printed output can be parsed. 3// RUN: mlir-opt %s | mlir-opt 4// Verify the generic form can be parsed. 5// RUN: mlir-opt -mlir-print-op-generic %s | mlir-opt 6 7// ----- 8 9// Unused operation to force loading the `arithmetic` dialect for the 10// test of type inferrence. 11arith.constant true 12 13func.func @operations(%attribute: !pdl.attribute, 14 %input: !pdl.value, 15 %type: !pdl.type) { 16 // attributes, operands, and results 17 %op0 = pdl_interp.create_operation "foo.op"(%input : !pdl.value) {"attr" = %attribute} -> (%type : !pdl.type) 18 19 // attributes, and results 20 %op1 = pdl_interp.create_operation "foo.op" {"attr" = %attribute} -> (%type : !pdl.type) 21 22 // attributes 23 %op2 = pdl_interp.create_operation "foo.op" {"attr" = %attribute, "attr1" = %attribute} 24 25 // operands, and results 26 %op3 = pdl_interp.create_operation "foo.op"(%input : !pdl.value) -> (%type : !pdl.type) 27 28 // inferred results 29 %op4 = pdl_interp.create_operation "arith.constant" -> <inferred> 30 31 pdl_interp.finalize 32} 33 34// ----- 35 36func.func @extract(%attrs : !pdl.range<attribute>, %ops : !pdl.range<operation>, %types : !pdl.range<type>, %vals: !pdl.range<value>) { 37 // attribute at index 0 38 %attr = pdl_interp.extract 0 of %attrs : !pdl.attribute 39 40 // operation at index 1 41 %op = pdl_interp.extract 1 of %ops : !pdl.operation 42 43 // type at index 2 44 %type = pdl_interp.extract 2 of %types : !pdl.type 45 46 // value at index 3 47 %val = pdl_interp.extract 3 of %vals : !pdl.value 48 49 pdl_interp.finalize 50} 51 52// ----- 53 54func.func @foreach(%ops: !pdl.range<operation>) { 55 // iterate over a range of operations 56 pdl_interp.foreach %op : !pdl.operation in %ops { 57 %val = pdl_interp.get_result 0 of %op 58 pdl_interp.continue 59 } -> ^end 60 61 ^end: 62 pdl_interp.finalize 63} 64 65// ----- 66 67func.func @users(%value: !pdl.value, %values: !pdl.range<value>) { 68 // all the users of a single value 69 %ops1 = pdl_interp.get_users of %value : !pdl.value 70 71 // all the users of all the values in a range 72 %ops2 = pdl_interp.get_users of %values : !pdl.range<value> 73 74 pdl_interp.finalize 75} 76