@@ -449,7 +449,15 @@ struct LoopInterchange {
449
449
return processLoopList (populateWorklist (*L));
450
450
}
451
451
452
- bool isComputableLoopNest (LoopVector LoopList) {
452
+ bool run (LoopNest &LN) {
453
+ const auto &LoopList = LN.getLoops ();
454
+ for (unsigned I = 1 ; I < LoopList.size (); ++I)
455
+ if (LoopList[I]->getParentLoop () != LoopList[I - 1 ])
456
+ return false ;
457
+ return processLoopList (LoopList);
458
+ }
459
+
460
+ bool isComputableLoopNest (ArrayRef<Loop *> LoopList) {
453
461
for (Loop *L : LoopList) {
454
462
const SCEV *ExitCountOuter = SE->getBackedgeTakenCount (L);
455
463
if (isa<SCEVCouldNotCompute>(ExitCountOuter)) {
@@ -468,13 +476,13 @@ struct LoopInterchange {
468
476
return true ;
469
477
}
470
478
471
- unsigned selectLoopForInterchange (const LoopVector & LoopList) {
479
+ unsigned selectLoopForInterchange (ArrayRef<Loop *> LoopList) {
472
480
// TODO: Add a better heuristic to select the loop to be interchanged based
473
481
// on the dependence matrix. Currently we select the innermost loop.
474
482
return LoopList.size () - 1 ;
475
483
}
476
484
477
- bool processLoopList (LoopVector LoopList) {
485
+ bool processLoopList (ArrayRef<Loop *> LoopList) {
478
486
bool Changed = false ;
479
487
unsigned LoopNestDepth = LoopList.size ();
480
488
if (LoopNestDepth < 2 ) {
@@ -515,14 +523,12 @@ struct LoopInterchange {
515
523
516
524
unsigned SelecLoopId = selectLoopForInterchange (LoopList);
517
525
// Move the selected loop outwards to the best possible position.
526
+ Loop *LoopToBeInterchanged = LoopList[SelecLoopId];
518
527
for (unsigned i = SelecLoopId; i > 0 ; i--) {
519
- bool Interchanged = processLoop (LoopList[i] , LoopList[i - 1 ], i, i - 1 ,
520
- LoopNestExit, DependencyMatrix);
528
+ bool Interchanged = processLoop (LoopToBeInterchanged , LoopList[i - 1 ], i,
529
+ i - 1 , LoopNestExit, DependencyMatrix);
521
530
if (!Interchanged)
522
531
return Changed;
523
- // Loops interchanged reflect the same in LoopList
524
- std::swap (LoopList[i - 1 ], LoopList[i]);
525
-
526
532
// Update the DependencyMatrix
527
533
interChangeDependencies (DependencyMatrix, i, i - 1 );
528
534
#ifdef DUMP_DEP_MATRICIES
@@ -539,7 +545,6 @@ struct LoopInterchange {
539
545
std::vector<std::vector<char >> &DependencyMatrix) {
540
546
LLVM_DEBUG (dbgs () << " Processing InnerLoopId = " << InnerLoopId
541
547
<< " and OuterLoopId = " << OuterLoopId << " \n " );
542
-
543
548
LoopInterchangeLegality LIL (OuterLoop, InnerLoop, SE, ORE);
544
549
if (!LIL.canInterchangeLoops (InnerLoopId, OuterLoopId, DependencyMatrix)) {
545
550
LLVM_DEBUG (dbgs () << " Not interchanging loops. Cannot prove legality.\n " );
@@ -1680,14 +1685,15 @@ Pass *llvm::createLoopInterchangePass() {
1680
1685
return new LoopInterchangeLegacyPass ();
1681
1686
}
1682
1687
1683
- PreservedAnalyses LoopInterchangePass::run (Loop &L, LoopAnalysisManager &AM,
1688
+ PreservedAnalyses LoopInterchangePass::run (LoopNest &LN,
1689
+ LoopAnalysisManager &AM,
1684
1690
LoopStandardAnalysisResults &AR,
1685
1691
LPMUpdater &U) {
1686
- Function &F = *L. getHeader ()-> getParent ();
1692
+ Function &F = *LN. getParent ();
1687
1693
1688
1694
DependenceInfo DI (&F, &AR.AA , &AR.SE , &AR.LI );
1689
1695
OptimizationRemarkEmitter ORE (&F);
1690
- if (!LoopInterchange (&AR.SE , &AR.LI , &DI, &AR.DT , &ORE).run (&L ))
1696
+ if (!LoopInterchange (&AR.SE , &AR.LI , &DI, &AR.DT , &ORE).run (LN ))
1691
1697
return PreservedAnalyses::all ();
1692
1698
return getLoopPassPreservedAnalyses ();
1693
1699
}
0 commit comments