[flang] [llvm] [mlir] [flang][OpenMP] Enable tiling (PR #143715)
Michael Kruse via llvm-commits
llvm-commits at lists.llvm.org
Tue Jul 8 08:16:36 PDT 2025
================
@@ -2992,18 +2991,59 @@ 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 =
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);
+
+ // Update afterIP to get the correct insertion point after
+ // tiling.
+ llvm::BasicBlock *AfterBB = NewLoops.front()->getAfter();
+ llvm::BasicBlock *AfterAfterBB = AfterBB->getSingleSuccessor();
+ afterIP = {AfterAfterBB, AfterAfterBB->begin()};
+ NewTopLoopInfo = NewLoops[0];
+
+ // Update the loop infos
+ loopInfos.clear();
+ for (const auto &newLoop : NewLoops) {
+ loopInfos.push_back(newLoop);
+ }
+ } // Tiling done
+
+ // Do collapse
+ if (const auto &numCollapse = loopOp.getNumCollapse()) {
+ SmallVector<llvm::CanonicalLoopInfo *> collapseLoopInfos(
+ loopInfos.begin(), loopInfos.begin() + (numCollapse));
+
+ auto newLoopInfo =
+ ompBuilder->collapseLoops(ompLoc.DL, collapseLoopInfos, {});
----------------
Meinersbur wrote:
Previously this was called withing the OpenMPLoopInfoStackFrame callback. Does it make a difference?
(Doing it outside of it seems more logical to me, but I assume there was a reason)
https://github.com/llvm/llvm-project/pull/143715
More information about the llvm-commits
mailing list