improve loop rotation to use CodeMetrics to analyze the
authorChris Lattner <sabre@nondot.org>
Sun, 2 Jan 2011 07:35:53 +0000 (07:35 +0000)
committerChris Lattner <sabre@nondot.org>
Sun, 2 Jan 2011 07:35:53 +0000 (07:35 +0000)
size of a loop header instead of its own code size estimator.
This allows it to handle bitcasts etc more precisely.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@122681 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/Scalar/LoopRotation.cpp
lib/Transforms/Scalar/LoopUnrollPass.cpp

index 88cb9d73b2d22ef2f885d8eca9a995828a4fc88c..efa46f4781dc3f2ef5e73059f1e295f8bd0b3f4e 100644 (file)
@@ -14,9 +14,9 @@
 #define DEBUG_TYPE "loop-rotate"
 #include "llvm/Transforms/Scalar.h"
 #include "llvm/Function.h"
-#include "llvm/IntrinsicInst.h"
 #include "llvm/Analysis/LoopPass.h"
 #include "llvm/Analysis/Dominators.h"
+#include "llvm/Analysis/CodeMetrics.h"
 #include "llvm/Analysis/ScalarEvolution.h"
 #include "llvm/Transforms/Utils/Local.h"
 #include "llvm/Transforms/Utils/BasicBlockUtils.h"
@@ -142,23 +142,14 @@ bool LoopRotate::rotateLoop(Loop *Lp, LPPassManager &LPM) {
   if (ExitBlocks.size() > 1)
     return false;
 
-  // Check size of original header and reject
-  // loop if it is very big.
-  unsigned Size = 0;
-  
-  // FIXME: Use common api to estimate size.
-  for (BasicBlock::const_iterator OI = OrigHeader->begin(), 
-         OE = OrigHeader->end(); OI != OE; ++OI) {
-    if (isa<PHINode>(OI)) 
-      continue;           // PHI nodes don't count.
-    if (isa<DbgInfoIntrinsic>(OI))
-      continue;  // Debug intrinsics don't count as size.
-    ++Size;
+  // Check size of original header and reject loop if it is very big.
+  {
+    CodeMetrics Metrics;
+    Metrics.analyzeBasicBlock(OrigHeader);
+    if (Metrics.NumInsts > MAX_HEADER_SIZE)
+      return false;
   }
 
-  if (Size > MAX_HEADER_SIZE)
-    return false;
-
   // Now, this loop is suitable for rotation.
 
   // Anything ScalarEvolution may know about this loop or the PHI nodes
index 65e576bde9361cc395fc9df6a87964cc9926c0f4..3a8619b91ea8600a9152207e61bed67ac07fbe20 100644 (file)
@@ -16,7 +16,7 @@
 #include "llvm/IntrinsicInst.h"
 #include "llvm/Transforms/Scalar.h"
 #include "llvm/Analysis/LoopPass.h"
-#include "llvm/Analysis/InlineCost.h"
+#include "llvm/Analysis/CodeMetrics.h"
 #include "llvm/Analysis/ScalarEvolution.h"
 #include "llvm/Support/CommandLine.h"
 #include "llvm/Support/Debug.h"