13ca95b02SDimitry Andric //===- LoopSimplify.h - Loop Canonicalization Pass --------------*- C++ -*-===// 23ca95b02SDimitry Andric // 33ca95b02SDimitry Andric // The LLVM Compiler Infrastructure 43ca95b02SDimitry Andric // 53ca95b02SDimitry Andric // This file is distributed under the University of Illinois Open Source 63ca95b02SDimitry Andric // License. See LICENSE.TXT for details. 73ca95b02SDimitry Andric // 83ca95b02SDimitry Andric //===----------------------------------------------------------------------===// 93ca95b02SDimitry Andric // 103ca95b02SDimitry Andric // This pass performs several transformations to transform natural loops into a 113ca95b02SDimitry Andric // simpler form, which makes subsequent analyses and transformations simpler and 123ca95b02SDimitry Andric // more effective. 133ca95b02SDimitry Andric // 143ca95b02SDimitry Andric // Loop pre-header insertion guarantees that there is a single, non-critical 153ca95b02SDimitry Andric // entry edge from outside of the loop to the loop header. This simplifies a 163ca95b02SDimitry Andric // number of analyses and transformations, such as LICM. 173ca95b02SDimitry Andric // 183ca95b02SDimitry Andric // Loop exit-block insertion guarantees that all exit blocks from the loop 193ca95b02SDimitry Andric // (blocks which are outside of the loop that have predecessors inside of the 203ca95b02SDimitry Andric // loop) only have predecessors from inside of the loop (and are thus dominated 213ca95b02SDimitry Andric // by the loop header). This simplifies transformations such as store-sinking 223ca95b02SDimitry Andric // that are built into LICM. 233ca95b02SDimitry Andric // 243ca95b02SDimitry Andric // This pass also guarantees that loops will have exactly one backedge. 253ca95b02SDimitry Andric // 263ca95b02SDimitry Andric // Indirectbr instructions introduce several complications. If the loop 273ca95b02SDimitry Andric // contains or is entered by an indirectbr instruction, it may not be possible 283ca95b02SDimitry Andric // to transform the loop and make these guarantees. Client code should check 293ca95b02SDimitry Andric // that these conditions are true before relying on them. 303ca95b02SDimitry Andric // 313ca95b02SDimitry Andric // Note that the simplifycfg pass will clean up blocks which are split out but 323ca95b02SDimitry Andric // end up being unnecessary, so usage of this pass should not pessimize 333ca95b02SDimitry Andric // generated code. 343ca95b02SDimitry Andric // 353ca95b02SDimitry Andric // This pass obviously modifies the CFG, but updates loop information and 363ca95b02SDimitry Andric // dominator information. 373ca95b02SDimitry Andric // 383ca95b02SDimitry Andric //===----------------------------------------------------------------------===// 393ca95b02SDimitry Andric #ifndef LLVM_TRANSFORMS_UTILS_LOOPSIMPLIFY_H 403ca95b02SDimitry Andric #define LLVM_TRANSFORMS_UTILS_LOOPSIMPLIFY_H 413ca95b02SDimitry Andric 423ca95b02SDimitry Andric #include "llvm/Analysis/AssumptionCache.h" 433ca95b02SDimitry Andric #include "llvm/Analysis/ScalarEvolution.h" 443ca95b02SDimitry Andric #include "llvm/IR/Dominators.h" 453ca95b02SDimitry Andric #include "llvm/IR/PassManager.h" 463ca95b02SDimitry Andric 473ca95b02SDimitry Andric namespace llvm { 483ca95b02SDimitry Andric 493ca95b02SDimitry Andric /// This pass is responsible for loop canonicalization. 503ca95b02SDimitry Andric class LoopSimplifyPass : public PassInfoMixin<LoopSimplifyPass> { 513ca95b02SDimitry Andric public: 52d88c1a5aSDimitry Andric PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM); 533ca95b02SDimitry Andric }; 543ca95b02SDimitry Andric 55*4ba319b5SDimitry Andric /// Simplify each loop in a loop nest recursively. 563ca95b02SDimitry Andric /// 573ca95b02SDimitry Andric /// This takes a potentially un-simplified loop L (and its children) and turns 583ca95b02SDimitry Andric /// it into a simplified loop nest with preheaders and single backedges. It will 593ca95b02SDimitry Andric /// update \c AliasAnalysis and \c ScalarEvolution analyses if they're non-null. 603ca95b02SDimitry Andric bool simplifyLoop(Loop *L, DominatorTree *DT, LoopInfo *LI, ScalarEvolution *SE, 613ca95b02SDimitry Andric AssumptionCache *AC, bool PreserveLCSSA); 623ca95b02SDimitry Andric 633ca95b02SDimitry Andric } // end namespace llvm 643ca95b02SDimitry Andric 653ca95b02SDimitry Andric #endif // LLVM_TRANSFORMS_UTILS_LOOPSIMPLIFY_H 66