From 23a6a1bdc5241dd4f4aab870b6bc2ae41d048491 Mon Sep 17 00:00:00 2001 From: Dan Gohman Date: Mon, 26 Jul 2010 18:11:16 +0000 Subject: [PATCH] Remove LCSSA's bogus dependence on LoopSimplify and LoopSimplify's bogus 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. llvm-svn: 109413 --- include/llvm/Support/StandardPasses.h | 3 +++ lib/Transforms/Scalar/LoopDeletion.cpp | 2 +- lib/Transforms/Scalar/LoopUnrollPass.cpp | 9 ++++++--- lib/Transforms/Utils/LCSSA.cpp | 9 ++------- lib/Transforms/Utils/LoopSimplify.cpp | 13 ++++--------- 5 files changed, 16 insertions(+), 20 deletions(-) diff --git a/include/llvm/Support/StandardPasses.h b/include/llvm/Support/StandardPasses.h index b97ad29d2eb..3b2fbf04123 100644 --- a/include/llvm/Support/StandardPasses.h +++ b/include/llvm/Support/StandardPasses.h @@ -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)); diff --git a/lib/Transforms/Scalar/LoopDeletion.cpp b/lib/Transforms/Scalar/LoopDeletion.cpp index 354b033db78..bd0e2071861 100644 --- a/lib/Transforms/Scalar/LoopDeletion.cpp +++ b/lib/Transforms/Scalar/LoopDeletion.cpp @@ -38,9 +38,9 @@ namespace { bool &Changed, BasicBlock *Preheader); virtual void getAnalysisUsage(AnalysisUsage& AU) const { - AU.addRequired(); AU.addRequired(); AU.addRequired(); + AU.addRequired(); AU.addRequiredID(LoopSimplifyID); AU.addRequiredID(LCSSAID); diff --git a/lib/Transforms/Scalar/LoopUnrollPass.cpp b/lib/Transforms/Scalar/LoopUnrollPass.cpp index 1b4583d0b35..3d446f0f379 100644 --- a/lib/Transforms/Scalar/LoopUnrollPass.cpp +++ b/lib/Transforms/Scalar/LoopUnrollPass.cpp @@ -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.addRequiredID(LoopSimplifyID); - AU.addRequiredID(LCSSAID); AU.addRequired(); - AU.addPreservedID(LCSSAID); AU.addPreserved(); + AU.addRequiredID(LoopSimplifyID); + AU.addPreservedID(LoopSimplifyID); + AU.addRequiredID(LCSSAID); + AU.addPreservedID(LCSSAID); // 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(); AU.addPreserved(); + AU.addPreserved(); } }; } diff --git a/lib/Transforms/Utils/LCSSA.cpp b/lib/Transforms/Utils/LCSSA.cpp index 5967cb9dc1b..d380e0dbc10 100644 --- a/lib/Transforms/Utils/LCSSA.cpp +++ b/lib/Transforms/Utils/LCSSA.cpp @@ -64,17 +64,12 @@ namespace { virtual void getAnalysisUsage(AnalysisUsage &AU) const { AU.setPreservesCFG(); - AU.addRequiredTransitive(); + AU.addRequired(); AU.addPreserved(); AU.addPreserved(); - AU.addRequiredTransitive(); + AU.addRequired(); AU.addPreserved(); - - // 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(); } private: diff --git a/lib/Transforms/Utils/LoopSimplify.cpp b/lib/Transforms/Utils/LoopSimplify.cpp index 6b1eaad68ba..1571fe8f0b3 100644 --- a/lib/Transforms/Utils/LoopSimplify.cpp +++ b/lib/Transforms/Utils/LoopSimplify.cpp @@ -77,22 +77,17 @@ namespace { virtual void getAnalysisUsage(AnalysisUsage &AU) const { // We need loop information to identify the loops... - AU.addRequiredTransitive(); + AU.addRequired(); AU.addPreserved(); - // 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(); - AU.addPreserved(); - - AU.addRequiredTransitive(); + AU.addRequired(); AU.addPreserved(); AU.addPreserved(); AU.addPreserved(); AU.addPreservedID(BreakCriticalEdgesID); // No critical edges added. + AU.addPreserved(); + AU.addPreservedID(LCSSAID); } /// verifyAnalysis() - Verify LoopSimplifyForm's guarantees.