[Mlir-commits] [llvm] [mlir] [MLIR][OpenMP] add interchange operation in the OpenMP mlir dialect (PR #186381)

Michael Kruse llvmlistbot at llvm.org
Thu Mar 19 07:08:57 PDT 2026


================
@@ -3965,6 +3967,98 @@ std::pair<unsigned, unsigned> FuseOp::getGenerateesODSOperandIndexAndLength() {
   return getODSOperandIndexAndLength(odsIndex_generatees);
 }
 
+//===----------------------------------------------------------------------===//
+// InterchangeOp
+//===----------------------------------------------------------------------===//
+
+static void printLoopTransformClis(OpAsmPrinter &p, InterchangeOp op,
+                                   OperandRange generatees,
+                                   OperandRange applyees) {
+  if (!generatees.empty())
+    p << '(' << llvm::interleaved(generatees) << ')';
+
+  if (!applyees.empty())
+    p << " <- (" << llvm::interleaved(applyees) << ')';
+}
+
+LogicalResult InterchangeOp::verify() {
+  if (getApplyees().size() < 2)
+    return emitOpError() << "must apply to at least two loops";
+
+  if (!getPermutation().has_value())
+    return emitOpError() << "must have permutation attribute";
+
+  auto permutation = getPermutation().value();
+  if (permutation.size() != getApplyees().size())
+    return emitOpError() << "expecting the same number of permutation "
+                            "attributes and applyees";
+
+  llvm::SmallVector<bool> found(permutation.size(), false);
+  for (auto &val : permutation) {
+    int perm = llvm::dyn_cast<IntegerAttr>(val).getInt();
+    if (perm <= 0)
+      return emitOpError()
+             << "permutation attribute must be a positive integer";
+    if ((unsigned)perm - 1 < permutation.size())
----------------
Meinersbur wrote:

```suggestion
    if ((size_t)perm - 1 < permutation.size())
```

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


More information about the Mlir-commits mailing list