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
16#ifndef LLVM_TRANSFORMS_UTILS_SIMPLIFYINDVAR_H
17#define LLVM_TRANSFORMS_UTILS_SIMPLIFYINDVAR_H
18
19#include "llvm/IR/ValueHandle.h"
20
21namespace llvm {
22
23class CastInst;
24class DominatorTree;
25class Loop;
26class LoopInfo;
27class PHINode;
28class ScalarEvolution;
29
30/// Interface for visiting interesting IV users that are recognized but not
31/// simplified by this utility.
32class IVVisitor {
33protected:
34  const DominatorTree *DT = nullptr;
35
36  virtual void anchor();
37
38public:
39  IVVisitor() = default;
40  virtual ~IVVisitor() = default;
41
42  const DominatorTree *getDomTree() const { return DT; }
43  virtual void visitCast(CastInst *Cast) = 0;
44};
45
46/// simplifyUsersOfIV - Simplify instructions that use this induction variable
47/// by using ScalarEvolution to analyze the IV's recurrence.
48bool simplifyUsersOfIV(PHINode *CurrIV, ScalarEvolution *SE, DominatorTree *DT,
49                       LoopInfo *LI, SmallVectorImpl<WeakTrackingVH> &Dead,
50                       IVVisitor *V = nullptr);
51
52/// SimplifyLoopIVs - Simplify users of induction variables within this
53/// loop. This does not actually change or add IVs.
54bool simplifyLoopIVs(Loop *L, ScalarEvolution *SE, DominatorTree *DT,
55                     LoopInfo *LI, SmallVectorImpl<WeakTrackingVH> &Dead);
56
57} // end namespace llvm
58
59#endif // LLVM_TRANSFORMS_UTILS_SIMPLIFYINDVAR_H
60