Details | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 14 | pmbaty | 1 | //===-- llvm/Transforms/Utils/SimplifyIndVar.h - Indvar Utils ---*- C++ -*-===// |
| 2 | // |
||
| 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
||
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
||
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
||
| 6 | // |
||
| 7 | //===----------------------------------------------------------------------===// |
||
| 8 | // |
||
| 9 | // This file defines in interface for induction variable simplification. It does |
||
| 10 | // not define any actual pass or policy, but provides a single function to |
||
| 11 | // simplify a loop's induction variables based on ScalarEvolution. |
||
| 12 | // |
||
| 13 | //===----------------------------------------------------------------------===// |
||
| 14 | |||
| 15 | #ifndef LLVM_TRANSFORMS_UTILS_SIMPLIFYINDVAR_H |
||
| 16 | #define LLVM_TRANSFORMS_UTILS_SIMPLIFYINDVAR_H |
||
| 17 | |||
| 18 | namespace llvm { |
||
| 19 | |||
| 20 | class Type; |
||
| 21 | class WeakTrackingVH; |
||
| 22 | template <typename T> class SmallVectorImpl; |
||
| 23 | class CastInst; |
||
| 24 | class DominatorTree; |
||
| 25 | class Loop; |
||
| 26 | class LoopInfo; |
||
| 27 | class PHINode; |
||
| 28 | class ScalarEvolution; |
||
| 29 | class SCEVExpander; |
||
| 30 | class TargetTransformInfo; |
||
| 31 | |||
| 32 | /// Interface for visiting interesting IV users that are recognized but not |
||
| 33 | /// simplified by this utility. |
||
| 34 | class IVVisitor { |
||
| 35 | protected: |
||
| 36 | const DominatorTree *DT = nullptr; |
||
| 37 | |||
| 38 | virtual void anchor(); |
||
| 39 | |||
| 40 | public: |
||
| 41 | IVVisitor() = default; |
||
| 42 | virtual ~IVVisitor() = default; |
||
| 43 | |||
| 44 | const DominatorTree *getDomTree() const { return DT; } |
||
| 45 | virtual void visitCast(CastInst *Cast) = 0; |
||
| 46 | }; |
||
| 47 | |||
| 48 | /// simplifyUsersOfIV - Simplify instructions that use this induction variable |
||
| 49 | /// by using ScalarEvolution to analyze the IV's recurrence. |
||
| 50 | bool simplifyUsersOfIV(PHINode *CurrIV, ScalarEvolution *SE, DominatorTree *DT, |
||
| 51 | LoopInfo *LI, const TargetTransformInfo *TTI, |
||
| 52 | SmallVectorImpl<WeakTrackingVH> &Dead, |
||
| 53 | SCEVExpander &Rewriter, IVVisitor *V = nullptr); |
||
| 54 | |||
| 55 | /// SimplifyLoopIVs - Simplify users of induction variables within this |
||
| 56 | /// loop. This does not actually change or add IVs. |
||
| 57 | bool simplifyLoopIVs(Loop *L, ScalarEvolution *SE, DominatorTree *DT, |
||
| 58 | LoopInfo *LI, const TargetTransformInfo *TTI, |
||
| 59 | SmallVectorImpl<WeakTrackingVH> &Dead); |
||
| 60 | |||
| 61 | /// Collect information about induction variables that are used by sign/zero |
||
| 62 | /// extend operations. This information is recorded by CollectExtend and provides |
||
| 63 | /// the input to WidenIV. |
||
| 64 | struct WideIVInfo { |
||
| 65 | PHINode *NarrowIV = nullptr; |
||
| 66 | |||
| 67 | // Widest integer type created [sz]ext |
||
| 68 | Type *WidestNativeType = nullptr; |
||
| 69 | |||
| 70 | // Was a sext user seen before a zext? |
||
| 71 | bool IsSigned = false; |
||
| 72 | }; |
||
| 73 | |||
| 74 | /// Widen Induction Variables - Extend the width of an IV to cover its |
||
| 75 | /// widest uses. |
||
| 76 | PHINode *createWideIV(const WideIVInfo &WI, |
||
| 77 | LoopInfo *LI, ScalarEvolution *SE, SCEVExpander &Rewriter, |
||
| 78 | DominatorTree *DT, SmallVectorImpl<WeakTrackingVH> &DeadInsts, |
||
| 79 | unsigned &NumElimExt, unsigned &NumWidened, |
||
| 80 | bool HasGuards, bool UsePostIncrementRanges); |
||
| 81 | |||
| 82 | } // end namespace llvm |
||
| 83 | |||
| 84 | #endif // LLVM_TRANSFORMS_UTILS_SIMPLIFYINDVAR_H |