@@ -83,6 +83,22 @@ class AliasAnalysis {
83
83
// / Alias Queries...
84
84
// /
85
85
86
+ // / Location - A description of a memory location.
87
+ struct Location {
88
+ // / Ptr - The address of the start of the location.
89
+ const Value *Ptr ;
90
+ // / Size - The size of the location.
91
+ unsigned Size ;
92
+ // / TBAATag - The metadata node which describes the TBAA type of
93
+ // / the location, or null if there is no (unique) tag.
94
+ const MDNode *TBAATag;
95
+
96
+ explicit Location (const Value *P = 0 ,
97
+ unsigned S = UnknownSize,
98
+ const MDNode *N = 0 )
99
+ : Ptr(P), Size(S), TBAATag(N) {}
100
+ };
101
+
86
102
// / Alias analysis result - Either we know for sure that it does not alias, we
87
103
// / know for sure it must alias, or we don't know anything: The two pointers
88
104
// / _might_ alias. This enum is designed so you can do things like:
@@ -98,27 +114,41 @@ class AliasAnalysis {
98
114
// / Returns a Result indicating whether the two pointers are aliased to each
99
115
// / other. This is the interface that must be implemented by specific alias
100
116
// / analysis implementations.
101
- // /
102
- virtual AliasResult alias (const Value *V1, unsigned V1Size,
103
- const Value *V2, unsigned V2Size);
117
+ virtual AliasResult alias (const Location &LocA, const Location &LocB);
104
118
105
- // / alias - A convenience wrapper for the case where the sizes are unknown.
119
+ // / alias - A convenience wrapper.
120
+ AliasResult alias (const Value *V1, unsigned V1Size,
121
+ const Value *V2, unsigned V2Size) {
122
+ return alias (Location (V1, V1Size), Location (V2, V2Size));
123
+ }
124
+
125
+ // / alias - A convenience wrapper.
106
126
AliasResult alias (const Value *V1, const Value *V2) {
107
127
return alias (V1, UnknownSize, V2, UnknownSize);
108
128
}
109
129
110
130
// / isNoAlias - A trivial helper function to check to see if the specified
111
131
// / pointers are no-alias.
132
+ bool isNoAlias (const Location &LocA, const Location &LocB) {
133
+ return alias (LocA, LocB) == NoAlias;
134
+ }
135
+
136
+ // / isNoAlias - A convenience wrapper.
112
137
bool isNoAlias (const Value *V1, unsigned V1Size,
113
138
const Value *V2, unsigned V2Size) {
114
- return alias ( V1, V1Size, V2, V2Size) == NoAlias ;
139
+ return isNoAlias ( Location ( V1, V1Size), Location ( V2, V2Size)) ;
115
140
}
116
141
117
- // / pointsToConstantMemory - If the specified pointer is known to point into
118
- // / constant global memory , return true. This allows disambiguation of store
142
+ // / pointsToConstantMemory - If the specified memory location is known to be
143
+ // / constant, return true. This allows disambiguation of store
119
144
// / instructions from constant pointers.
120
145
// /
121
- virtual bool pointsToConstantMemory (const Value *P);
146
+ virtual bool pointsToConstantMemory (const Location &Loc);
147
+
148
+ // / pointsToConstantMemory - A convenient wrapper.
149
+ bool pointsToConstantMemory (const Value *P) {
150
+ return pointsToConstantMemory (Location (P));
151
+ }
122
152
123
153
// ===--------------------------------------------------------------------===//
124
154
// / Simple mod/ref information...
@@ -220,55 +250,87 @@ class AliasAnalysis {
220
250
221
251
222
252
// / getModRefInfo - Return information about whether or not an instruction may
223
- // / read or write memory specified by the pointer operand . An instruction
253
+ // / read or write the specified memory location . An instruction
224
254
// / that doesn't read or write memory may be trivially LICM'd for example.
225
255
ModRefResult getModRefInfo (const Instruction *I,
226
- const Value *P, unsigned Size ) {
256
+ const Location &Loc ) {
227
257
switch (I->getOpcode ()) {
228
- case Instruction::VAArg: return getModRefInfo ((const VAArgInst*)I, P, Size );
229
- case Instruction::Load: return getModRefInfo ((const LoadInst*)I, P, Size );
230
- case Instruction::Store: return getModRefInfo ((const StoreInst*)I, P, Size );
231
- case Instruction::Call: return getModRefInfo ((const CallInst*)I, P, Size );
232
- case Instruction::Invoke: return getModRefInfo ((const InvokeInst*)I,P, Size );
258
+ case Instruction::VAArg: return getModRefInfo ((const VAArgInst*)I, Loc );
259
+ case Instruction::Load: return getModRefInfo ((const LoadInst*)I, Loc );
260
+ case Instruction::Store: return getModRefInfo ((const StoreInst*)I, Loc );
261
+ case Instruction::Call: return getModRefInfo ((const CallInst*)I, Loc );
262
+ case Instruction::Invoke: return getModRefInfo ((const InvokeInst*)I,Loc );
233
263
default : return NoModRef;
234
264
}
235
265
}
236
266
267
+ // / getModRefInfo - A convenience wrapper.
268
+ ModRefResult getModRefInfo (const Instruction *I,
269
+ const Value *P, unsigned Size ) {
270
+ return getModRefInfo (I, Location (P, Size ));
271
+ }
272
+
237
273
// / getModRefInfo (for call sites) - Return whether information about whether
238
- // / a particular call site modifies or reads the memory specified by the
239
- // / pointer.
274
+ // / a particular call site modifies or reads the specified memory location.
240
275
virtual ModRefResult getModRefInfo (ImmutableCallSite CS,
241
- const Value *P, unsigned Size );
276
+ const Location &Loc);
277
+
278
+ // / getModRefInfo (for call sites) - A convenience wrapper.
279
+ ModRefResult getModRefInfo (ImmutableCallSite CS,
280
+ const Value *P, unsigned Size ) {
281
+ return getModRefInfo (CS, Location (P, Size ));
282
+ }
242
283
243
284
// / getModRefInfo (for calls) - Return whether information about whether
244
- // / a particular call modifies or reads the memory specified by the
245
- // / pointer.
285
+ // / a particular call modifies or reads the specified memory location.
286
+ ModRefResult getModRefInfo (const CallInst *C, const Location &Loc) {
287
+ return getModRefInfo (ImmutableCallSite (C), Loc);
288
+ }
289
+
290
+ // / getModRefInfo (for calls) - A convenience wrapper.
246
291
ModRefResult getModRefInfo (const CallInst *C, const Value *P, unsigned Size ) {
247
- return getModRefInfo (ImmutableCallSite (C), P, Size );
292
+ return getModRefInfo (C, Location ( P, Size ) );
248
293
}
249
294
250
295
// / getModRefInfo (for invokes) - Return whether information about whether
251
- // / a particular invoke modifies or reads the memory specified by the
252
- // / pointer.
296
+ // / a particular invoke modifies or reads the specified memory location.
297
+ ModRefResult getModRefInfo (const InvokeInst *I,
298
+ const Location &Loc) {
299
+ return getModRefInfo (ImmutableCallSite (I), Loc);
300
+ }
301
+
302
+ // / getModRefInfo (for invokes) - A convenience wrapper.
253
303
ModRefResult getModRefInfo (const InvokeInst *I,
254
304
const Value *P, unsigned Size ) {
255
- return getModRefInfo (ImmutableCallSite (I), P, Size );
305
+ return getModRefInfo (I, Location ( P, Size ) );
256
306
}
257
307
258
308
// / getModRefInfo (for loads) - Return whether information about whether
259
- // / a particular load modifies or reads the memory specified by the
260
- // / pointer.
261
- ModRefResult getModRefInfo (const LoadInst *L, const Value *P, unsigned Size );
309
+ // / a particular load modifies or reads the specified memory location.
310
+ ModRefResult getModRefInfo (const LoadInst *L, const Location &Loc);
311
+
312
+ // / getModRefInfo (for loads) - A convenience wrapper.
313
+ ModRefResult getModRefInfo (const LoadInst *L, const Value *P, unsigned Size ) {
314
+ return getModRefInfo (L, Location (P, Size ));
315
+ }
262
316
263
317
// / getModRefInfo (for stores) - Return whether information about whether
264
- // / a particular store modifies or reads the memory specified by the
265
- // / pointer.
266
- ModRefResult getModRefInfo (const StoreInst *S, const Value *P, unsigned Size );
318
+ // / a particular store modifies or reads the specified memory location.
319
+ ModRefResult getModRefInfo (const StoreInst *S, const Location &Loc);
320
+
321
+ // / getModRefInfo (for stores) - A convenience wrapper.
322
+ ModRefResult getModRefInfo (const StoreInst *S, const Value *P, unsigned Size ) {
323
+ return getModRefInfo (S, Location (P, Size ));
324
+ }
267
325
268
326
// / getModRefInfo (for va_args) - Return whether information about whether
269
- // / a particular va_arg modifies or reads the memory specified by the
270
- // / pointer.
271
- ModRefResult getModRefInfo (const VAArgInst* I, const Value* P, unsigned Size );
327
+ // / a particular va_arg modifies or reads the specified memory location.
328
+ ModRefResult getModRefInfo (const VAArgInst* I, const Location &Loc);
329
+
330
+ // / getModRefInfo (for va_args) - A convenience wrapper.
331
+ ModRefResult getModRefInfo (const VAArgInst* I, const Value* P, unsigned Size ) {
332
+ return getModRefInfo (I, Location (P, Size ));
333
+ }
272
334
273
335
// / getModRefInfo - Return information about whether two call sites may refer
274
336
// / to the same set of memory locations. See
@@ -277,101 +339,31 @@ class AliasAnalysis {
277
339
virtual ModRefResult getModRefInfo (ImmutableCallSite CS1,
278
340
ImmutableCallSite CS2);
279
341
280
- // ===--------------------------------------------------------------------===//
281
- // / Dependence queries.
282
- // /
283
-
284
- // / DependenceResult - These are the return values for getDependence queries.
285
- // / They are defined in terms of "memory", but they are also used to model
286
- // / other side effects, such as I/O and volatility.
287
- enum DependenceResult {
288
- // / ReadThenRead - The instructions are ReadThenReadSome and the second
289
- // / instruction reads from exactly the same memory read from by the first.
290
- ReadThenRead,
291
-
292
- // / ReadThenReadSome - The instructions are Independent, both are read-only,
293
- // / and the second instruction reads from a subset of the memory read from
294
- // / by the first.
295
- ReadThenReadSome,
296
-
297
- // / Independent - Neither instruction reads from or writes to memory written
298
- // / to by the other. All enum values lower than this one are special cases
299
- // / of Indepenent.
300
- Independent,
301
-
302
- // / WriteThenRead - The instructions are WriteThenReadSome and the second
303
- // / instruction reads from exactly the same memory written by the first.
304
- WriteThenRead,
305
-
306
- // / WriteThenReadSome - The first instruction is write-only, the second
307
- // / instruction is read-only, and the second only reads from memory
308
- // / written to by the first.
309
- WriteThenReadSome,
310
-
311
- // / ReadThenWrite - The first instruction is read-only, the second
312
- // / instruction is write-only, and the second wrotes to exactly the
313
- // / same memory read from by the first.
314
- ReadThenWrite,
315
-
316
- // / WriteThenWrite - The instructions are WriteThenWriteSome, and the
317
- // / second instruction writes to exactly the same memory written to by
318
- // / the first.
319
- WriteThenWrite,
320
-
321
- // / WriteSomeThenWrite - Both instructions are write-only, and the second
322
- // / instruction writes to a superset of the memory written to by the first.
323
- WriteSomeThenWrite,
324
-
325
- // / Unknown - The relationship between the instructions cannot be
326
- // / determined or does not fit into any of the cases defined here.
327
- Unknown
328
- };
329
-
330
- // / DependenceQueryFlags - Flags for refining dependence queries.
331
- enum DependenceQueryFlags {
332
- Default = 0 ,
333
- IgnoreLoads = 1 ,
334
- IgnoreStores = 2
335
- };
336
-
337
- // / getDependence - Determine the dependence relationship between the
338
- // / instructions. This does not include "register" dependencies; it just
339
- // / considers memory references and other side effects.
340
- // / WARNING: This is an experimental interface.
341
- DependenceResult getDependence (const Instruction *First,
342
- const Instruction *Second) {
343
- return getDependence (First, 0 , Default, Second, 0 , Default);
344
- }
345
-
346
- // / getDependence - Determine the dependence relationship between the
347
- // / instructions. This does not include "register" dependencies; it just
348
- // / considers memory references and other side effects. This overload
349
- // / has additional parameters to allow phi-translated addresses to be
350
- // / specified, and additional flags to refine the query.
351
- // / WARNING: This is an experimental interface.
352
- virtual DependenceResult getDependence (const Instruction *First,
353
- const Value *FirstPHITranslatedAddr,
354
- DependenceQueryFlags FirstFlags,
355
- const Instruction *Second,
356
- const Value *SecondPHITranslatedAddr,
357
- DependenceQueryFlags SecondFlags);
358
-
359
342
// ===--------------------------------------------------------------------===//
360
343
// / Higher level methods for querying mod/ref information.
361
344
// /
362
345
363
346
// / canBasicBlockModify - Return true if it is possible for execution of the
364
347
// / specified basic block to modify the value pointed to by Ptr.
365
- // /
366
- bool canBasicBlockModify (const BasicBlock &BB, const Value *P, unsigned Size );
348
+ bool canBasicBlockModify (const BasicBlock &BB, const Location &Loc);
349
+
350
+ // / canBasicBlockModify - A convenience wrapper.
351
+ bool canBasicBlockModify (const BasicBlock &BB, const Value *P, unsigned Size ){
352
+ return canBasicBlockModify (BB, Location (P, Size ));
353
+ }
367
354
368
355
// / canInstructionRangeModify - Return true if it is possible for the
369
356
// / execution of the specified instructions to modify the value pointed to by
370
357
// / Ptr. The instructions to consider are all of the instructions in the
371
358
// / range of [I1,I2] INCLUSIVE. I1 and I2 must be in the same basic block.
372
- // /
373
359
bool canInstructionRangeModify (const Instruction &I1, const Instruction &I2,
374
- const Value *Ptr , unsigned Size );
360
+ const Location &Loc);
361
+
362
+ // / canInstructionRangeModify - A convenience wrapper.
363
+ bool canInstructionRangeModify (const Instruction &I1, const Instruction &I2,
364
+ const Value *Ptr , unsigned Size ) {
365
+ return canInstructionRangeModify (I1, I2, Location (Ptr , Size ));
366
+ }
375
367
376
368
// ===--------------------------------------------------------------------===//
377
369
// / Methods that clients should call when they transform the program to allow
@@ -401,17 +393,6 @@ class AliasAnalysis {
401
393
copyValue (Old, New);
402
394
deleteValue (Old);
403
395
}
404
-
405
- protected:
406
- // / getDependenceViaModRefInfo - Helper function for implementing getDependence
407
- // / in implementations which already have getModRefInfo implementations.
408
- DependenceResult getDependenceViaModRefInfo (const Instruction *First,
409
- const Value *FirstPHITranslatedAddr,
410
- DependenceQueryFlags FirstFlags,
411
- const Instruction *Second,
412
- const Value *SecondPHITranslatedAddr,
413
- DependenceQueryFlags SecondFlags);
414
-
415
396
};
416
397
417
398
// / isNoAliasCall - Return true if this pointer is returned by a noalias
0 commit comments