LLVM 20.0.0git
IVUsers.h
Go to the documentation of this file.
1//===- llvm/Analysis/IVUsers.h - Induction Variable Users -------*- 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 implements bookkeeping for "interesting" users of expressions
10// computed from induction variables.
11//
12//===----------------------------------------------------------------------===//
13
14#ifndef LLVM_ANALYSIS_IVUSERS_H
15#define LLVM_ANALYSIS_IVUSERS_H
16
20#include "llvm/IR/Instruction.h"
21#include "llvm/IR/ValueHandle.h"
22
23namespace llvm {
24
25class AssumptionCache;
26class DominatorTree;
27class ScalarEvolution;
28class SCEV;
29class IVUsers;
30
31/// IVStrideUse - Keep track of one use of a strided induction variable.
32/// The Expr member keeps track of the expression, User is the actual user
33/// instruction of the operand, and 'OperandValToReplace' is the operand of
34/// the User that is the use.
35class IVStrideUse final : public CallbackVH, public ilist_node<IVStrideUse> {
36 friend class IVUsers;
37public:
39 : CallbackVH(U), Parent(P), OperandValToReplace(O) {
40 }
41
42 /// getUser - Return the user instruction for this use.
44 return cast<Instruction>(getValPtr());
45 }
46
47 /// setUser - Assign a new user instruction for this use.
48 void setUser(Instruction *NewUser) {
49 setValPtr(NewUser);
50 }
51
52 /// getOperandValToReplace - Return the Value of the operand in the user
53 /// instruction that this IVStrideUse is representing.
55 return OperandValToReplace;
56 }
57
58 /// setOperandValToReplace - Assign a new Value as the operand value
59 /// to replace.
61 OperandValToReplace = Op;
62 }
63
64 /// getPostIncLoops - Return the set of loops for which the expression has
65 /// been adjusted to use post-inc mode.
67 return PostIncLoops;
68 }
69
70 /// transformToPostInc - Transform the expression to post-inc form for the
71 /// given loop.
72 void transformToPostInc(const Loop *L);
73
74private:
75 /// Parent - a pointer to the IVUsers that owns this IVStrideUse.
76 IVUsers *Parent;
77
78 /// OperandValToReplace - The Value of the operand in the user instruction
79 /// that this IVStrideUse is representing.
80 WeakTrackingVH OperandValToReplace;
81
82 /// PostIncLoops - The set of loops for which Expr has been adjusted to
83 /// use post-inc mode. This corresponds with SCEVExpander's post-inc concept.
84 PostIncLoopSet PostIncLoops;
85
86 /// Deleted - Implementation of CallbackVH virtual function to
87 /// receive notification when the User is deleted.
88 void deleted() override;
89};
90
91class IVUsers {
92 friend class IVStrideUse;
93 Loop *L;
95 LoopInfo *LI;
96 DominatorTree *DT;
99
100 /// IVUses - A list of all tracked IV uses of induction variable expressions
101 /// we are interested in.
102 ilist<IVStrideUse> IVUses;
103
104 // Ephemeral values used by @llvm.assume in this function.
106
107public:
109 ScalarEvolution *SE);
110
112 : L(std::move(X.L)), AC(std::move(X.AC)), DT(std::move(X.DT)),
113 SE(std::move(X.SE)), Processed(std::move(X.Processed)),
114 IVUses(std::move(X.IVUses)), EphValues(std::move(X.EphValues)) {
115 for (IVStrideUse &U : IVUses)
116 U.Parent = this;
117 }
118 IVUsers(const IVUsers &) = delete;
119 IVUsers &operator=(IVUsers &&) = delete;
120 IVUsers &operator=(const IVUsers &) = delete;
121
122 Loop *getLoop() const { return L; }
123
124 /// AddUsersIfInteresting - Inspect the specified Instruction. If it is a
125 /// reducible SCEV, recursively add its users to the IVUsesByStride set and
126 /// return true. Otherwise, return false.
128
130
131 /// getReplacementExpr - Return a SCEV expression which computes the
132 /// value of the OperandValToReplace of the given IVStrideUse.
133 const SCEV *getReplacementExpr(const IVStrideUse &IU) const;
134
135 /// getExpr - Return the expression for the use. Returns nullptr if the result
136 /// is not invertible.
137 const SCEV *getExpr(const IVStrideUse &IU) const;
138
139 const SCEV *getStride(const IVStrideUse &IU, const Loop *L) const;
140
143 iterator begin() { return IVUses.begin(); }
144 iterator end() { return IVUses.end(); }
145 const_iterator begin() const { return IVUses.begin(); }
146 const_iterator end() const { return IVUses.end(); }
147 bool empty() const { return IVUses.empty(); }
148
149 bool isIVUserOrOperand(Instruction *Inst) const {
150 return Processed.count(Inst);
151 }
152
153 void releaseMemory();
154
155 void print(raw_ostream &OS, const Module * = nullptr) const;
156
157 /// dump - This method is used for debugging.
158 void dump() const;
159};
160
162
164 std::unique_ptr<IVUsers> IU;
165
166public:
167 static char ID;
168
170
171 IVUsers &getIU() { return *IU; }
172 const IVUsers &getIU() const { return *IU; }
173
174 void getAnalysisUsage(AnalysisUsage &AU) const override;
175
176 bool runOnLoop(Loop *L, LPPassManager &LPM) override;
177
178 void releaseMemory() override;
179
180 void print(raw_ostream &OS, const Module * = nullptr) const override;
181};
182
183/// Analysis pass that exposes the \c IVUsers for a loop.
184class IVUsersAnalysis : public AnalysisInfoMixin<IVUsersAnalysis> {
186 static AnalysisKey Key;
187
188public:
190
193};
194
195}
196
197#endif
aarch64 AArch64 CCMP Pass
static GCMetadataPrinterRegistry::Add< ErlangGCPrinter > X("erlang", "erlang-compatible garbage collector")
This header provides classes for managing per-loop analyses.
#define I(x, y, z)
Definition: MD5.cpp:58
#define P(N)
raw_pwrite_stream & OS
A container for analyses that lazily runs them and caches their results.
Definition: PassManager.h:253
Represent the analysis usage information of a pass.
A cache of @llvm.assume calls within a function.
Value handle with callbacks on RAUW and destruction.
Definition: ValueHandle.h:383
void setValPtr(Value *P)
Definition: ValueHandle.h:390
This class represents an Operation in the Expression.
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree.
Definition: Dominators.h:162
IVStrideUse - Keep track of one use of a strided induction variable.
Definition: IVUsers.h:35
Instruction * getUser() const
getUser - Return the user instruction for this use.
Definition: IVUsers.h:43
void setOperandValToReplace(Value *Op)
setOperandValToReplace - Assign a new Value as the operand value to replace.
Definition: IVUsers.h:60
const PostIncLoopSet & getPostIncLoops() const
getPostIncLoops - Return the set of loops for which the expression has been adjusted to use post-inc ...
Definition: IVUsers.h:66
void transformToPostInc(const Loop *L)
transformToPostInc - Transform the expression to post-inc form for the given loop.
Definition: IVUsers.cpp:367
Value * getOperandValToReplace() const
getOperandValToReplace - Return the Value of the operand in the user instruction that this IVStrideUs...
Definition: IVUsers.h:54
IVStrideUse(IVUsers *P, Instruction *U, Value *O)
Definition: IVUsers.h:38
void setUser(Instruction *NewUser)
setUser - Assign a new user instruction for this use.
Definition: IVUsers.h:48
Analysis pass that exposes the IVUsers for a loop.
Definition: IVUsers.h:184
IVUsers run(Loop &L, LoopAnalysisManager &AM, LoopStandardAnalysisResults &AR)
Definition: IVUsers.cpp:36
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - This function should be overriden by passes that need analysis information to do t...
Definition: IVUsers.cpp:304
bool runOnLoop(Loop *L, LPPassManager &LPM) override
Definition: IVUsers.cpp:312
void print(raw_ostream &OS, const Module *=nullptr) const override
print - Print out the internal state of the pass.
Definition: IVUsers.cpp:323
void releaseMemory() override
releaseMemory() - This member can be implemented by a pass if it wants to be able to release its memo...
Definition: IVUsers.cpp:327
const IVUsers & getIU() const
Definition: IVUsers.h:172
void dump() const
dump - This method is used for debugging.
Definition: IVUsers.cpp:292
ilist< IVStrideUse >::const_iterator const_iterator
Definition: IVUsers.h:142
bool isIVUserOrOperand(Instruction *Inst) const
Definition: IVUsers.h:149
iterator end()
Definition: IVUsers.h:144
IVStrideUse & AddUser(Instruction *User, Value *Operand)
Definition: IVUsers.cpp:246
void releaseMemory()
Definition: IVUsers.cpp:295
Loop * getLoop() const
Definition: IVUsers.h:122
IVUsers & operator=(IVUsers &&)=delete
const SCEV * getStride(const IVStrideUse &IU, const Loop *L) const
Definition: IVUsers.cpp:358
IVUsers(const IVUsers &)=delete
const SCEV * getReplacementExpr(const IVStrideUse &IU) const
getReplacementExpr - Return a SCEV expression which computes the value of the OperandValToReplace of ...
Definition: IVUsers.cpp:331
IVUsers(IVUsers &&X)
Definition: IVUsers.h:111
iterator begin()
Definition: IVUsers.h:143
bool AddUsersIfInteresting(Instruction *I)
AddUsersIfInteresting - Inspect the specified Instruction.
Definition: IVUsers.cpp:136
const_iterator end() const
Definition: IVUsers.h:146
ilist< IVStrideUse >::iterator iterator
Definition: IVUsers.h:141
const_iterator begin() const
Definition: IVUsers.h:145
const SCEV * getExpr(const IVStrideUse &IU) const
getExpr - Return the expression for the use.
Definition: IVUsers.cpp:336
IVUsers & operator=(const IVUsers &)=delete
void print(raw_ostream &OS, const Module *=nullptr) const
Definition: IVUsers.cpp:265
bool empty() const
Definition: IVUsers.h:147
Represents a single loop in the control flow graph.
Definition: LoopInfo.h:39
A Module instance is used to store all the information related to an LLVM module.
Definition: Module.h:65
This class represents an analyzed expression in the program.
The main scalar evolution driver.
size_type count(ConstPtrType Ptr) const
count - Return 1 if the specified pointer is in the set, 0 otherwise.
Definition: SmallPtrSet.h:452
Value * getValPtr() const
Definition: ValueHandle.h:99
LLVM Value Representation.
Definition: Value.h:74
Value handle that is nullable, but tries to track the Value.
Definition: ValueHandle.h:204
An intrusive list with ownership and callbacks specified/controlled by ilist_traits,...
Definition: ilist.h:328
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:52
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
DWARFExpression::Operation Op
Pass * createIVUsersPass()
Definition: IVUsers.cpp:51
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
Definition: STLExtras.h:1873
Implement std::hash so that hash_code can be used in STL containers.
Definition: BitVector.h:858
A CRTP mix-in that provides informational APIs needed for analysis passes.
Definition: PassManager.h:92
A special type used by analysis passes to provide an address that identifies that particular analysis...
Definition: Analysis.h:28
The adaptor from a function pass to a loop pass computes these analyses and makes them available to t...