diff options
author | Ryotaro Kasuga <kasuga.ryotaro@fujitsu.com> | 2025-03-04 17:24:04 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-03-04 17:24:04 +0900 |
commit | aa37a698d4066058d03016ea467230bd039c1eb1 (patch) | |
tree | af04ac81913b9080968a51df2ec954fc29a98309 /llvm/lib/Transforms/Scalar/LoopInterchange.cpp | |
parent | d6942d54f677000cf713d2b0eba57b641452beb4 (diff) | |
download | llvm-aa37a698d4066058d03016ea467230bd039c1eb1.zip llvm-aa37a698d4066058d03016ea467230bd039c1eb1.tar.gz llvm-aa37a698d4066058d03016ea467230bd039c1eb1.tar.bz2 |
[LoopInterchange] Move some processes to another function (NFC) (#129514)
Some post-processing involved in exchanging a pair of loops has been
done separately from `processLoop`, which is a main function that does
the transformation. It's better to consolidate these processes into the
same function. This patch is a preparation of #127474.
Diffstat (limited to 'llvm/lib/Transforms/Scalar/LoopInterchange.cpp')
-rw-r--r-- | llvm/lib/Transforms/Scalar/LoopInterchange.cpp | 27 |
1 files changed, 14 insertions, 13 deletions
diff --git a/llvm/lib/Transforms/Scalar/LoopInterchange.cpp b/llvm/lib/Transforms/Scalar/LoopInterchange.cpp index f45d90f..967be10 100644 --- a/llvm/lib/Transforms/Scalar/LoopInterchange.cpp +++ b/llvm/lib/Transforms/Scalar/LoopInterchange.cpp @@ -511,18 +511,8 @@ struct LoopInterchange { for (unsigned j = SelecLoopId; j > 0; j--) { bool ChangedPerIter = false; for (unsigned i = SelecLoopId; i > SelecLoopId - j; i--) { - bool Interchanged = processLoop(LoopList[i], LoopList[i - 1], i, i - 1, - DependencyMatrix, CostMap); - if (!Interchanged) - continue; - // Loops interchanged, update LoopList accordingly. - std::swap(LoopList[i - 1], LoopList[i]); - // Update the DependencyMatrix - interChangeDependencies(DependencyMatrix, i, i - 1); - - LLVM_DEBUG(dbgs() << "Dependency matrix after interchange:\n"; - printDepMatrix(DependencyMatrix)); - + bool Interchanged = + processLoop(LoopList, i, i - 1, DependencyMatrix, CostMap); ChangedPerIter |= Interchanged; Changed |= Interchanged; } @@ -534,10 +524,12 @@ struct LoopInterchange { return Changed; } - bool processLoop(Loop *InnerLoop, Loop *OuterLoop, unsigned InnerLoopId, + bool processLoop(SmallVectorImpl<Loop *> &LoopList, unsigned InnerLoopId, unsigned OuterLoopId, std::vector<std::vector<char>> &DependencyMatrix, const DenseMap<const Loop *, unsigned> &CostMap) { + Loop *OuterLoop = LoopList[OuterLoopId]; + Loop *InnerLoop = LoopList[InnerLoopId]; LLVM_DEBUG(dbgs() << "Processing InnerLoopId = " << InnerLoopId << " and OuterLoopId = " << OuterLoopId << "\n"); LoopInterchangeLegality LIL(OuterLoop, InnerLoop, SE, ORE); @@ -566,6 +558,15 @@ struct LoopInterchange { LoopsInterchanged++; llvm::formLCSSARecursively(*OuterLoop, *DT, LI, SE); + + // Loops interchanged, update LoopList accordingly. + std::swap(LoopList[OuterLoopId], LoopList[InnerLoopId]); + // Update the DependencyMatrix + interChangeDependencies(DependencyMatrix, InnerLoopId, OuterLoopId); + + LLVM_DEBUG(dbgs() << "Dependency matrix after interchange:\n"; + printDepMatrix(DependencyMatrix)); + return true; } }; |