[MLIR][PDL] Make predicate order deterministic.
authorStanislav Funiak <stano@cerebras.net>
Tue, 4 Jan 2022 02:33:26 +0000 (08:03 +0530)
committerUday Bondhugula <uday@polymagelabs.com>
Tue, 4 Jan 2022 02:33:44 +0000 (08:03 +0530)
commit138803e017739c81b43b73631c7096bfc4d097d8
tree7c05e121316b669f9f24b8109234aed83580f329
parent2692eae57428e1136ab58ac4004883245d0623ca
[MLIR][PDL] Make predicate order deterministic.

The tree merging of pattern predicates places the predicates in an unordered set. When the predicates are sorted, they are taken in the set order, not the insertion order. This results in nondeterministic behavior.

One solution to this problem would be to use `SetVector`. However, the value `SetVector` does not provide a `find` function for fast O(1) lookups and stores the predicates twice -- once in the set and once in the vector, which is undesirable, because we store patternToAnswer in each predicate. A simpler solution is to store the tie breaking ID (which follows the insertion order), and use this ID to break any ties when comparing predicates.

Reviewed By: Mogball

Differential Revision: https://reviews.llvm.org/D116081
mlir/lib/Conversion/PDLToPDLInterp/PredicateTree.cpp