diff --git a/mlir/include/mlir/Dialect/PDLInterp/IR/PDLInterpOps.td b/mlir/include/mlir/Dialect/PDLInterp/IR/PDLInterpOps.td --- a/mlir/include/mlir/Dialect/PDLInterp/IR/PDLInterpOps.td +++ b/mlir/include/mlir/Dialect/PDLInterp/IR/PDLInterpOps.td @@ -371,6 +371,32 @@ } //===----------------------------------------------------------------------===// +// pdl_interp::ChooseOpOp +//===----------------------------------------------------------------------===// + +def PDLInterp_ChooseOpOp + : PDLInterp_Op<"choose_op", [NoSideEffect]> { + let summary = "Makes an iterative choice from a range of operations"; + let description = [{ + `pdl_interp.choose_op` returns an element from a range of operations and + executes the rest of the pattern until the end of the match is reached. + In the bytecode interpreter, this operation is implemented by looping over + the operations and, for each choice, running the rest of the bytecode until + we reach the end. This may result in multiple matches being reported. + + Example: + + ```mlir + %op = pdl_interp.choose_op from %ops + ``` + }]; + + let arguments = (ins PDL_RangeOf:$operations); + let results = (outs PDL_Operation:$operation); + let assemblyFormat = "`from` $operations attr-dict"; +} + +//===----------------------------------------------------------------------===// // pdl_interp::CreateAttributeOp //===----------------------------------------------------------------------===// @@ -534,6 +560,31 @@ } //===----------------------------------------------------------------------===// +// pdl_interp::GetAcceptingOpsOp +//===----------------------------------------------------------------------===// + +def PDLInterp_GetAcceptingOpsOp + : PDLInterp_Op<"get_accepting_ops", [NoSideEffect]> { + let summary = "Get the operations accepting a `Value`"; + let description = [{ + `pdl_interp.get_accepting_ops` returns the operations accepting a specific + value or from a range of values at the specified operand position. + In the case of range, the accepting ops of the first value are returned. + + Example: + + ```mlir + %ops = pdl_interp.get_accepting_ops of %value : !pdl.value at 2 + ``` + }]; + + let arguments = (ins PDL_InstOrRangeOf:$value, + Confined:$index); + let results = (outs PDL_RangeOf:$operations); + let assemblyFormat = "`of` $value `:` type($value) `at` $index attr-dict"; +} + +//===----------------------------------------------------------------------===// // pdl_interp::GetAttributeOp //===----------------------------------------------------------------------===// diff --git a/mlir/test/Dialect/PDLInterp/ops.mlir b/mlir/test/Dialect/PDLInterp/ops.mlir --- a/mlir/test/Dialect/PDLInterp/ops.mlir +++ b/mlir/test/Dialect/PDLInterp/ops.mlir @@ -23,3 +23,24 @@ pdl_interp.finalize } + +// ----- + +func @accepting_ops(%input: !pdl.value, %inputs: !pdl.range) { + // single value + %ops1 = pdl_interp.get_accepting_ops of %input : !pdl.value at 2 + + // a range of values + %ops2 = pdl_interp.get_accepting_ops of %inputs : !pdl.range at 3 + + pdl_interp.finalize +} + +// ----- + +func @choose_op(%ops: !pdl.range) { + // choose an op + %op = pdl_interp.choose_op from %ops + + pdl_interp.finalize +}