LLVM 20.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#include <utility>
19
20namespace llvm {
21
22class Type;
23class WeakTrackingVH;
24template <typename T> class SmallVectorImpl;
25class CastInst;
26class DominatorTree;
27class Loop;
28class LoopInfo;
29class PHINode;
30class ScalarEvolution;
31class SCEVExpander;
32class TargetTransformInfo;
33
34/// Interface for visiting interesting IV users that are recognized but not
35/// simplified by this utility.
36class IVVisitor {
37protected:
38 const DominatorTree *DT = nullptr;
39
40 virtual void anchor();
41
42public:
43 IVVisitor() = default;
44 virtual ~IVVisitor() = default;
45
46 const DominatorTree *getDomTree() const { return DT; }
47 virtual void visitCast(CastInst *Cast) = 0;
48};
49
50/// simplifyUsersOfIV - Simplify instructions that use this induction variable
51/// by using ScalarEvolution to analyze the IV's recurrence. Returns a pair
52/// where the first entry indicates that the function makes changes and the
53/// second entry indicates that it introduced new opportunities for loop
54/// unswitching.
55std::pair<bool, bool> simplifyUsersOfIV(PHINode *CurrIV, ScalarEvolution *SE,
56 DominatorTree *DT, LoopInfo *LI,
59 SCEVExpander &Rewriter,
60 IVVisitor *V = nullptr);
61
62/// SimplifyLoopIVs - Simplify users of induction variables within this
63/// loop. This does not actually change or add IVs.
67
68/// Collect information about induction variables that are used by sign/zero
69/// extend operations. This information is recorded by CollectExtend and provides
70/// the input to WidenIV.
71struct WideIVInfo {
72 PHINode *NarrowIV = nullptr;
73
74 // Widest integer type created [sz]ext
76
77 // Was a sext user seen before a zext?
78 bool IsSigned = false;
79};
80
81/// Widen Induction Variables - Extend the width of an IV to cover its
82/// widest uses.
84 LoopInfo *LI, ScalarEvolution *SE, SCEVExpander &Rewriter,
86 unsigned &NumElimExt, unsigned &NumWidened,
87 bool HasGuards, bool UsePostIncrementRanges);
88
89} // end namespace llvm
90
91#endif // LLVM_TRANSFORMS_UTILS_SIMPLIFYINDVAR_H
RelocType Type
Definition: COFFYAML.cpp:391
static cl::opt< bool > UsePostIncrementRanges("indvars-post-increment-ranges", cl::Hidden, cl::desc("Use post increment control-dependent ranges in IndVarSimplify"), cl::init(true))
This is the base class for all instructions that perform data casts.
Definition: InstrTypes.h:530
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree.
Definition: Dominators.h:162
Interface for visiting interesting IV users that are recognized but not simplified by this utility.
virtual ~IVVisitor()=default
const DominatorTree * DT
IVVisitor()=default
virtual void visitCast(CastInst *Cast)=0
const DominatorTree * getDomTree() const
virtual void anchor()
Represents a single loop in the control flow graph.
Definition: LoopInfo.h:44
This class uses information about analyze scalars to rewrite expressions in canonical form.
The main scalar evolution driver.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Definition: SmallVector.h:587
This pass provides access to the codegen interfaces that are needed for IR-level transformations.
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:45
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
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.
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.
std::pair< bool, 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...
Collect information about induction variables that are used by sign/zero extend operations.
PHINode * NarrowIV