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
18 #include "llvm/IR/ValueHandle.h"
27 class ScalarEvolution
;
30 /// Interface for visiting interesting IV users that are recognized but not
31 /// simplified by this utility.
34 const DominatorTree
*DT
= nullptr;
36 virtual void anchor();
39 IVVisitor() = default;
40 virtual ~IVVisitor() = default;
42 const DominatorTree
*getDomTree() const { return DT
; }
43 virtual void visitCast(CastInst
*Cast
) = 0;
46 /// simplifyUsersOfIV - Simplify instructions that use this induction variable
47 /// by using ScalarEvolution to analyze the IV's recurrence.
48 bool simplifyUsersOfIV(PHINode
*CurrIV
, ScalarEvolution
*SE
, DominatorTree
*DT
,
49 LoopInfo
*LI
, SmallVectorImpl
<WeakTrackingVH
> &Dead
,
50 SCEVExpander
&Rewriter
, IVVisitor
*V
= nullptr);
52 /// SimplifyLoopIVs - Simplify users of induction variables within this
53 /// loop. This does not actually change or add IVs.
54 bool simplifyLoopIVs(Loop
*L
, ScalarEvolution
*SE
, DominatorTree
*DT
,
55 LoopInfo
*LI
, SmallVectorImpl
<WeakTrackingVH
> &Dead
);
57 } // end namespace llvm
59 #endif // LLVM_TRANSFORMS_UTILS_SIMPLIFYINDVAR_H