LLVM  14.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 
19 #include "llvm/IR/ConstantRange.h"
20 #include "llvm/IR/ValueHandle.h"
21 
22 namespace llvm {
23 
24 class CastInst;
25 class DominatorTree;
26 class Loop;
27 class LoopInfo;
28 class PHINode;
29 class ScalarEvolution;
30 class SCEVExpander;
31 class TargetTransformInfo;
32 
33 /// Interface for visiting interesting IV users that are recognized but not
34 /// simplified by this utility.
35 class IVVisitor {
36 protected:
37  const DominatorTree *DT = nullptr;
38 
39  virtual void anchor();
40 
41 public:
42  IVVisitor() = default;
43  virtual ~IVVisitor() = default;
44 
45  const DominatorTree *getDomTree() const { return DT; }
46  virtual void visitCast(CastInst *Cast) = 0;
47 };
48 
49 /// simplifyUsersOfIV - Simplify instructions that use this induction variable
50 /// by using ScalarEvolution to analyze the IV's recurrence.
51 bool simplifyUsersOfIV(PHINode *CurrIV, ScalarEvolution *SE, DominatorTree *DT,
52  LoopInfo *LI, const TargetTransformInfo *TTI,
53  SmallVectorImpl<WeakTrackingVH> &Dead,
54  SCEVExpander &Rewriter, IVVisitor *V = nullptr);
55 
56 /// SimplifyLoopIVs - Simplify users of induction variables within this
57 /// loop. This does not actually change or add IVs.
58 bool simplifyLoopIVs(Loop *L, ScalarEvolution *SE, DominatorTree *DT,
59  LoopInfo *LI, const TargetTransformInfo *TTI,
60  SmallVectorImpl<WeakTrackingVH> &Dead);
61 
62 /// Collect information about induction variables that are used by sign/zero
63 /// extend operations. This information is recorded by CollectExtend and provides
64 /// the input to WidenIV.
65 struct WideIVInfo {
66  PHINode *NarrowIV = nullptr;
67 
68  // Widest integer type created [sz]ext
69  Type *WidestNativeType = nullptr;
70 
71  // Was a sext user seen before a zext?
72  bool IsSigned = false;
73 };
74 
75 /// Widen Induction Variables - Extend the width of an IV to cover its
76 /// widest uses.
80  unsigned &NumElimExt, unsigned &NumWidened,
81  bool HasGuards, bool UsePostIncrementRanges);
82 
83 } // end namespace llvm
84 
85 #endif // LLVM_TRANSFORMS_UTILS_SIMPLIFYINDVAR_H
llvm
This file implements support for optimizing divisions by a constant.
Definition: AllocatorList.h:23
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:2042
llvm::WideIVInfo::WidestNativeType
Type * WidestNativeType
Definition: SimplifyIndVar.h:69
llvm::IVVisitor::visitCast
virtual void visitCast(CastInst *Cast)=0
llvm::IVVisitor::IVVisitor
IVVisitor()=default
llvm::RegState::Dead
@ Dead
Unused definition.
Definition: MachineInstrBuilder.h:50
llvm::SCEVExpander
This class uses information about analyze scalars to rewrite expressions in canonical form.
Definition: ScalarEvolutionExpander.h:65
llvm::IVVisitor::getDomTree
const DominatorTree * getDomTree() const
Definition: SimplifyIndVar.h:45
llvm::ScalarEvolution
The main scalar evolution driver.
Definition: ScalarEvolution.h:460
llvm::DominatorTree
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree.
Definition: Dominators.h:151
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:37
llvm::WideIVInfo
Collect information about induction variables that are used by sign/zero extend operations.
Definition: SimplifyIndVar.h:65
Rewriter
Virtual Register Rewriter
Definition: VirtRegMap.cpp:237
llvm::WideIVInfo::IsSigned
bool IsSigned
Definition: SimplifyIndVar.h:72
llvm::WideIVInfo::NarrowIV
PHINode * NarrowIV
Definition: SimplifyIndVar.h:66
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:916
llvm::IVVisitor
Interface for visiting interesting IV users that are recognized but not simplified by this utility.
Definition: SimplifyIndVar.h:35
llvm::TTI
TargetTransformInfo TTI
Definition: TargetTransformInfo.h:163
llvm::LoopInfo
Definition: LoopInfo.h:1083
ConstantRange.h
llvm::CastInst
This is the base class for all instructions that perform data casts.
Definition: InstrTypes.h:430
ValueHandle.h
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:928
llvm::IVVisitor::~IVVisitor
virtual ~IVVisitor()=default
llvm::IVVisitor::anchor
virtual void anchor()
Definition: SimplifyIndVar.cpp:912
ScalarEvolutionExpressions.h
llvm::PHINode
Definition: Instructions.h:2633
llvm::SmallVectorImpl< WeakTrackingVH >
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))