[Mlir-commits] [llvm] [mlir] [MLIR][OpenMP] add interchange operation in the OpenMP mlir dialect (PR #186381)
Michael Kruse
llvmlistbot at llvm.org
Fri Mar 27 05:03:30 PDT 2026
================
@@ -6785,6 +6783,89 @@ void OpenMPIRBuilder::unrollLoopHeuristic(DebugLoc, CanonicalLoopInfo *Loop) {
});
}
+std::vector<CanonicalLoopInfo *>
+OpenMPIRBuilder::interchangeLoops(DebugLoc DL,
+ ArrayRef<CanonicalLoopInfo *> Loops,
+ std::vector<int> Permutation) {
+ assert(Permutation.size() == Loops.size() &&
+ "The permutation must have every input loop");
+ int NumLoops = Loops.size();
+ assert(NumLoops >= 2 && "At least two loops to interchange required");
+
+ CanonicalLoopInfo *OutermostLoop = Loops.front();
+ CanonicalLoopInfo *InnermostLoop = Loops.back();
+ Function *F = OutermostLoop->getBody()->getParent();
+
+ // Loop control blocks that may become orphaned later.
+ SmallVector<BasicBlock *> OldControlBBs;
+ for (CanonicalLoopInfo *Loop : Loops)
+ Loop->collectControlBlocks(OldControlBBs);
+
+ // Create the new loop nest structure
+ std::vector<CanonicalLoopInfo *> Result;
+
+ BasicBlock *Enter = OutermostLoop->getPreheader();
+ BasicBlock *Continue = OutermostLoop->getAfter();
+ BasicBlock *OutroInsertBefore = InnermostLoop->getExit();
+
+ for (int i = 0; i < NumLoops; i++) {
+ int loop_n = Permutation[i] - 1;
----------------
Meinersbur wrote:
```suggestion
int LoopIndex = Permutation[i] - 1;
```
[style] [Variable names should be nouns (as they represent state). The name should be camel case, and start with an upper-case letter (e.g. Leader or Boats).](https://llvm.org/docs/CodingStandards.html#name-types-functions-variables-and-enumerators-properly)
https://github.com/llvm/llvm-project/pull/186381
More information about the Mlir-commits
mailing list