[Mlir-commits] [mlir] [MLIR][Presburger] Implement Matrix::moveColumns (PR #68362)

Kunwar Grover llvmlistbot at llvm.org
Wed Oct 11 04:00:48 PDT 2023


================
@@ -192,6 +192,36 @@ template <typename T> void Matrix<T>::fillRow(unsigned row, const T &value) {
     at(row, col) = value;
 }
 
+template <typename T> void Matrix<T>::moveColumns(unsigned srcPos, unsigned num, unsigned dstPos) {
+  if(num == 0)
+    return;
+
+  int offset = dstPos - srcPos;
+  if(offset == 0)
+    return;
+
+  assert(0 <= srcPos + offset && srcPos + num + offset <= getNumColumns() &&
+      "invalid move num");
+
+  unsigned insertCount = offset > 0 ? offset : -offset,
+           insertPos = offset > 0 ? srcPos : srcPos + num,
+           deletePos = offset > 0 ? srcPos + num : srcPos + offset;
+  // TODO: This can be done using std::rotate.
+  // Insert new zero columns in the positions where the adjacent columns are to
+  // be moved.
+  insertColumns(insertPos, insertCount);
+  // Update deletePos if insertion of new columns invalidates it.
+  if(insertPos < deletePos)
+    deletePos += insertCount;
+
+  // Swap the adjacent columns with inserted zero columns.
+  for(unsigned i = 0; i < insertCount; i++)
----------------
Groverkss wrote:

++i

https://github.com/llvm/llvm-project/pull/68362


More information about the Mlir-commits mailing list