[ScopDetection] Add stat for total number of loops.

The total number of loops is useful as a baseline comparing how many
loops have been optimized in different configurations.

llvm-svn: 311469
diff --git a/polly/lib/Analysis/ScopDetection.cpp b/polly/lib/Analysis/ScopDetection.cpp
index 6b5ed84..d6c9849 100644
--- a/polly/lib/Analysis/ScopDetection.cpp
+++ b/polly/lib/Analysis/ScopDetection.cpp
@@ -212,6 +212,8 @@
 //===----------------------------------------------------------------------===//
 // Statistics.
 
+STATISTIC(NumTotalLoops, "Number of loops (in- or out of scops, in any "
+                         "function processed by Polly)");
 STATISTIC(NumScopRegions, "Number of scops");
 STATISTIC(NumLoopsInScop, "Number of loops in scops");
 STATISTIC(NumScopsDepthOne, "Number of scops with maximal loop depth 1");
@@ -303,6 +305,17 @@
 //===----------------------------------------------------------------------===//
 // ScopDetection.
 
+static void countTotalLoops(Loop *L) {
+  NumTotalLoops++;
+  for (Loop *SubLoop : L->getSubLoops())
+    countTotalLoops(SubLoop);
+}
+
+static void countTotalLoops(LoopInfo &LI) {
+  for (Loop *L : LI)
+    countTotalLoops(L);
+}
+
 ScopDetection::ScopDetection(Function &F, const DominatorTree &DT,
                              ScalarEvolution &SE, LoopInfo &LI, RegionInfo &RI,
                              AliasAnalysis &AA, OptimizationRemarkEmitter &ORE)
@@ -325,6 +338,7 @@
 
   findScops(*TopRegion);
 
+  countTotalLoops(LI);
   NumScopRegions += ValidRegions.size();
 
   // Prune non-profitable regions.