SimplifyIndVar.h 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. //===-- llvm/Transforms/Utils/SimplifyIndVar.h - Indvar Utils ---*- 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. // This file defines in interface for induction variable simplification. It does
  11. // not define any actual pass or policy, but provides a single function to
  12. // simplify a loop's induction variables based on ScalarEvolution.
  13. //
  14. //===----------------------------------------------------------------------===//
  15. #ifndef LLVM_TRANSFORMS_UTILS_SIMPLIFYINDVAR_H
  16. #define LLVM_TRANSFORMS_UTILS_SIMPLIFYINDVAR_H
  17. #include "llvm/IR/ValueHandle.h"
  18. #include "llvm/Support/CommandLine.h"
  19. namespace llvm {
  20. class CastInst;
  21. class DominatorTree;
  22. class IVUsers;
  23. class Loop;
  24. class LPPassManager;
  25. class PHINode;
  26. class ScalarEvolution;
  27. /// Interface for visiting interesting IV users that are recognized but not
  28. /// simplified by this utility.
  29. class IVVisitor {
  30. protected:
  31. const DominatorTree *DT;
  32. bool ShouldSplitOverflowIntrinsics;
  33. virtual void anchor();
  34. public:
  35. IVVisitor(): DT(nullptr), ShouldSplitOverflowIntrinsics(false) {}
  36. virtual ~IVVisitor() {}
  37. const DominatorTree *getDomTree() const { return DT; }
  38. bool shouldSplitOverflowInstrinsics() const {
  39. return ShouldSplitOverflowIntrinsics;
  40. }
  41. void setSplitOverflowIntrinsics() {
  42. ShouldSplitOverflowIntrinsics = true;
  43. assert(DT && "Splitting overflow intrinsics requires a DomTree.");
  44. }
  45. virtual void visitCast(CastInst *Cast) = 0;
  46. };
  47. /// simplifyUsersOfIV - Simplify instructions that use this induction variable
  48. /// by using ScalarEvolution to analyze the IV's recurrence.
  49. bool simplifyUsersOfIV(PHINode *CurrIV, ScalarEvolution *SE, LPPassManager *LPM,
  50. SmallVectorImpl<WeakVH> &Dead, IVVisitor *V = nullptr);
  51. /// SimplifyLoopIVs - Simplify users of induction variables within this
  52. /// loop. This does not actually change or add IVs.
  53. bool simplifyLoopIVs(Loop *L, ScalarEvolution *SE, LPPassManager *LPM,
  54. SmallVectorImpl<WeakVH> &Dead);
  55. } // namespace llvm
  56. #endif