This patch refactors the looping strategy of coalesce for future patches. The new strategy works in-place and uses IneqType to organize inequalities into vectors of the same type. Future coalesce cases will pattern match on this organization. E.g. the contained case needs all inequalities and equalities to be redundant, so this case becomes checking whether the respective vectors are empty. For other cases, the patterns consider the types of all inequalities of both sets making it wasteful to only consider whether a can be coalesced with b in one step, as inequalities would need to be typed again for the opposite case. Therefore, the new strategy tries to coalesce a with b and b with a in a single step.
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
Instead of creating a new Simplex object each time you do a coalescePair call, can you instead precompute them and only recompute if two polyhedrons get coalesced? This should reduce the number of times you compute Simplex from n^2 to at max 2n. AFAIU creating a Simplex object is the most expensive operation in coalescing so this is useful to do.
mlir/lib/Analysis/Presburger/PresburgerSet.cpp | ||
---|---|---|
557 | Could you write a comment that since a polyhedron may have been coalesced, polyhedrons.size() can change after an iteration. | |
558 | For this loop, polyhedrons.size() doesn't change since you break if it changes. You can use: for (unsigned j = i + 1, e = polyhedrons.size(); j < e; ++j) instead. | |
560 | This will overflow if i = 0 right? |
Thanks for this patch.
Please add some tests.
mlir/lib/Analysis/Presburger/PresburgerSet.cpp | ||
---|---|---|
503–504 | I think "Erases polyhedrons[i] and polyhedrons[j] and appends poly to the vector`" would be more understandable | |
508–514 | Why can't you append poly directly? Also, local ids are missing. | |
516 | Please write a comment for this | |
516 | const &p? | |
519 | nit: can just use i here | |
519 | ||
521 | You can return LogicalResult | |
531–536 | You can just erase the empty poly here. | |
541–549 | isRedundant* perform pivots, so are expensive. Early exit the loop as soon as onlyRedundantEqs becomes false. | |
545–550 | If using the simplex array, you can use that here. Also, note in the comment that this only happens when there is exactly one empty poly left, since if there were two empty left one of them will get removed as a subset of the other. | |
551–554 | I can't see a usecase for not coalescing in-place. I would just call it coalesceInPlace and do all the operations directly on integerPolyhedrons. We can write a function coalesce() { newSet = *this; newSet.coalesceInPlace(); return newSet; } if someone really wants a copy returned. |
mlir/lib/Analysis/Presburger/PresburgerSet.cpp | ||
---|---|---|
551–554 | But let's leave that for a different patch. Non-in-place might be useful when this is const I guess. The above coalesce would be able to be const. |
I implemented a slightly different looping strategy that now does not shorten the polyhedron vector, but rather replaces elements and keeps track of which ones are actually part of the polytope. Additionally, I implemented the vector of simplices and addressed comments.
mlir/lib/Analysis/Presburger/PresburgerSet.cpp | ||
---|---|---|
541–549 | I do early exit here: k < e && onlyRedundantEqsA. If you want, I can make this part of the body rather than part of the for. |
mlir/lib/Analysis/Presburger/PresburgerSet.cpp | ||
---|---|---|
541–549 | Oops, I missed that. Yeah, putting it in the body might make it easier to spot. |
mlir/lib/Analysis/Presburger/PresburgerSet.cpp | ||
---|---|---|
518–524 | Please write a comment on what exactly this does. Also, a comment that simplices and polyhedrons are guaranteed to be at least of size 2. | |
590 | You can check for rational emptiness here only. After this, you don't need to check that since coalesce of two non empty polyhedrons should not be empty. | |
594 | ||
596 | ||
606 | For now, can you just iterate from j=0 to n - coalescing? I'm not convinced that this covers all cases and may cause problems later. A TODO comment for this would be good and we can discuss this in a later patch. | |
609 | n - coalescing does not change here so you can do e = n-coalescing, j < e. |
Removed the addCoalescedPolyhedron function as currently only erasing is needed. Furthermore, addressed remaining comments.
mlir/lib/Analysis/Presburger/PresburgerSet.cpp | ||
---|---|---|
539 | newly ??? It seems there is a very missing in the last subclause of this sentence. |
The IntegerPolyhedra at the end of the vector are not needed anymore, so they are erased now.
mlir/lib/Analysis/Presburger/PresburgerSet.cpp | ||
---|---|---|
539 | Is "the IntegerPolyhedron now at position i is not compared" more understandable? |
Addressed minor comments and moved the change in Simplex.h to another patch (that already landed).
Drop braces for single-line if statements