[flang-commits] [flang] [llvm] [mlir] [flang][OpenMP] Enable tiling (PR #143715)
Michael Kruse via flang-commits
flang-commits at lists.llvm.org
Tue Aug 19 05:09:17 PDT 2025
================
@@ -3035,18 +3034,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);
+ }
----------------
Meinersbur wrote:
```suggestion
for (const auto &newLoop : NewLoops)
loopInfos.push_back(newLoop);
```
[coding standard]
https://github.com/llvm/llvm-project/pull/143715
More information about the flang-commits
mailing list