1 //===- SimpleLoopUnswitch.h - Hoist loop-invariant control flow -*- C++ -*-===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 10 #ifndef LLVM_TRANSFORMS_SCALAR_SIMPLELOOPUNSWITCH_H 11 #define LLVM_TRANSFORMS_SCALAR_SIMPLELOOPUNSWITCH_H 12 13 #include "llvm/Analysis/LoopAnalysisManager.h" 14 #include "llvm/Analysis/LoopInfo.h" 15 #include "llvm/IR/PassManager.h" 16 #include "llvm/Transforms/Scalar/LoopPassManager.h" 17 18 namespace llvm { 19 20 /// This pass transforms loops that contain branches on loop-invariant 21 /// conditions to have multiple loops. For example, it turns the left into the 22 /// right code: 23 /// 24 /// for (...) if (lic) 25 /// A for (...) 26 /// if (lic) A; B; C 27 /// B else 28 /// C for (...) 29 /// A; C 30 /// 31 /// This can increase the size of the code exponentially (doubling it every time 32 /// a loop is unswitched) so we only unswitch if the resultant code will be 33 /// smaller than a threshold. 34 /// 35 /// This pass expects LICM to be run before it to hoist invariant conditions out 36 /// of the loop, to make the unswitching opportunity obvious. 37 /// 38 class SimpleLoopUnswitchPass : public PassInfoMixin<SimpleLoopUnswitchPass> { 39 public: 40 SimpleLoopUnswitchPass() = default; 41 42 PreservedAnalyses run(Loop &L, LoopAnalysisManager &AM, 43 LoopStandardAnalysisResults &AR, LPMUpdater &U); 44 }; 45 46 /// Create the legacy pass object for the simple loop unswitcher. 47 /// 48 /// See the documentaion for `SimpleLoopUnswitchPass` for details. 49 Pass *createSimpleLoopUnswitchLegacyPass(); 50 51 } // end namespace llvm 52 53 #endif // LLVM_TRANSFORMS_SCALAR_SIMPLELOOPUNSWITCH_H 54