[PATCH] D51994: TableGen/ISel: Allow PatFrag predicate code to access captured operands

Nicolai Hähnle via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Oct 8 09:21:55 PDT 2018


nhaehnle added a comment.

In https://reviews.llvm.org/D51994#1242128, @hfinkel wrote:

> I'm somewhat confused by the motivation. Can you explain why the fact that the operands are commuted causes a problem. In https://reviews.llvm.org/D51995, you just seem to be looping over them anyway.


Sorry, I missed this. The issue is as follows; we're trying to match expressions like `(add (add A, B), C)`. Indeed, we want to loop over A, B, and C!

The issue is that TableGen automatically generates commuted patterns, so we might also match an expression like `(add A, (add B, C))`. The C++ code in the PatFrag has no way of knowing which of these versions we actually matched. So with only access to the top-level node, there's no way to loop over A, B, and C without effectively duplicating the pattern matching that was already done for that.

And even if we did duplicate the matching in C++, we wouldn't actually have a guarantee that what we're doing is correct! For example, if the top level node is actually `(add (add A, B), (add C, D))`, then there's no way of knowing which of the children of the top-level `add` we should consider as black boxes, so we don't know whether to loop over A, B, and (add C, D) or whether to loop over (add A, B), C, and D.


Repository:
  rL LLVM

https://reviews.llvm.org/D51994





More information about the llvm-commits mailing list