SimplifyIndVar.h 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. #pragma once
  2. #ifdef __GNUC__
  3. #pragma GCC diagnostic push
  4. #pragma GCC diagnostic ignored "-Wunused-parameter"
  5. #endif
  6. //===-- llvm/Transforms/Utils/SimplifyIndVar.h - Indvar Utils ---*- 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 file defines in interface for induction variable simplification. It does
  15. // not define any actual pass or policy, but provides a single function to
  16. // simplify a loop's induction variables based on ScalarEvolution.
  17. //
  18. //===----------------------------------------------------------------------===//
  19. #ifndef LLVM_TRANSFORMS_UTILS_SIMPLIFYINDVAR_H
  20. #define LLVM_TRANSFORMS_UTILS_SIMPLIFYINDVAR_H
  21. namespace llvm {
  22. class Type;
  23. class WeakTrackingVH;
  24. template <typename T> class SmallVectorImpl;
  25. class CastInst;
  26. class DominatorTree;
  27. class Loop;
  28. class LoopInfo;
  29. class PHINode;
  30. class ScalarEvolution;
  31. class SCEVExpander;
  32. class TargetTransformInfo;
  33. /// Interface for visiting interesting IV users that are recognized but not
  34. /// simplified by this utility.
  35. class IVVisitor {
  36. protected:
  37. const DominatorTree *DT = nullptr;
  38. virtual void anchor();
  39. public:
  40. IVVisitor() = default;
  41. virtual ~IVVisitor() = default;
  42. const DominatorTree *getDomTree() const { return DT; }
  43. virtual void visitCast(CastInst *Cast) = 0;
  44. };
  45. /// simplifyUsersOfIV - Simplify instructions that use this induction variable
  46. /// by using ScalarEvolution to analyze the IV's recurrence.
  47. bool simplifyUsersOfIV(PHINode *CurrIV, ScalarEvolution *SE, DominatorTree *DT,
  48. LoopInfo *LI, const TargetTransformInfo *TTI,
  49. SmallVectorImpl<WeakTrackingVH> &Dead,
  50. SCEVExpander &Rewriter, 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, DominatorTree *DT,
  54. LoopInfo *LI, const TargetTransformInfo *TTI,
  55. SmallVectorImpl<WeakTrackingVH> &Dead);
  56. /// Collect information about induction variables that are used by sign/zero
  57. /// extend operations. This information is recorded by CollectExtend and provides
  58. /// the input to WidenIV.
  59. struct WideIVInfo {
  60. PHINode *NarrowIV = nullptr;
  61. // Widest integer type created [sz]ext
  62. Type *WidestNativeType = nullptr;
  63. // Was a sext user seen before a zext?
  64. bool IsSigned = false;
  65. };
  66. /// Widen Induction Variables - Extend the width of an IV to cover its
  67. /// widest uses.
  68. PHINode *createWideIV(const WideIVInfo &WI,
  69. LoopInfo *LI, ScalarEvolution *SE, SCEVExpander &Rewriter,
  70. DominatorTree *DT, SmallVectorImpl<WeakTrackingVH> &DeadInsts,
  71. unsigned &NumElimExt, unsigned &NumWidened,
  72. bool HasGuards, bool UsePostIncrementRanges);
  73. } // end namespace llvm
  74. #endif // LLVM_TRANSFORMS_UTILS_SIMPLIFYINDVAR_H
  75. #ifdef __GNUC__
  76. #pragma GCC diagnostic pop
  77. #endif