diff --git a/include/llvm/Transforms/Scalar.h b/include/llvm/Transforms/Scalar.h index ff12dc9ab7b..4fea3f73be1 100644 --- a/include/llvm/Transforms/Scalar.h +++ b/include/llvm/Transforms/Scalar.h @@ -306,7 +306,7 @@ FunctionPass *createBlockPlacementPass(); // LCSSA - This pass inserts phi nodes at loop boundaries to simplify other loop // optimizations. // -FunctionPass *createLCSSAPass(); +LoopPass *createLCSSAPass(); extern const PassInfo *LCSSAID; //===----------------------------------------------------------------------===// diff --git a/lib/Transforms/Utils/LCSSA.cpp b/lib/Transforms/Utils/LCSSA.cpp index ed166644d7f..3f4bad5c513 100644 --- a/lib/Transforms/Utils/LCSSA.cpp +++ b/lib/Transforms/Utils/LCSSA.cpp @@ -36,7 +36,8 @@ #include "llvm/ADT/SetVector.h" #include "llvm/ADT/Statistic.h" #include "llvm/Analysis/Dominators.h" -#include "llvm/Analysis/LoopInfo.h" +#include "llvm/Analysis/LoopPass.h" +#include "llvm/Analysis/ScalarEvolution.h" #include "llvm/Support/CFG.h" #include "llvm/Support/Compiler.h" #include @@ -46,17 +47,17 @@ using namespace llvm; STATISTIC(NumLCSSA, "Number of live out of a loop variables"); namespace { - struct VISIBILITY_HIDDEN LCSSA : public FunctionPass { + struct VISIBILITY_HIDDEN LCSSA : public LoopPass { static char ID; // Pass identification, replacement for typeid - LCSSA() : FunctionPass((intptr_t)&ID) {} + LCSSA() : LoopPass((intptr_t)&ID) {} // Cached analysis information for the current function. LoopInfo *LI; DominatorTree *DT; std::vector LoopBlocks; - virtual bool runOnFunction(Function &F); - bool visitSubloop(Loop* L); + virtual bool runOnLoop(Loop *L, LPPassManager &LPM); + void ProcessInstruction(Instruction* Instr, const std::vector& exitBlocks); @@ -69,7 +70,9 @@ namespace { AU.addRequiredID(LoopSimplifyID); AU.addPreservedID(LoopSimplifyID); AU.addRequired(); + AU.addPreserved(); AU.addRequired(); + AU.addPreserved(); } private: void getLoopValuesUsedOutsideLoop(Loop *L, @@ -88,28 +91,15 @@ namespace { RegisterPass X("lcssa", "Loop-Closed SSA Form Pass"); } -FunctionPass *llvm::createLCSSAPass() { return new LCSSA(); } +LoopPass *llvm::createLCSSAPass() { return new LCSSA(); } const PassInfo *llvm::LCSSAID = X.getPassInfo(); /// runOnFunction - Process all loops in the function, inner-most out. -bool LCSSA::runOnFunction(Function &F) { - bool changed = false; +bool LCSSA::runOnLoop(Loop *L, LPPassManager &LPM) { - LI = &getAnalysis(); + LI = &LPM.getAnalysis(); DT = &getAnalysis(); - for (LoopInfo::iterator I = LI->begin(), E = LI->end(); I != E; ++I) - changed |= visitSubloop(*I); - - return changed; -} - -/// visitSubloop - Recursively process all subloops, and then process the given -/// loop if it has live-out values. -bool LCSSA::visitSubloop(Loop* L) { - for (Loop::iterator I = L->begin(), E = L->end(); I != E; ++I) - visitSubloop(*I); - // Speed up queries by creating a sorted list of blocks LoopBlocks.clear(); LoopBlocks.insert(LoopBlocks.end(), L->block_begin(), L->block_end());