llvm.org GIT mirror llvm / fff81b2
[PM] Port LoopSimplify to the new pass manager. While here move simplifyLoop() function to the new header, as suggested by Chandler in the review. Differential Revision: http://reviews.llvm.org/D21404 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@274959 91177308-0d34-0410-b5e6-96231b3b80d8 Davide Italiano 3 years ago
7 changed file(s) with 100 addition(s) and 8 deletion(s). Raw diff Collapse all Expand all
0 //===- LoopSimplify.h - Loop Canonicalization Pass --------------*- C++ -*-===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This pass performs several transformations to transform natural loops into a
10 // simpler form, which makes subsequent analyses and transformations simpler and
11 // more effective.
12 //
13 // Loop pre-header insertion guarantees that there is a single, non-critical
14 // entry edge from outside of the loop to the loop header. This simplifies a
15 // number of analyses and transformations, such as LICM.
16 //
17 // Loop exit-block insertion guarantees that all exit blocks from the loop
18 // (blocks which are outside of the loop that have predecessors inside of the
19 // loop) only have predecessors from inside of the loop (and are thus dominated
20 // by the loop header). This simplifies transformations such as store-sinking
21 // that are built into LICM.
22 //
23 // This pass also guarantees that loops will have exactly one backedge.
24 //
25 // Indirectbr instructions introduce several complications. If the loop
26 // contains or is entered by an indirectbr instruction, it may not be possible
27 // to transform the loop and make these guarantees. Client code should check
28 // that these conditions are true before relying on them.
29 //
30 // Note that the simplifycfg pass will clean up blocks which are split out but
31 // end up being unnecessary, so usage of this pass should not pessimize
32 // generated code.
33 //
34 // This pass obviously modifies the CFG, but updates loop information and
35 // dominator information.
36 //
37 //===----------------------------------------------------------------------===//
38 #ifndef LLVM_TRANSFORMS_UTILS_LOOPSIMPLIFY_H
39 #define LLVM_TRANSFORMS_UTILS_LOOPSIMPLIFY_H
40
41 #include "llvm/Analysis/AssumptionCache.h"
42 #include "llvm/Analysis/ScalarEvolution.h"
43 #include "llvm/IR/Dominators.h"
44 #include "llvm/IR/PassManager.h"
45
46 namespace llvm {
47
48 /// This pass is responsible for loop canonicalization.
49 class LoopSimplifyPass : public PassInfoMixin {
50 public:
51 PreservedAnalyses run(Function &F, AnalysisManager &AM);
52 };
53
54 /// \brief Simplify each loop in a loop nest recursively.
55 ///
56 /// This takes a potentially un-simplified loop L (and its children) and turns
57 /// it into a simplified loop nest with preheaders and single backedges. It will
58 /// update \c AliasAnalysis and \c ScalarEvolution analyses if they're non-null.
59 bool simplifyLoop(Loop *L, DominatorTree *DT, LoopInfo *LI, ScalarEvolution *SE,
60 AssumptionCache *AC, bool PreserveLCSSA);
61
62 } // end namespace llvm
63
64 #endif // LLVM_TRANSFORMS_UTILS_LOOPSIMPLIFY_H
322322 BasicBlock *InsertPreheaderForLoop(Loop *L, DominatorTree *DT, LoopInfo *LI,
323323 bool PreserveLCSSA);
324324
325 /// \brief Simplify each loop in a loop nest recursively.
326 ///
327 /// This takes a potentially un-simplified loop L (and its children) and turns
328 /// it into a simplified loop nest with preheaders and single backedges. It will
329 /// update \c AliasAnalysis and \c ScalarEvolution analyses if they're non-null.
330 bool simplifyLoop(Loop *L, DominatorTree *DT, LoopInfo *LI, ScalarEvolution *SE,
331 AssumptionCache *AC, bool PreserveLCSSA);
332
333325 /// \brief Put loop into LCSSA form.
334326 ///
335327 /// Looks at all instructions in the loop which have uses outside of the
101101 #include "llvm/Transforms/Scalar/TailRecursionElimination.h"
102102 #include "llvm/Transforms/Utils/AddDiscriminators.h"
103103 #include "llvm/Transforms/Utils/LCSSA.h"
104 #include "llvm/Transforms/Utils/LoopSimplify.h"
104105 #include "llvm/Transforms/Utils/Mem2Reg.h"
105106 #include "llvm/Transforms/Utils/MemorySSA.h"
106107 #include "llvm/Transforms/Utils/SimplifyInstructions.h"
139139 FUNCTION_PASS("lower-expect", LowerExpectIntrinsicPass())
140140 FUNCTION_PASS("guard-widening", GuardWideningPass())
141141 FUNCTION_PASS("gvn", GVN())
142 FUNCTION_PASS("loop-simplify", LoopSimplifyPass())
142143 FUNCTION_PASS("mem2reg", PromotePass())
143144 FUNCTION_PASS("memcpyopt", MemCpyOptPass())
144145 FUNCTION_PASS("mldst-motion", MergedLoadStoreMotionPass())
3636 //
3737 //===----------------------------------------------------------------------===//
3838
39 #include "llvm/Transforms/Utils/LoopSimplify.h"
3940 #include "llvm/Transforms/Scalar.h"
4041 #include "llvm/ADT/DepthFirstIterator.h"
4142 #include "llvm/ADT/SetOperations.h"
801802 return Changed;
802803 }
803804
805 PreservedAnalyses LoopSimplifyPass::run(Function &F,
806 AnalysisManager &AM) {
807 bool Changed = false;
808 LoopInfo *LI = &AM.getResult(F);
809 DominatorTree *DT = &AM.getResult(F);
810 ScalarEvolution *SE = AM.getCachedResult(F);
811 AssumptionCache *AC = &AM.getResult(F);
812
813 // FIXME: This pass should verify that the loops on which it's operating
814 // are in canonical SSA form, and that the pass itself preserves this form.
815 for (LoopInfo::iterator I = LI->begin(), E = LI->end(); I != E; ++I)
816 Changed |= simplifyLoop(*I, DT, LI, SE, AC, true /* PreserveLCSSA */);
817
818 if (!Changed)
819 return PreservedAnalyses::all();
820 PreservedAnalyses PA;
821
822 // The old PM also preserved LCSSAID and BreakCriticalEdgesID.
823 // This makes no sense in the new PM so we omit those from the set
824 // of preserved passes.
825 PA.preserve();
826 PA.preserve();
827 PA.preserve();
828 PA.preserve();
829 PA.preserve();
830 PA.preserve();
831 PA.preserve();
832 return PA;
833 }
834
804835 // FIXME: Restore this code when we re-enable verification in verifyAnalysis
805836 // below.
806837 #if 0
3333 #include "llvm/Transforms/Utils/BasicBlockUtils.h"
3434 #include "llvm/Transforms/Utils/Cloning.h"
3535 #include "llvm/Transforms/Utils/Local.h"
36 #include "llvm/Transforms/Utils/LoopSimplify.h"
3637 #include "llvm/Transforms/Utils/LoopUtils.h"
3738 #include "llvm/Transforms/Utils/SimplifyIndVar.h"
3839 using namespace llvm;
0 ; RUN: opt < %s -loop-simplify
1 ; RUN: opt < %s -passes=loop-simplify
12
23 ; This function should get a preheader inserted before BB3, that is jumped
34 ; to by BB1 & BB2