1 //===-- llvm/Transforms/Utils/SimplifyIndVar.h - Indvar Utils ---*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
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.
13 //===----------------------------------------------------------------------===//
15 #ifndef LLVM_TRANSFORMS_UTILS_SIMPLIFYINDVAR_H
16 #define LLVM_TRANSFORMS_UTILS_SIMPLIFYINDVAR_H
22 template <typename T> class SmallVectorImpl;
28 class ScalarEvolution;
30 class TargetTransformInfo;
32 /// Interface for visiting interesting IV users that are recognized but not
33 /// simplified by this utility.
36 const DominatorTree *DT = nullptr;
38 virtual void anchor();
41 IVVisitor() = default;
42 virtual ~IVVisitor() = default;
44 const DominatorTree *getDomTree() const { return DT; }
45 virtual void visitCast(CastInst *Cast) = 0;
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);
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);
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.
65 PHINode *NarrowIV = nullptr;
67 // Widest integer type created [sz]ext
68 Type *WidestNativeType = nullptr;
70 // Was a sext user seen before a zext?
71 bool IsSigned = false;
74 /// Widen Induction Variables - Extend the width of an IV to cover its
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);
82 } // end namespace llvm
84 #endif // LLVM_TRANSFORMS_UTILS_SIMPLIFYINDVAR_H