[Mlir-commits] [mlir] [MLIR][Presburger] Implement IntegerRelation::mergeAndAlignSymbols (PR #76736)
Kunwar Grover
llvmlistbot at llvm.org
Wed Jan 3 06:21:05 PST 2024
================
@@ -1288,6 +1288,37 @@ void IntegerRelation::eliminateRedundantLocalVar(unsigned posA, unsigned posB) {
removeVar(posB);
}
+void IntegerRelation::mergeAndAlignSymbols(IntegerRelation &other) {
+ assert(space.isUsingIds() && other.space.isUsingIds() &&
+ "Both relations need to have identifers to merge & align");
+
+ // First merge & align identifiers into `other` from `this`.
+ unsigned i = 0;
+ for (const Identifier identifier : space.getIds(VarKind::Symbol)) {
+ // If the identifier exists in `other`, then align it; otherwise insert it
+ // assuming it is a new identifier. Search in `other` starting at position
+ // `i` since the left of `i` is aligned.
+ auto *findBegin = other.space.getIds(VarKind::Symbol).begin() + i;
+ auto *findEnd = other.space.getIds(VarKind::Symbol).end();
+ auto *itr = std::find(findBegin, findEnd, identifier);
+ if (itr != findEnd) {
+ other.swapVar(other.getVarKindOffset(VarKind::Symbol) + i,
+ other.getVarKindOffset(VarKind::Symbol) + i +
+ std::distance(findBegin, itr));
+ } else {
+ other.insertVar(VarKind::Symbol, i);
+ other.space.getId(VarKind::Symbol, i) = identifier;
+ }
+ ++i;
+ }
+
+ // Finally add identifiers that are in `other`, but not in `this` to `this`.
+ for (unsigned e = other.getNumVarKind(VarKind::Symbol); i < e; ++i) {
+ insertVar(VarKind::Symbol, i);
----------------
Groverkss wrote:
We should add a insertVar variant with Identifier at some point. Not in this patch, but just wanted to point it out.
https://github.com/llvm/llvm-project/pull/76736
More information about the Mlir-commits
mailing list