[flang] [llvm] [mlir] [flang][OpenMP] Enable tiling (PR #143715)

Jan Leyonberg via llvm-commits llvm-commits at lists.llvm.org
Thu Jun 26 07:53:33 PDT 2025


================
@@ -2992,18 +2991,60 @@ convertOmpLoopNest(Operation &opInst, llvm::IRBuilderBase &builder,
     loopInfos.push_back(*loopResult);
   }
 
-  // Collapse loops. Store the insertion point because LoopInfos may get
-  // invalidated.
+  //  llvm::OpenMPIRBuilder::InsertPointTy afterIP = builder.saveIP();
   llvm::OpenMPIRBuilder::InsertPointTy afterIP =
       loopInfos.front()->getAfterIP();
 
-  // Update the stack frame created for this loop to point to the resulting loop
-  // after applying transformations.
-  moduleTranslation.stackWalk<OpenMPLoopInfoStackFrame>(
-      [&](OpenMPLoopInfoStackFrame &frame) {
-        frame.loopInfo = ompBuilder->collapseLoops(ompLoc.DL, loopInfos, {});
-        return WalkResult::interrupt();
-      });
+  // Initialize the new loop info to the current one, in case there
+  // are no loop transformations done.
+  llvm::CanonicalLoopInfo *NewTopLoopInfo = nullptr;
+
+  // Do tiling
+  if (const auto &tiles = loopOp.getTileSizes()) {
+    llvm::Type *IVType = loopInfos.front()->getIndVarType();
+    SmallVector<llvm::Value *> TileSizes;
+
+    for (auto tile : tiles.value()) {
+      llvm::Value *TileVal = llvm::ConstantInt::get(IVType, tile);
+      TileSizes.push_back(TileVal);
+    }
+
+    std::vector<llvm::CanonicalLoopInfo *> NewLoops =
+        ompBuilder->tileLoops(ompLoc.DL, loopInfos, TileSizes);
+
+    // Collapse loops. Store the insertion point because LoopInfos may get
----------------
jsjodin wrote:

Done. Stray comment, I updated it to make sense.

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


More information about the llvm-commits mailing list