LLVM  16.0.0git
SimplifyIndVar.h
Go to the documentation of this file.
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.
79  unsigned &NumElimExt, unsigned &NumWidened,
80  bool HasGuards, bool UsePostIncrementRanges);
81 
82 } // end namespace llvm
83 
84 #endif // LLVM_TRANSFORMS_UTILS_SIMPLIFYINDVAR_H
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
llvm::createWideIV
PHINode * createWideIV(const WideIVInfo &WI, LoopInfo *LI, ScalarEvolution *SE, SCEVExpander &Rewriter, DominatorTree *DT, SmallVectorImpl< WeakTrackingVH > &DeadInsts, unsigned &NumElimExt, unsigned &NumWidened, bool HasGuards, bool UsePostIncrementRanges)
Widen Induction Variables - Extend the width of an IV to cover its widest uses.
Definition: SimplifyIndVar.cpp:2086
llvm::WideIVInfo::WidestNativeType
Type * WidestNativeType
Definition: SimplifyIndVar.h:68
llvm::IVVisitor::visitCast
virtual void visitCast(CastInst *Cast)=0
llvm::IVVisitor::IVVisitor
IVVisitor()=default
llvm::SCEVExpander
This class uses information about analyze scalars to rewrite expressions in canonical form.
Definition: ScalarEvolutionExpander.h:50
llvm::IVVisitor::getDomTree
const DominatorTree * getDomTree() const
Definition: SimplifyIndVar.h:44
llvm::ScalarEvolution
The main scalar evolution driver.
Definition: ScalarEvolution.h:449
llvm::DominatorTree
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree.
Definition: Dominators.h:166
llvm::Type
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:45
llvm::IVVisitor::DT
const DominatorTree * DT
Definition: SimplifyIndVar.h:36
llvm::WideIVInfo
Collect information about induction variables that are used by sign/zero extend operations.
Definition: SimplifyIndVar.h:64
Rewriter
Virtual Register Rewriter
Definition: VirtRegMap.cpp:237
llvm::WideIVInfo::IsSigned
bool IsSigned
Definition: SimplifyIndVar.h:71
llvm::WideIVInfo::NarrowIV
PHINode * NarrowIV
Definition: SimplifyIndVar.h:65
llvm::simplifyUsersOfIV
bool simplifyUsersOfIV(PHINode *CurrIV, ScalarEvolution *SE, DominatorTree *DT, LoopInfo *LI, const TargetTransformInfo *TTI, SmallVectorImpl< WeakTrackingVH > &Dead, SCEVExpander &Rewriter, IVVisitor *V=nullptr)
simplifyUsersOfIV - Simplify instructions that use this induction variable by using ScalarEvolution t...
Definition: SimplifyIndVar.cpp:961
llvm::IVVisitor
Interface for visiting interesting IV users that are recognized but not simplified by this utility.
Definition: SimplifyIndVar.h:34
TemplateParamKind::Type
@ Type
llvm::TTI
TargetTransformInfo TTI
Definition: TargetTransformInfo.h:168
llvm::LoopInfo
Definition: LoopInfo.h:1108
llvm::CastInst
This is the base class for all instructions that perform data casts.
Definition: InstrTypes.h:429
llvm::simplifyLoopIVs
bool simplifyLoopIVs(Loop *L, ScalarEvolution *SE, DominatorTree *DT, LoopInfo *LI, const TargetTransformInfo *TTI, SmallVectorImpl< WeakTrackingVH > &Dead)
SimplifyLoopIVs - Simplify users of induction variables within this loop.
Definition: SimplifyIndVar.cpp:973
llvm::IVVisitor::~IVVisitor
virtual ~IVVisitor()=default
llvm::IVVisitor::anchor
virtual void anchor()
Definition: SimplifyIndVar.cpp:957
llvm::PHINode
Definition: Instructions.h:2697
llvm::SmallVectorImpl
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Definition: APFloat.h:42
llvm::RegState::Dead
@ Dead
Unused definition.
Definition: MachineInstrBuilder.h:50
UsePostIncrementRanges
static cl::opt< bool > UsePostIncrementRanges("indvars-post-increment-ranges", cl::Hidden, cl::desc("Use post increment control-dependent ranges in IndVarSimplify"), cl::init(true))