Stanislav Funiak 842b6861c0 Defines new PDLInterp operations needed for multi-root matching in PDL.
This is commit 1 of 4 for the multi-root matching in PDL, discussed in https://llvm.discourse.group/t/rfc-multi-root-pdl-patterns-for-kernel-matching/4148 (topic flagged for review).

These operations are:
* pdl.get_accepting_ops: Returns a list of operations accepting the given value or a range of values at the specified position. Thus if there are two operations `%op1 = "foo"(%val)` and `%op2 = "bar"(%val)` accepting a value at position 0, `%ops = pdl_interp.get_accepting_ops of %val : !pdl.value at 0` will return both of them. This allows us to traverse upwards from a value to operations accepting the value.
* pdl.choose_op: Iteratively chooses one operation from a range of operations. Therefore, writing `%op = pdl_interp.choose_op from %ops` in the example above will select either `%op1`or `%op2`.

Testing: Added the corresponding test cases to mlir/test/Dialect/PDLInterp/ops.mlir.

Reviewed By: rriddle

Differential Revision: https://reviews.llvm.org/D108543
2021-11-26 17:59:22 +05:30

69 lines
1.9 KiB
MLIR

// RUN: mlir-opt -split-input-file %s | mlir-opt
// Verify the printed output can be parsed.
// RUN: mlir-opt %s | mlir-opt
// Verify the generic form can be parsed.
// RUN: mlir-opt -mlir-print-op-generic %s | mlir-opt
// -----
func @operations(%attribute: !pdl.attribute,
%input: !pdl.value,
%type: !pdl.type) {
// attributes, operands, and results
%op0 = pdl_interp.create_operation "foo.op"(%input : !pdl.value) {"attr" = %attribute} -> (%type : !pdl.type)
// attributes, and results
%op1 = pdl_interp.create_operation "foo.op" {"attr" = %attribute} -> (%type : !pdl.type)
// attributes
%op2 = pdl_interp.create_operation "foo.op" {"attr" = %attribute, "attr1" = %attribute}
// operands, and results
%op3 = pdl_interp.create_operation "foo.op"(%input : !pdl.value) -> (%type : !pdl.type)
pdl_interp.finalize
}
// -----
func @extract(%attrs : !pdl.range<attribute>, %ops : !pdl.range<operation>, %types : !pdl.range<type>, %vals: !pdl.range<value>) {
// attribute at index 0
%attr = pdl_interp.extract 0 of %attrs : !pdl.attribute
// operation at index 1
%op = pdl_interp.extract 1 of %ops : !pdl.operation
// type at index 2
%type = pdl_interp.extract 2 of %types : !pdl.type
// value at index 3
%val = pdl_interp.extract 3 of %vals : !pdl.value
pdl_interp.finalize
}
// -----
func @foreach(%ops: !pdl.range<operation>) {
// iterate over a range of operations
pdl_interp.foreach %op : !pdl.operation in %ops {
%val = pdl_interp.get_result 0 of %op
pdl_interp.continue
} -> ^end
^end:
pdl_interp.finalize
}
// -----
func @users(%value: !pdl.value, %values: !pdl.range<value>) {
// all the users of a single value
%ops1 = pdl_interp.get_users of %value : !pdl.value
// all the users of all the values in a range
%ops2 = pdl_interp.get_users of %values : !pdl.range<value>
pdl_interp.finalize
}