LLVM: include/llvm/Analysis/PtrUseVisitor.h Source File (original) (raw)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22#ifndef LLVM_ANALYSIS_PTRUSEVISITOR_H
23#define LLVM_ANALYSIS_PTRUSEVISITOR_H
24
32#include
33#include <type_traits>
34
35namespace llvm {
37
39
40
41
42
43
44
45
47public:
48
49
50
51
52
54 public:
55
57 AbortedInfo = nullptr;
58 EscapedInfo = nullptr;
59 }
60
61
62 bool isAborted() const { return AbortedInfo != nullptr; }
63
64
65 bool isEscaped() const { return EscapedInfo != nullptr; }
66
67
69
70
71
72
74
75
76
77
79
80
81
83
84
85
87 assert(I && "Expected a valid pointer in setAborted");
88 AbortedInfo = I;
89 }
90
91
92
94 assert(I && "Expected a valid pointer in setEscaped");
95 EscapedInfo = I;
96 }
97
98
100 assert(I && "Expected a valid pointer in setEscapedReadOnly");
101 EscapedReadOnly = I;
102 }
103
104
105
106
107
112
113 private:
117 };
118
119protected:
121
122
123
124
125
127
128
129
130
131
138
139
141
142
144
145
146
147
148
149
150
151
153
154
155
157
158
160
161
162
163
164
166
167
168
169
170
172
173
174
175
176
178};
179
180}
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207template
211
213
214public:
216 static_assert(std::is_base_of<PtrUseVisitor, DerivedT>::value,
217 "Must pass the derived type to this template!");
218 }
219
220
221
222
223
225
226
227
228 assert(I.getType()->isPointerTy());
233 PI.reset();
234
235
237
238
245
247 static_cast<DerivedT*>(this)->visit(I);
248 if (PI.isAborted())
249 break;
250 }
251 return PI;
252 }
253
254protected:
256 if (SI.getValueOperand() == U->get())
258 }
259
263
267
270 }
271
274 return;
275
276
280 }
281
282
284 }
285
286
287
290 switch (II.getIntrinsicID()) {
291 default:
293
294
295
296 case Intrinsic::fake_use:
298 return;
299
300 case Intrinsic::lifetime_start:
301 case Intrinsic::lifetime_end:
302 return;
303 }
304 }
305
306
307
309 PI.setEscaped(&CB);
311 }
312};
313
314}
315
316#endif
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
This file implements a class to represent arbitrary precision integral constant values and operations...
uint64_t IntrinsicInst * II
This file defines the PointerIntPair class.
This file defines the SmallPtrSet class.
This file defines the SmallVector class.
Class for arbitrary precision integers.
This class represents a conversion between pointers from one address space to another.
This class represents a no-op cast from one type to another.
Base class for all callable instructions (InvokeInst and CallInst) Holds everything related to callin...
A parsed version of the target data layout string in and methods for querying it.
an instruction for type-safe pointer arithmetic to access elements of arrays and structs
Base class for instruction visitors.
void visitCallBase(CallBase &I)
void visitIntrinsicInst(IntrinsicInst &I)
void visit(Iterator Start, Iterator End)
Class to represent integer types.
unsigned getBitWidth() const
Get the number of bits in this IntegerType.
A wrapper class for inspecting calls to intrinsic functions.
This is the common base class for memset/memcpy/memmove.
PointerIntPair - This class implements a pair of a pointer and small integer.
PointerTy getPointer() const
This class represents a cast from a pointer to an integer.
void visitCallBase(CallBase &CB)
Definition PtrUseVisitor.h:308
PtrUseVisitor(const DataLayout &DL)
Definition PtrUseVisitor.h:215
PtrInfo visitPtr(Value &I)
Recursively visit the uses of the given pointer.
Definition PtrUseVisitor.h:224
void visitGetElementPtrInst(GetElementPtrInst &GEPI)
Definition PtrUseVisitor.h:272
void visitAddrSpaceCastInst(AddrSpaceCastInst &ASC)
Definition PtrUseVisitor.h:264
void visitBitCastInst(BitCastInst &BC)
Definition PtrUseVisitor.h:260
void visitStoreInst(StoreInst &SI)
Definition PtrUseVisitor.h:255
void visitIntrinsicInst(IntrinsicInst &II)
Definition PtrUseVisitor.h:289
void visitPtrToIntInst(PtrToIntInst &I)
Definition PtrUseVisitor.h:268
void visitMemIntrinsic(MemIntrinsic &I)
Definition PtrUseVisitor.h:288
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
An instruction for storing to memory.
A Use represents the edge between a Value definition and its users.
LLVM Value Representation.
This class provides information about the result of a visit.
Definition PtrUseVisitor.h:53
Instruction * getEscapedReadOnlyInst() const
Get the instruction causing the pointer to escape which is a read-only nocapture call.
Definition PtrUseVisitor.h:82
Instruction * getAbortingInst() const
Get the instruction causing the visit to abort.
Definition PtrUseVisitor.h:73
Instruction * getEscapingInst() const
Get the instruction causing the pointer to escape.
Definition PtrUseVisitor.h:78
bool isEscaped() const
Is the pointer escaped at some point?
Definition PtrUseVisitor.h:65
void setEscaped(Instruction *I)
Mark the pointer as escaped.
Definition PtrUseVisitor.h:93
void setAborted(Instruction *I)
Mark the visit as aborted.
Definition PtrUseVisitor.h:86
bool isEscapedReadOnly() const
Is the pointer escaped into a read-only nocapture call at some point?
Definition PtrUseVisitor.h:68
void reset()
Reset the pointer info, clearing all state.
Definition PtrUseVisitor.h:56
bool isAborted() const
Did we abort the visit early?
Definition PtrUseVisitor.h:62
void setEscapedAndAborted(Instruction *I)
Mark the pointer as escaped, and the visit as aborted.
Definition PtrUseVisitor.h:108
void setEscapedReadOnly(Instruction *I)
Mark the pointer as escaped into a readonly-nocapture call.
Definition PtrUseVisitor.h:99
Implementation of non-dependent functionality for PtrUseVisitor.
Definition PtrUseVisitor.h:46
APInt Offset
The constant offset of the use if that is known.
Definition PtrUseVisitor.h:159
void enqueueUsers(Value &I)
Enqueue the users of this instruction in the visit worklist.
PtrUseVisitorBase(const DataLayout &DL)
Note that the constructor is protected because this class must be a base class, we can't create insta...
Definition PtrUseVisitor.h:165
SmallVector< UseToVisit, 8 > Worklist
The worklist of to-visit uses.
Definition PtrUseVisitor.h:140
bool IsOffsetKnown
True if we have a known constant offset for the use currently being visited.
Definition PtrUseVisitor.h:156
bool adjustOffsetForGEP(GetElementPtrInst &GEPI)
Walk the operands of a GEP and adjust the offset as appropriate.
PtrInfo PI
The info collected about the pointer being visited thus far.
Definition PtrUseVisitor.h:126
Use * U
The use currently being visited.
Definition PtrUseVisitor.h:152
const DataLayout & DL
Definition PtrUseVisitor.h:120
SmallPtrSet< Use *, 8 > VisitedUses
A set of visited uses to break cycles in unreachable code.
Definition PtrUseVisitor.h:143
A self-contained host- and target-independent arbitrary-precision floating-point software implementat...
This is an optimization pass for GlobalISel generic memory operations.
bool isa(const From &Val)
isa - Return true if the parameter to the template is an instance of one of the template type argu...
decltype(auto) cast(const From &Val)
cast - Return the argument parameter cast to the specified type.
A struct of the data needed to visit a particular use.
Definition PtrUseVisitor.h:132
UseAndIsOffsetKnownPair UseAndIsOffsetKnown
Definition PtrUseVisitor.h:135
PointerIntPair< Use *, 1, bool > UseAndIsOffsetKnownPair
Definition PtrUseVisitor.h:133
APInt Offset
Definition PtrUseVisitor.h:136