LoopSimplify.h 3.0 KB

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