LLVM 19.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
18namespace llvm {
19
20class Type;
21class WeakTrackingVH;
22template <typename T> class SmallVectorImpl;
23class CastInst;
24class DominatorTree;
25class Loop;
26class LoopInfo;
27class PHINode;
28class ScalarEvolution;
29class SCEVExpander;
30class TargetTransformInfo;
31
32/// Interface for visiting interesting IV users that are recognized but not
33/// simplified by this utility.
34class IVVisitor {
35protected:
36 const DominatorTree *DT = nullptr;
37
38 virtual void anchor();
39
40public:
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.
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.
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.
64struct WideIVInfo {
65 PHINode *NarrowIV = nullptr;
66
67 // Widest integer type created [sz]ext
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.
77 LoopInfo *LI, ScalarEvolution *SE, SCEVExpander &Rewriter,
79 unsigned &NumElimExt, unsigned &NumWidened,
80 bool HasGuards, bool UsePostIncrementRanges);
81
82} // end namespace llvm
83
84#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:574
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:586
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.
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