[PATCH] D75333: Refactor to distinguish the reason for not interchanging loops.

Masakazu Ueno via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Mar 3 04:11:21 PST 2020


masakazu.ueno updated this revision to Diff 247845.
masakazu.ueno added a comment.

Thank you for the review. I fixed the source code.


Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D75333/new/

https://reviews.llvm.org/D75333

Files:
  lib/Transforms/Scalar/LoopInterchange.cpp


Index: lib/Transforms/Scalar/LoopInterchange.cpp
===================================================================
--- lib/Transforms/Scalar/LoopInterchange.cpp
+++ lib/Transforms/Scalar/LoopInterchange.cpp
@@ -51,6 +51,12 @@
 
 #define DEBUG_TYPE "loop-interchange"
 
+enum class LoopInterchangeResult {
+  NotLegal,      // Loops are not legal to interchange.
+  NotProfitable, // Loops are not profitable to interchange.
+  Optimized,
+};
+
 STATISTIC(LoopsInterchanged, "Number of loops interchanged");
 
 static cl::opt<int> LoopInterchangeCostThreshold(
@@ -529,10 +535,11 @@
     unsigned SelecLoopId = selectLoopForInterchange(LoopList);
     // Move the selected loop outwards to the best possible position.
     for (unsigned i = SelecLoopId; i > 0; i--) {
-      bool Interchanged =
+      LoopInterchangeResult Result =
           processLoop(LoopList, i, i - 1, LoopNestExit, DependencyMatrix);
-      if (!Interchanged)
-        return Changed;
+      if (Result == LoopInterchangeResult::NotLegal ||
+          Result == LoopInterchangeResult::NotProfitable) return Changed;
+
       // Loops interchanged reflect the same in LoopList
       std::swap(LoopList[i - 1], LoopList[i]);
 
@@ -542,14 +549,14 @@
       LLVM_DEBUG(dbgs() << "Dependence after interchange\n");
       printDepMatrix(DependencyMatrix);
 #endif
-      Changed |= Interchanged;
+      Changed |= Result == LoopInterchangeResult::Optimized;
     }
     return Changed;
   }
 
-  bool processLoop(LoopVector LoopList, unsigned InnerLoopId,
-                   unsigned OuterLoopId, BasicBlock *LoopNestExit,
-                   std::vector<std::vector<char>> &DependencyMatrix) {
+  LoopInterchangeResult processLoop(LoopVector LoopList, unsigned InnerLoopId,
+                                    unsigned OuterLoopId, BasicBlock *LoopNestExit,
+                                    std::vector<std::vector<char>> &DependencyMatrix) {
     LLVM_DEBUG(dbgs() << "Processing Inner Loop Id = " << InnerLoopId
                       << " and OuterLoopId = " << OuterLoopId << "\n");
     Loop *InnerLoop = LoopList[InnerLoopId];
@@ -558,13 +565,13 @@
     LoopInterchangeLegality LIL(OuterLoop, InnerLoop, SE, ORE);
     if (!LIL.canInterchangeLoops(InnerLoopId, OuterLoopId, DependencyMatrix)) {
       LLVM_DEBUG(dbgs() << "Not interchanging loops. Cannot prove legality.\n");
-      return false;
+      return LoopInterchangeResult::NotLegal;
     }
     LLVM_DEBUG(dbgs() << "Loops are legal to interchange\n");
     LoopInterchangeProfitability LIP(OuterLoop, InnerLoop, SE, ORE);
     if (!LIP.isProfitable(InnerLoopId, OuterLoopId, DependencyMatrix)) {
       LLVM_DEBUG(dbgs() << "Interchanging loops not profitable.\n");
-      return false;
+      return LoopInterchangeResult::NotProfitable;
     }
 
     ORE->emit([&]() {
@@ -579,7 +586,7 @@
     LIT.transform();
     LLVM_DEBUG(dbgs() << "Loops interchanged.\n");
     LoopsInterchanged++;
-    return true;
+    return LoopInterchangeResult::Optimized;
   }
 };
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D75333.247845.patch
Type: text/x-patch
Size: 3014 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200303/cb168c08/attachment-0001.bin>


More information about the llvm-commits mailing list