Skip to content

Commit aa37a69

Browse files
authored
[LoopInterchange] Move some processes to another function (NFC) (llvm#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 llvm#127474.
1 parent d6942d5 commit aa37a69

File tree

1 file changed

+14
-13
lines changed

1 file changed

+14
-13
lines changed

llvm/lib/Transforms/Scalar/LoopInterchange.cpp

+14-13
Original file line numberDiff line numberDiff line change
@@ -511,18 +511,8 @@ struct LoopInterchange {
511511
for (unsigned j = SelecLoopId; j > 0; j--) {
512512
bool ChangedPerIter = false;
513513
for (unsigned i = SelecLoopId; i > SelecLoopId - j; i--) {
514-
bool Interchanged = processLoop(LoopList[i], LoopList[i - 1], i, i - 1,
515-
DependencyMatrix, CostMap);
516-
if (!Interchanged)
517-
continue;
518-
// Loops interchanged, update LoopList accordingly.
519-
std::swap(LoopList[i - 1], LoopList[i]);
520-
// Update the DependencyMatrix
521-
interChangeDependencies(DependencyMatrix, i, i - 1);
522-
523-
LLVM_DEBUG(dbgs() << "Dependency matrix after interchange:\n";
524-
printDepMatrix(DependencyMatrix));
525-
514+
bool Interchanged =
515+
processLoop(LoopList, i, i - 1, DependencyMatrix, CostMap);
526516
ChangedPerIter |= Interchanged;
527517
Changed |= Interchanged;
528518
}
@@ -534,10 +524,12 @@ struct LoopInterchange {
534524
return Changed;
535525
}
536526

537-
bool processLoop(Loop *InnerLoop, Loop *OuterLoop, unsigned InnerLoopId,
527+
bool processLoop(SmallVectorImpl<Loop *> &LoopList, unsigned InnerLoopId,
538528
unsigned OuterLoopId,
539529
std::vector<std::vector<char>> &DependencyMatrix,
540530
const DenseMap<const Loop *, unsigned> &CostMap) {
531+
Loop *OuterLoop = LoopList[OuterLoopId];
532+
Loop *InnerLoop = LoopList[InnerLoopId];
541533
LLVM_DEBUG(dbgs() << "Processing InnerLoopId = " << InnerLoopId
542534
<< " and OuterLoopId = " << OuterLoopId << "\n");
543535
LoopInterchangeLegality LIL(OuterLoop, InnerLoop, SE, ORE);
@@ -566,6 +558,15 @@ struct LoopInterchange {
566558
LoopsInterchanged++;
567559

568560
llvm::formLCSSARecursively(*OuterLoop, *DT, LI, SE);
561+
562+
// Loops interchanged, update LoopList accordingly.
563+
std::swap(LoopList[OuterLoopId], LoopList[InnerLoopId]);
564+
// Update the DependencyMatrix
565+
interChangeDependencies(DependencyMatrix, InnerLoopId, OuterLoopId);
566+
567+
LLVM_DEBUG(dbgs() << "Dependency matrix after interchange:\n";
568+
printDepMatrix(DependencyMatrix));
569+
569570
return true;
570571
}
571572
};

0 commit comments

Comments
 (0)