Hi there,
we’re using PDL to do pattern matching in our downstream repository. We have a couple of patterns that only differ in a single attribute value that they try to match, i.e.:
pdl.pattern : benefit(1) {
%ARGS = operands
%FOO_ATTR = pdl.attribute = "foo"
%TYPE = pdl.type
%OP = pdl.operation "some_op"(%ARGS : !pdl.range<value>) {"FooAttr" = %FOO_ATTR} -> (%TYPE : !pdl.type)
pdl.rewrite ...
}
pdl.pattern : benefit(1) {
%ARGS = operands
%BAR_ATTR = pdl.attribute = "bar"
%TYPE = pdl.type
%OP = pdl.operation "some_op"(%ARGS : !pdl.range<value>) {"BarAttr" = %BAR_ATTR} -> (%TYPE : !pdl.type)
pdl.rewrite ...
}
So the only difference in these patterns is the name and value of the attribute. The pattern + rewrite is quite large, so we would like to avoid having to maintain effectively the same pattern multiple times.
TableGen’s Pat
provides PatFrag
which can be used to extract common logic. We were wondering if there’s a way to achieve something similar here. Alternatively, it would be nice if we could specify a list of possible values for an attribute, something similar to:
pdl.pattern : benefit(1) {
%ARGS = operands
%ATTR_VAL = pdl.attribute = any("foo", "bar")
%ATTR_KEY = pdl.attribute = any("FooAttr", "BarAttr")
%TYPE = pdl.type
%OP = pdl.operation "some_op"(%ARGS : !pdl.range<value>) {%ATTR_KEY = %ATTR_VAL} -> (%TYPE : !pdl.type)
pdl.rewrite ...
}
Is there a way to achieve something like this or do we have to maintain two separate patterns for now?