Skip to content

Commit

Permalink
Merge pull request #101 from Xilinx/matthias.fix_pdll_sorting
Browse files Browse the repository at this point in the history
PDLL: Fix sorting of constraints by their dependencies
  • Loading branch information
ehsan-toosi authored Feb 8, 2024
2 parents 845176a + 8faf399 commit 53132a4
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion mlir/lib/Conversion/PDLToPDLInterp/PredicateTree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "llvm/ADT/TypeSwitch.h"
#include "llvm/Support/Debug.h"
#include <queue>
#include "llvm/ADT/SmallPtrSet.h"

#define DEBUG_TYPE "pdl-predicate-tree"

Expand Down Expand Up @@ -889,8 +890,17 @@ static void insertExitNode(std::unique_ptr<MatcherNode> *root) {
template <typename Iterator, typename Compare>
void stableTopologicalSort(Iterator begin, Iterator end, Compare cmp) {
while (begin != end) {
// Cannot compute sortBeforeOthers in the predicate of stable_partition
// because stable_partition will not keep the [begin, end) range intact
// while it runs.
llvm::SmallPtrSet<typename Iterator::value_type, 16> sortBeforeOthers;
for(auto i = begin; i != end; ++i) {
if (std::none_of(begin, end, [&](auto const &b) { return cmp(b, *i); }))
sortBeforeOthers.insert(*i);
}

auto const next = std::stable_partition(begin, end, [&](auto const &a) {
return std::none_of(begin, end, [&](auto const &b) { return cmp(b, a); });
return sortBeforeOthers.contains(a);
});
assert(next != begin && "not a partial ordering");
begin = next;
Expand Down

0 comments on commit 53132a4

Please sign in to comment.