Skip to content

Commit 41f14cf

Browse files
author
Dan Gohman
committed
Remove the experimental AliasAnalysis::getDependency interface, which
isn't a good level of abstraction for memdep. Instead, generalize AliasAnalysis::alias and related interfaces with a new Location class for describing a memory location. For now, this is the same Pointer and Size as before, plus an additional field for a TBAA tag. Also, introduce a fixed MD_tbaa metadata tag kind. llvm-svn: 113858
1 parent 62e9a05 commit 41f14cf

13 files changed

+256
-510
lines changed

Diff for: llvm/include/llvm/Analysis/AliasAnalysis.h

+108-127
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,22 @@ class AliasAnalysis {
8383
/// Alias Queries...
8484
///
8585

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+
86102
/// Alias analysis result - Either we know for sure that it does not alias, we
87103
/// know for sure it must alias, or we don't know anything: The two pointers
88104
/// _might_ alias. This enum is designed so you can do things like:
@@ -98,27 +114,41 @@ class AliasAnalysis {
98114
/// Returns a Result indicating whether the two pointers are aliased to each
99115
/// other. This is the interface that must be implemented by specific alias
100116
/// 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);
104118

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.
106126
AliasResult alias(const Value *V1, const Value *V2) {
107127
return alias(V1, UnknownSize, V2, UnknownSize);
108128
}
109129

110130
/// isNoAlias - A trivial helper function to check to see if the specified
111131
/// 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.
112137
bool isNoAlias(const Value *V1, unsigned V1Size,
113138
const Value *V2, unsigned V2Size) {
114-
return alias(V1, V1Size, V2, V2Size) == NoAlias;
139+
return isNoAlias(Location(V1, V1Size), Location(V2, V2Size));
115140
}
116141

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
119144
/// instructions from constant pointers.
120145
///
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+
}
122152

123153
//===--------------------------------------------------------------------===//
124154
/// Simple mod/ref information...
@@ -220,55 +250,87 @@ class AliasAnalysis {
220250

221251

222252
/// 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
224254
/// that doesn't read or write memory may be trivially LICM'd for example.
225255
ModRefResult getModRefInfo(const Instruction *I,
226-
const Value *P, unsigned Size) {
256+
const Location &Loc) {
227257
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);
233263
default: return NoModRef;
234264
}
235265
}
236266

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+
237273
/// 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.
240275
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+
}
242283

243284
/// 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.
246291
ModRefResult getModRefInfo(const CallInst *C, const Value *P, unsigned Size) {
247-
return getModRefInfo(ImmutableCallSite(C), P, Size);
292+
return getModRefInfo(C, Location(P, Size));
248293
}
249294

250295
/// 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.
253303
ModRefResult getModRefInfo(const InvokeInst *I,
254304
const Value *P, unsigned Size) {
255-
return getModRefInfo(ImmutableCallSite(I), P, Size);
305+
return getModRefInfo(I, Location(P, Size));
256306
}
257307

258308
/// 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+
}
262316

263317
/// 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+
}
267325

268326
/// 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+
}
272334

273335
/// getModRefInfo - Return information about whether two call sites may refer
274336
/// to the same set of memory locations. See
@@ -277,101 +339,31 @@ class AliasAnalysis {
277339
virtual ModRefResult getModRefInfo(ImmutableCallSite CS1,
278340
ImmutableCallSite CS2);
279341

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-
359342
//===--------------------------------------------------------------------===//
360343
/// Higher level methods for querying mod/ref information.
361344
///
362345

363346
/// canBasicBlockModify - Return true if it is possible for execution of the
364347
/// 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+
}
367354

368355
/// canInstructionRangeModify - Return true if it is possible for the
369356
/// execution of the specified instructions to modify the value pointed to by
370357
/// Ptr. The instructions to consider are all of the instructions in the
371358
/// range of [I1,I2] INCLUSIVE. I1 and I2 must be in the same basic block.
372-
///
373359
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+
}
375367

376368
//===--------------------------------------------------------------------===//
377369
/// Methods that clients should call when they transform the program to allow
@@ -401,17 +393,6 @@ class AliasAnalysis {
401393
copyValue(Old, New);
402394
deleteValue(Old);
403395
}
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-
415396
};
416397

417398
/// isNoAliasCall - Return true if this pointer is returned by a noalias

Diff for: llvm/include/llvm/Analysis/LibCallAliasAnalysis.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ namespace llvm {
3636
~LibCallAliasAnalysis();
3737

3838
ModRefResult getModRefInfo(ImmutableCallSite CS,
39-
const Value *P, unsigned Size);
39+
const Location &Loc);
4040

4141
ModRefResult getModRefInfo(ImmutableCallSite CS1,
4242
ImmutableCallSite CS2) {
@@ -64,7 +64,7 @@ namespace llvm {
6464
private:
6565
ModRefResult AnalyzeLibCallDetails(const LibCallFunctionInfo *FI,
6666
ImmutableCallSite CS,
67-
const Value *P, unsigned Size);
67+
const Location &Loc);
6868
};
6969
} // End of llvm namespace
7070

Diff for: llvm/include/llvm/Analysis/LibCallSemantics.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ namespace llvm {
4848
Yes, No, Unknown
4949
};
5050
LocResult (*isLocation)(ImmutableCallSite CS,
51-
const Value *Ptr, unsigned Size);
51+
const AliasAnalysis::Location &Loc);
5252
};
5353

5454
/// LibCallFunctionInfo - Each record in the array of FunctionInfo structs

Diff for: llvm/include/llvm/LLVMContext.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ class LLVMContext {
3737
// Pinned metadata names, which always have the same value. This is a
3838
// compile-time performance optimization, not a correctness optimization.
3939
enum {
40-
MD_dbg = 0 // "dbg"
40+
MD_dbg = 0, // "dbg"
41+
MD_tbaa = 1 // "tbaa"
4142
};
4243

4344
/// getMDKindID - Return a unique non-zero ID for the specified metadata kind.

0 commit comments

Comments
 (0)