1 //===-- llvm/Transforms/Utils/SimplifyIndVar.h - Indvar Utils ---*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
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.
14 //===----------------------------------------------------------------------===//
16 #ifndef LLVM_TRANSFORMS_UTILS_SIMPLIFYINDVAR_H
17 #define LLVM_TRANSFORMS_UTILS_SIMPLIFYINDVAR_H
19 #include "llvm/Support/CommandLine.h"
20 #include "llvm/Support/ValueHandle.h"
30 class ScalarEvolution;
32 /// Interface for visiting interesting IV users that are recognized but not
33 /// simplified by this utility.
36 const DominatorTree *DT;
37 bool ShouldSplitOverflowIntrinsics;
39 virtual void anchor();
41 IVVisitor(): DT(NULL), ShouldSplitOverflowIntrinsics(false) {}
42 virtual ~IVVisitor() {}
44 const DominatorTree *getDomTree() const { return DT; }
46 bool shouldSplitOverflowInstrinsics() const {
47 return ShouldSplitOverflowIntrinsics;
49 void setSplitOverflowIntrinsics() {
50 ShouldSplitOverflowIntrinsics = true;
51 assert(DT && "Splitting overflow intrinsics requires a DomTree.");
54 virtual void visitCast(CastInst *Cast) = 0;
57 /// simplifyUsersOfIV - Simplify instructions that use this induction variable
58 /// by using ScalarEvolution to analyze the IV's recurrence.
59 bool simplifyUsersOfIV(PHINode *CurrIV, ScalarEvolution *SE, LPPassManager *LPM,
60 SmallVectorImpl<WeakVH> &Dead, IVVisitor *V = NULL);
62 /// SimplifyLoopIVs - Simplify users of induction variables within this
63 /// loop. This does not actually change or add IVs.
64 bool simplifyLoopIVs(Loop *L, ScalarEvolution *SE, LPPassManager *LPM,
65 SmallVectorImpl<WeakVH> &Dead);