[PATCH] D48651: [RFC] Pattern matching on schedule trees.
Oleksandr "Alex" Zinenko via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Jul 3 05:26:12 PDT 2018
ftynse added inline comments.
================
Comment at: include/polly/ScheduleOptimizer.h:50
+
+Suggestions on how to do that?
+
----------------
chelini wrote:
> ftynse wrote:
> > It depends on what you need exactly. Just one node without specifying a type? Does that mean that the node _does_ exist or _may_ exist? Do you want to skip over multiple levels of the tree? Do you want to skip over multiple siblings? One can go shell-like wildcard way with `?` and `*`. Or some flavor of regular expressions, but this quickly goes out of hand. I'd like to see examples of what needs to be expressed before taking a decision. My feeling after using different flavors of schedule trees is that you probably need some traversal matchers like `hasSibling` or `hasDescendant`
> Hi, Indeed `hasSibling` or `hasDescendant` would be really useful. In the case of matrix-multiplication suggested by Michael you may, for example, have two different schedule trees:
>
> -Domain
> --Band {/*mat mul op */}
> ---Leaf
>
> For the simple case without initialization or
>
> -Domain
> --Sequence
> ---Filter
> ----Band
> -----Leaf
> ---Filter
> ----Band
> -----Leaf
> ---Filter
> ----Band {/*mat mul op */}
> -----Leaf
>
> For the case with initialization. A possible matchers would look like as Domain(hasDescendant(Band())). Of course, band should have specific properties related to the matmul operation. Do you already have in mind a possible implementation for these traversal matchers?
I do have a possible implementation in mind. What I don't see is how to make it usable in this case. With a pure structural matcher,
```
domain(
band(isMatMul))
```
you have a guaranteed structure in case of a match. That is, you can write
```lang=c++
auto matcher = domain(band([](isl::schedule_node n) { return true; /*check if matmul*/ }));
if (ScheduleNodeMatcher::isMatching(matcher, node)) {
auto n = node.get_child(0); // guaranteed to produce a non-null node
// n is guaranteed to be a band node here
n.band_tile(...); // no need for extra cheks
}
```
With traversals, you don't get such guarantee: the descendant you are interested in may be arbitrarily deep and you need to somehow reach it to do a transformation. One way to go would be to return some collection of nodes that matched with a predefined structure. Another possibility would be to do that transformation in the callback passed to the matcher, but I'm not convinced it is the right approach, I think matchers are for //finding// stuff.
In this particular example, I don't see why do you want to match the domain... It's always at the root anyway. But you seem to need to anchor the matcher at leafs.
https://reviews.llvm.org/D48651
More information about the llvm-commits
mailing list