Remove LCSSA's bogus dependence on LoopSimplify and LoopSimplify's bogus
authorDan Gohman <gohman@apple.com>
Mon, 26 Jul 2010 18:11:16 +0000 (18:11 +0000)
committerDan Gohman <gohman@apple.com>
Mon, 26 Jul 2010 18:11:16 +0000 (18:11 +0000)
dependence on DominanceFrontier. Instead, add an explicit DominanceFrontier
pass in StandardPasses.h to ensure that it gets scheduled at the right
time.

Declare that loop unrolling preserves ScalarEvolution, and shuffle some
getAnalysisUsages.

This eliminates one LoopSimplify and one LCCSA run in the standard
compile opts sequence.

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

include/llvm/Support/StandardPasses.h
lib/Transforms/Scalar/LoopDeletion.cpp
lib/Transforms/Scalar/LoopUnrollPass.cpp
lib/Transforms/Utils/LCSSA.cpp
lib/Transforms/Utils/LoopSimplify.cpp

index b97ad29d2eb75f089cf483a29f4bd94a25a228e0..3b2fbf04123dbf525b3feef7ecc08a1556be459f 100644 (file)
@@ -20,6 +20,7 @@
 #define LLVM_SUPPORT_STANDARDPASSES_H
 
 #include "llvm/PassManager.h"
+#include "llvm/Analysis/Dominators.h"
 #include "llvm/Analysis/Passes.h"
 #include "llvm/Analysis/Verifier.h"
 #include "llvm/Transforms/Scalar.h"
@@ -128,6 +129,8 @@ namespace llvm {
     PM->add(createTailCallEliminationPass());   // Eliminate tail calls
     PM->add(createCFGSimplificationPass());     // Merge & remove BBs
     PM->add(createReassociatePass());           // Reassociate expressions
+    // Explicitly schedule this to ensure that it runs before any loop pass.
+    PM->add(new DominanceFrontier());           // Calculate Dominance Frontiers
     PM->add(createLoopRotatePass());            // Rotate Loop
     PM->add(createLICMPass());                  // Hoist loop invariants
     PM->add(createLoopUnswitchPass(OptimizeSize || OptimizationLevel < 3));
index 354b033db7896ee9d17929ed1906802c79f91289..bd0e20718611c12d7da74aef2874681987e4130f 100644 (file)
@@ -38,9 +38,9 @@ namespace {
                     bool &Changed, BasicBlock *Preheader);
 
     virtual void getAnalysisUsage(AnalysisUsage& AU) const {
-      AU.addRequired<ScalarEvolution>();
       AU.addRequired<DominatorTree>();
       AU.addRequired<LoopInfo>();
+      AU.addRequired<ScalarEvolution>();
       AU.addRequiredID(LoopSimplifyID);
       AU.addRequiredID(LCSSAID);
       
index 1b4583d0b355fe5e3a06b48cb885be9bd8d44b93..3d446f0f379398b665e9f89e0a5297040b609081 100644 (file)
@@ -17,6 +17,7 @@
 #include "llvm/Transforms/Scalar.h"
 #include "llvm/Analysis/LoopPass.h"
 #include "llvm/Analysis/InlineCost.h"
+#include "llvm/Analysis/ScalarEvolution.h"
 #include "llvm/Support/CommandLine.h"
 #include "llvm/Support/Debug.h"
 #include "llvm/Support/raw_ostream.h"
@@ -55,17 +56,19 @@ namespace {
     /// loop preheaders be inserted into the CFG...
     ///
     virtual void getAnalysisUsage(AnalysisUsage &AU) const {
+      AU.addRequired<LoopInfo>();
+      AU.addPreserved<LoopInfo>();
       AU.addRequiredID(LoopSimplifyID);
+      AU.addPreservedID(LoopSimplifyID);
       AU.addRequiredID(LCSSAID);
-      AU.addRequired<LoopInfo>();
       AU.addPreservedID(LCSSAID);
-      AU.addPreserved<LoopInfo>();
       // FIXME: Loop unroll requires LCSSA. And LCSSA requires dom info.
       // If loop unroll does not preserve dom info then LCSSA pass on next
       // loop will receive invalid dom info.
       // For now, recreate dom info, if loop is unrolled.
       AU.addPreserved<DominatorTree>();
       AU.addPreserved<DominanceFrontier>();
+      AU.addPreserved<ScalarEvolution>();
     }
   };
 }
index 5967cb9dc1b05d60970f0bf3ef35cf43d6361f6a..d380e0dbc10fcb1a059a94fcf02e2aecdb094c2f 100644 (file)
@@ -64,17 +64,12 @@ namespace {
     virtual void getAnalysisUsage(AnalysisUsage &AU) const {
       AU.setPreservesCFG();
 
-      AU.addRequiredTransitive<DominatorTree>();
+      AU.addRequired<DominatorTree>();
       AU.addPreserved<DominatorTree>();
       AU.addPreserved<DominanceFrontier>();
-      AU.addRequiredTransitive<LoopInfo>();
+      AU.addRequired<LoopInfo>();
       AU.addPreserved<LoopInfo>();
-
-      // LCSSA doesn't actually require LoopSimplify, but the PassManager
-      // doesn't know how to schedule LoopSimplify by itself.
-      AU.addRequiredID(LoopSimplifyID);
       AU.addPreservedID(LoopSimplifyID);
-
       AU.addPreserved<ScalarEvolution>();
     }
   private:
index 6b1eaad68ba31b8c3cd992422056b74a8bd50a2e..1571fe8f0b36ed70af9871939dcd9f6b276eea7b 100644 (file)
@@ -77,22 +77,17 @@ namespace {
 
     virtual void getAnalysisUsage(AnalysisUsage &AU) const {
       // We need loop information to identify the loops...
-      AU.addRequiredTransitive<DominatorTree>();
+      AU.addRequired<DominatorTree>();
       AU.addPreserved<DominatorTree>();
 
-      // Request DominanceFrontier now, even though LoopSimplify does
-      // not use it. This allows Pass Manager to schedule Dominance
-      // Frontier early enough such that one LPPassManager can handle
-      // multiple loop transformation passes.
-      AU.addRequired<DominanceFrontier>();
-      AU.addPreserved<DominanceFrontier>();
-
-      AU.addRequiredTransitive<LoopInfo>();
+      AU.addRequired<LoopInfo>();
       AU.addPreserved<LoopInfo>();
 
       AU.addPreserved<AliasAnalysis>();
       AU.addPreserved<ScalarEvolution>();
       AU.addPreservedID(BreakCriticalEdgesID);  // No critical edges added.
+      AU.addPreserved<DominanceFrontier>();
+      AU.addPreservedID(LCSSAID);
     }
 
     /// verifyAnalysis() - Verify LoopSimplifyForm's guarantees.