This is an archive of the discontinued LLVM Phabricator instance.

[MLIR][PDL] Make predicate order deterministic.
ClosedPublic

Authored by sfuniak on Dec 20 2021, 9:52 PM.

Details

Summary

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.

Diff Detail

Event Timeline

sfuniak created this revision.Dec 20 2021, 9:52 PM
sfuniak requested review of this revision.Dec 20 2021, 9:52 PM
Mogball accepted this revision.Dec 21 2021, 9:40 AM
Mogball added inline comments.
mlir/lib/Conversion/PDLToPDLInterp/PredicateTree.cpp
913

Nit: can we make the IDs start from 0?

This revision is now accepted and ready to land.Dec 21 2021, 9:40 AM
sfuniak updated this revision to Diff 395767.Dec 21 2021, 4:10 PM

Changed to 0-based indexing of the insertion order.

sfuniak updated this revision to Diff 397174.Jan 3 2022, 6:28 PM

Rebased.

This revision was landed with ongoing or failed builds.Jan 3 2022, 6:39 PM
This revision was automatically updated to reflect the committed changes.