1cd96cfd8SDavide Italiano //===- LoopSimplify.h - Loop Canonicalization Pass --------------*- C++ -*-===// 2cd96cfd8SDavide Italiano // 32946cd70SChandler Carruth // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 42946cd70SChandler Carruth // See https://llvm.org/LICENSE.txt for license information. 52946cd70SChandler Carruth // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6cd96cfd8SDavide Italiano // 7cd96cfd8SDavide Italiano //===----------------------------------------------------------------------===// 8cd96cfd8SDavide Italiano // 9cd96cfd8SDavide Italiano // This pass performs several transformations to transform natural loops into a 10cd96cfd8SDavide Italiano // simpler form, which makes subsequent analyses and transformations simpler and 11cd96cfd8SDavide Italiano // more effective. 12cd96cfd8SDavide Italiano // 13cd96cfd8SDavide Italiano // Loop pre-header insertion guarantees that there is a single, non-critical 14cd96cfd8SDavide Italiano // entry edge from outside of the loop to the loop header. This simplifies a 15cd96cfd8SDavide Italiano // number of analyses and transformations, such as LICM. 16cd96cfd8SDavide Italiano // 17cd96cfd8SDavide Italiano // Loop exit-block insertion guarantees that all exit blocks from the loop 18cd96cfd8SDavide Italiano // (blocks which are outside of the loop that have predecessors inside of the 19cd96cfd8SDavide Italiano // loop) only have predecessors from inside of the loop (and are thus dominated 20cd96cfd8SDavide Italiano // by the loop header). This simplifies transformations such as store-sinking 21cd96cfd8SDavide Italiano // that are built into LICM. 22cd96cfd8SDavide Italiano // 23cd96cfd8SDavide Italiano // This pass also guarantees that loops will have exactly one backedge. 24cd96cfd8SDavide Italiano // 25cd96cfd8SDavide Italiano // Indirectbr instructions introduce several complications. If the loop 26cd96cfd8SDavide Italiano // contains or is entered by an indirectbr instruction, it may not be possible 27cd96cfd8SDavide Italiano // to transform the loop and make these guarantees. Client code should check 28cd96cfd8SDavide Italiano // that these conditions are true before relying on them. 29cd96cfd8SDavide Italiano // 30cd96cfd8SDavide Italiano // Note that the simplifycfg pass will clean up blocks which are split out but 31cd96cfd8SDavide Italiano // end up being unnecessary, so usage of this pass should not pessimize 32cd96cfd8SDavide Italiano // generated code. 33cd96cfd8SDavide Italiano // 34cd96cfd8SDavide Italiano // This pass obviously modifies the CFG, but updates loop information and 35cd96cfd8SDavide Italiano // dominator information. 36cd96cfd8SDavide Italiano // 37cd96cfd8SDavide Italiano //===----------------------------------------------------------------------===// 38cd96cfd8SDavide Italiano #ifndef LLVM_TRANSFORMS_UTILS_LOOPSIMPLIFY_H 39cd96cfd8SDavide Italiano #define LLVM_TRANSFORMS_UTILS_LOOPSIMPLIFY_H 40cd96cfd8SDavide Italiano 41cd96cfd8SDavide Italiano #include "llvm/IR/PassManager.h" 42cd96cfd8SDavide Italiano 43cd96cfd8SDavide Italiano namespace llvm { 44cd96cfd8SDavide Italiano 45*510b0f42SSimon Pilgrim class AssumptionCache; 46*510b0f42SSimon Pilgrim class DominatorTree; 47*510b0f42SSimon Pilgrim class Loop; 48*510b0f42SSimon Pilgrim class LoopInfo; 49f31eba64SAlina Sbirlea class MemorySSAUpdater; 50*510b0f42SSimon Pilgrim class ScalarEvolution; 51f31eba64SAlina Sbirlea 52cd96cfd8SDavide Italiano /// This pass is responsible for loop canonicalization. 53cd96cfd8SDavide Italiano class LoopSimplifyPass : public PassInfoMixin<LoopSimplifyPass> { 54cd96cfd8SDavide Italiano public: 5536e0d01eSSean Silva PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM); 56cd96cfd8SDavide Italiano }; 57cd96cfd8SDavide Italiano 585f8f34e4SAdrian Prantl /// Simplify each loop in a loop nest recursively. 59cd96cfd8SDavide Italiano /// 60cd96cfd8SDavide Italiano /// This takes a potentially un-simplified loop L (and its children) and turns 61cd96cfd8SDavide Italiano /// it into a simplified loop nest with preheaders and single backedges. It will 62f31eba64SAlina Sbirlea /// update \c DominatorTree, \c LoopInfo, \c ScalarEvolution and \c MemorySSA 63f31eba64SAlina Sbirlea /// analyses if they're non-null, and LCSSA if \c PreserveLCSSA is true. 64cd96cfd8SDavide Italiano bool simplifyLoop(Loop *L, DominatorTree *DT, LoopInfo *LI, ScalarEvolution *SE, 65f31eba64SAlina Sbirlea AssumptionCache *AC, MemorySSAUpdater *MSSAU, 66f31eba64SAlina Sbirlea bool PreserveLCSSA); 67cd96cfd8SDavide Italiano 68cd96cfd8SDavide Italiano } // end namespace llvm 69cd96cfd8SDavide Italiano 70cd96cfd8SDavide Italiano #endif // LLVM_TRANSFORMS_UTILS_LOOPSIMPLIFY_H 71