Make DataLayout Non-Optional in the Module
[oota-llvm.git] / include / llvm / Analysis / AliasAnalysis.h
1 //===- llvm/Analysis/AliasAnalysis.h - Alias Analysis Interface -*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file defines the generic AliasAnalysis interface, which is used as the
11 // common interface used by all clients of alias analysis information, and
12 // implemented by all alias analysis implementations.  Mod/Ref information is
13 // also captured by this interface.
14 //
15 // Implementations of this interface must implement the various virtual methods,
16 // which automatically provides functionality for the entire suite of client
17 // APIs.
18 //
19 // This API identifies memory regions with the Location class. The pointer
20 // component specifies the base memory address of the region. The Size specifies
21 // the maximum size (in address units) of the memory region, or UnknownSize if
22 // the size is not known. The TBAA tag identifies the "type" of the memory
23 // reference; see the TypeBasedAliasAnalysis class for details.
24 //
25 // Some non-obvious details include:
26 //  - Pointers that point to two completely different objects in memory never
27 //    alias, regardless of the value of the Size component.
28 //  - NoAlias doesn't imply inequal pointers. The most obvious example of this
29 //    is two pointers to constant memory. Even if they are equal, constant
30 //    memory is never stored to, so there will never be any dependencies.
31 //    In this and other situations, the pointers may be both NoAlias and
32 //    MustAlias at the same time. The current API can only return one result,
33 //    though this is rarely a problem in practice.
34 //
35 //===----------------------------------------------------------------------===//
36
37 #ifndef LLVM_ANALYSIS_ALIASANALYSIS_H
38 #define LLVM_ANALYSIS_ALIASANALYSIS_H
39
40 #include "llvm/ADT/DenseMap.h"
41 #include "llvm/IR/CallSite.h"
42 #include "llvm/IR/Metadata.h"
43
44 namespace llvm {
45
46 class LoadInst;
47 class StoreInst;
48 class VAArgInst;
49 class DataLayout;
50 class TargetLibraryInfo;
51 class Pass;
52 class AnalysisUsage;
53 class MemTransferInst;
54 class MemIntrinsic;
55 class DominatorTree;
56
57 class AliasAnalysis {
58 protected:
59   const DataLayout *DL;
60   const TargetLibraryInfo *TLI;
61
62 private:
63   AliasAnalysis *AA;       // Previous Alias Analysis to chain to.
64
65 protected:
66   /// InitializeAliasAnalysis - Subclasses must call this method to initialize
67   /// the AliasAnalysis interface before any other methods are called.  This is
68   /// typically called by the run* methods of these subclasses.  This may be
69   /// called multiple times.
70   ///
71   void InitializeAliasAnalysis(Pass *P, const DataLayout *DL);
72
73   /// getAnalysisUsage - All alias analysis implementations should invoke this
74   /// directly (using AliasAnalysis::getAnalysisUsage(AU)).
75   virtual void getAnalysisUsage(AnalysisUsage &AU) const;
76
77 public:
78   static char ID; // Class identification, replacement for typeinfo
79   AliasAnalysis() : DL(nullptr), TLI(nullptr), AA(nullptr) {}
80   virtual ~AliasAnalysis();  // We want to be subclassed
81
82   /// UnknownSize - This is a special value which can be used with the
83   /// size arguments in alias queries to indicate that the caller does not
84   /// know the sizes of the potential memory references.
85   static uint64_t const UnknownSize = ~UINT64_C(0);
86
87   /// getDataLayout - Return a pointer to the current DataLayout object, or
88   /// null if no DataLayout object is available.
89   ///
90   const DataLayout *getDataLayout() const { return DL; }
91
92   /// getTargetLibraryInfo - Return a pointer to the current TargetLibraryInfo
93   /// object, or null if no TargetLibraryInfo object is available.
94   ///
95   const TargetLibraryInfo *getTargetLibraryInfo() const { return TLI; }
96
97   /// getTypeStoreSize - Return the DataLayout store size for the given type,
98   /// if known, or a conservative value otherwise.
99   ///
100   uint64_t getTypeStoreSize(Type *Ty);
101
102   //===--------------------------------------------------------------------===//
103   /// Alias Queries...
104   ///
105
106   /// Location - A description of a memory location.
107   struct Location {
108     /// Ptr - The address of the start of the location.
109     const Value *Ptr;
110     /// Size - The maximum size of the location, in address-units, or
111     /// UnknownSize if the size is not known.  Note that an unknown size does
112     /// not mean the pointer aliases the entire virtual address space, because
113     /// there are restrictions on stepping out of one object and into another.
114     /// See http://llvm.org/docs/LangRef.html#pointeraliasing
115     uint64_t Size;
116     /// AATags - The metadata nodes which describes the aliasing of the
117     /// location (each member is null if that kind of information is
118     /// unavailable)..
119     AAMDNodes AATags;
120
121     explicit Location(const Value *P = nullptr, uint64_t S = UnknownSize,
122                       const AAMDNodes &N = AAMDNodes())
123       : Ptr(P), Size(S), AATags(N) {}
124
125     Location getWithNewPtr(const Value *NewPtr) const {
126       Location Copy(*this);
127       Copy.Ptr = NewPtr;
128       return Copy;
129     }
130
131     Location getWithNewSize(uint64_t NewSize) const {
132       Location Copy(*this);
133       Copy.Size = NewSize;
134       return Copy;
135     }
136
137     Location getWithoutAATags() const {
138       Location Copy(*this);
139       Copy.AATags = AAMDNodes();
140       return Copy;
141     }
142   };
143
144   /// getLocation - Fill in Loc with information about the memory reference by
145   /// the given instruction.
146   Location getLocation(const LoadInst *LI);
147   Location getLocation(const StoreInst *SI);
148   Location getLocation(const VAArgInst *VI);
149   Location getLocation(const AtomicCmpXchgInst *CXI);
150   Location getLocation(const AtomicRMWInst *RMWI);
151   static Location getLocationForSource(const MemTransferInst *MTI);
152   static Location getLocationForDest(const MemIntrinsic *MI);
153
154   /// Alias analysis result - Either we know for sure that it does not alias, we
155   /// know for sure it must alias, or we don't know anything: The two pointers
156   /// _might_ alias.  This enum is designed so you can do things like:
157   ///     if (AA.alias(P1, P2)) { ... }
158   /// to check to see if two pointers might alias.
159   ///
160   /// See docs/AliasAnalysis.html for more information on the specific meanings
161   /// of these values.
162   ///
163   enum AliasResult {
164     NoAlias = 0,        ///< No dependencies.
165     MayAlias,           ///< Anything goes.
166     PartialAlias,       ///< Pointers differ, but pointees overlap.
167     MustAlias           ///< Pointers are equal.
168   };
169
170   /// alias - The main low level interface to the alias analysis implementation.
171   /// Returns an AliasResult indicating whether the two pointers are aliased to
172   /// each other.  This is the interface that must be implemented by specific
173   /// alias analysis implementations.
174   virtual AliasResult alias(const Location &LocA, const Location &LocB);
175
176   /// alias - A convenience wrapper.
177   AliasResult alias(const Value *V1, uint64_t V1Size,
178                     const Value *V2, uint64_t V2Size) {
179     return alias(Location(V1, V1Size), Location(V2, V2Size));
180   }
181
182   /// alias - A convenience wrapper.
183   AliasResult alias(const Value *V1, const Value *V2) {
184     return alias(V1, UnknownSize, V2, UnknownSize);
185   }
186
187   /// isNoAlias - A trivial helper function to check to see if the specified
188   /// pointers are no-alias.
189   bool isNoAlias(const Location &LocA, const Location &LocB) {
190     return alias(LocA, LocB) == NoAlias;
191   }
192
193   /// isNoAlias - A convenience wrapper.
194   bool isNoAlias(const Value *V1, uint64_t V1Size,
195                  const Value *V2, uint64_t V2Size) {
196     return isNoAlias(Location(V1, V1Size), Location(V2, V2Size));
197   }
198   
199   /// isNoAlias - A convenience wrapper.
200   bool isNoAlias(const Value *V1, const Value *V2) {
201     return isNoAlias(Location(V1), Location(V2));
202   }
203   
204   /// isMustAlias - A convenience wrapper.
205   bool isMustAlias(const Location &LocA, const Location &LocB) {
206     return alias(LocA, LocB) == MustAlias;
207   }
208
209   /// isMustAlias - A convenience wrapper.
210   bool isMustAlias(const Value *V1, const Value *V2) {
211     return alias(V1, 1, V2, 1) == MustAlias;
212   }
213   
214   /// pointsToConstantMemory - If the specified memory location is
215   /// known to be constant, return true. If OrLocal is true and the
216   /// specified memory location is known to be "local" (derived from
217   /// an alloca), return true. Otherwise return false.
218   virtual bool pointsToConstantMemory(const Location &Loc,
219                                       bool OrLocal = false);
220
221   /// pointsToConstantMemory - A convenient wrapper.
222   bool pointsToConstantMemory(const Value *P, bool OrLocal = false) {
223     return pointsToConstantMemory(Location(P), OrLocal);
224   }
225
226   //===--------------------------------------------------------------------===//
227   /// Simple mod/ref information...
228   ///
229
230   /// ModRefResult - Represent the result of a mod/ref query.  Mod and Ref are
231   /// bits which may be or'd together.
232   ///
233   enum ModRefResult { NoModRef = 0, Ref = 1, Mod = 2, ModRef = 3 };
234
235   /// These values define additional bits used to define the
236   /// ModRefBehavior values.
237   enum { Nowhere = 0, ArgumentPointees = 4, Anywhere = 8 | ArgumentPointees };
238
239   /// ModRefBehavior - Summary of how a function affects memory in the program.
240   /// Loads from constant globals are not considered memory accesses for this
241   /// interface.  Also, functions may freely modify stack space local to their
242   /// invocation without having to report it through these interfaces.
243   enum ModRefBehavior {
244     /// DoesNotAccessMemory - This function does not perform any non-local loads
245     /// or stores to memory.
246     ///
247     /// This property corresponds to the GCC 'const' attribute.
248     /// This property corresponds to the LLVM IR 'readnone' attribute.
249     /// This property corresponds to the IntrNoMem LLVM intrinsic flag.
250     DoesNotAccessMemory = Nowhere | NoModRef,
251
252     /// OnlyReadsArgumentPointees - The only memory references in this function
253     /// (if it has any) are non-volatile loads from objects pointed to by its
254     /// pointer-typed arguments, with arbitrary offsets.
255     ///
256     /// This property corresponds to the IntrReadArgMem LLVM intrinsic flag.
257     OnlyReadsArgumentPointees = ArgumentPointees | Ref,
258
259     /// OnlyAccessesArgumentPointees - The only memory references in this
260     /// function (if it has any) are non-volatile loads and stores from objects
261     /// pointed to by its pointer-typed arguments, with arbitrary offsets.
262     ///
263     /// This property corresponds to the IntrReadWriteArgMem LLVM intrinsic flag.
264     OnlyAccessesArgumentPointees = ArgumentPointees | ModRef,
265
266     /// OnlyReadsMemory - This function does not perform any non-local stores or
267     /// volatile loads, but may read from any memory location.
268     ///
269     /// This property corresponds to the GCC 'pure' attribute.
270     /// This property corresponds to the LLVM IR 'readonly' attribute.
271     /// This property corresponds to the IntrReadMem LLVM intrinsic flag.
272     OnlyReadsMemory = Anywhere | Ref,
273
274     /// UnknownModRefBehavior - This indicates that the function could not be
275     /// classified into one of the behaviors above.
276     UnknownModRefBehavior = Anywhere | ModRef
277   };
278
279   /// Get the location associated with a pointer argument of a callsite.
280   /// The mask bits are set to indicate the allowed aliasing ModRef kinds.
281   /// Note that these mask bits do not necessarily account for the overall
282   /// behavior of the function, but rather only provide additional
283   /// per-argument information.
284   virtual Location getArgLocation(ImmutableCallSite CS, unsigned ArgIdx,
285                                   ModRefResult &Mask);
286
287   /// getModRefBehavior - Return the behavior when calling the given call site.
288   virtual ModRefBehavior getModRefBehavior(ImmutableCallSite CS);
289
290   /// getModRefBehavior - Return the behavior when calling the given function.
291   /// For use when the call site is not known.
292   virtual ModRefBehavior getModRefBehavior(const Function *F);
293
294   /// doesNotAccessMemory - If the specified call is known to never read or
295   /// write memory, return true.  If the call only reads from known-constant
296   /// memory, it is also legal to return true.  Calls that unwind the stack
297   /// are legal for this predicate.
298   ///
299   /// Many optimizations (such as CSE and LICM) can be performed on such calls
300   /// without worrying about aliasing properties, and many calls have this
301   /// property (e.g. calls to 'sin' and 'cos').
302   ///
303   /// This property corresponds to the GCC 'const' attribute.
304   ///
305   bool doesNotAccessMemory(ImmutableCallSite CS) {
306     return getModRefBehavior(CS) == DoesNotAccessMemory;
307   }
308
309   /// doesNotAccessMemory - If the specified function is known to never read or
310   /// write memory, return true.  For use when the call site is not known.
311   ///
312   bool doesNotAccessMemory(const Function *F) {
313     return getModRefBehavior(F) == DoesNotAccessMemory;
314   }
315
316   /// onlyReadsMemory - If the specified call is known to only read from
317   /// non-volatile memory (or not access memory at all), return true.  Calls
318   /// that unwind the stack are legal for this predicate.
319   ///
320   /// This property allows many common optimizations to be performed in the
321   /// absence of interfering store instructions, such as CSE of strlen calls.
322   ///
323   /// This property corresponds to the GCC 'pure' attribute.
324   ///
325   bool onlyReadsMemory(ImmutableCallSite CS) {
326     return onlyReadsMemory(getModRefBehavior(CS));
327   }
328
329   /// onlyReadsMemory - If the specified function is known to only read from
330   /// non-volatile memory (or not access memory at all), return true.  For use
331   /// when the call site is not known.
332   ///
333   bool onlyReadsMemory(const Function *F) {
334     return onlyReadsMemory(getModRefBehavior(F));
335   }
336
337   /// onlyReadsMemory - Return true if functions with the specified behavior are
338   /// known to only read from non-volatile memory (or not access memory at all).
339   ///
340   static bool onlyReadsMemory(ModRefBehavior MRB) {
341     return !(MRB & Mod);
342   }
343
344   /// onlyAccessesArgPointees - Return true if functions with the specified
345   /// behavior are known to read and write at most from objects pointed to by
346   /// their pointer-typed arguments (with arbitrary offsets).
347   ///
348   static bool onlyAccessesArgPointees(ModRefBehavior MRB) {
349     return !(MRB & Anywhere & ~ArgumentPointees);
350   }
351
352   /// doesAccessArgPointees - Return true if functions with the specified
353   /// behavior are known to potentially read or write from objects pointed
354   /// to be their pointer-typed arguments (with arbitrary offsets).
355   ///
356   static bool doesAccessArgPointees(ModRefBehavior MRB) {
357     return (MRB & ModRef) && (MRB & ArgumentPointees);
358   }
359
360   /// getModRefInfo - Return information about whether or not an instruction may
361   /// read or write the specified memory location.  An instruction
362   /// that doesn't read or write memory may be trivially LICM'd for example.
363   ModRefResult getModRefInfo(const Instruction *I,
364                              const Location &Loc) {
365     switch (I->getOpcode()) {
366     case Instruction::VAArg:  return getModRefInfo((const VAArgInst*)I, Loc);
367     case Instruction::Load:   return getModRefInfo((const LoadInst*)I,  Loc);
368     case Instruction::Store:  return getModRefInfo((const StoreInst*)I, Loc);
369     case Instruction::Fence:  return getModRefInfo((const FenceInst*)I, Loc);
370     case Instruction::AtomicCmpXchg:
371       return getModRefInfo((const AtomicCmpXchgInst*)I, Loc);
372     case Instruction::AtomicRMW:
373       return getModRefInfo((const AtomicRMWInst*)I, Loc);
374     case Instruction::Call:   return getModRefInfo((const CallInst*)I,  Loc);
375     case Instruction::Invoke: return getModRefInfo((const InvokeInst*)I,Loc);
376     default:                  return NoModRef;
377     }
378   }
379
380   /// getModRefInfo - A convenience wrapper.
381   ModRefResult getModRefInfo(const Instruction *I,
382                              const Value *P, uint64_t Size) {
383     return getModRefInfo(I, Location(P, Size));
384   }
385
386   /// getModRefInfo (for call sites) - Return information about whether
387   /// a particular call site modifies or reads the specified memory location.
388   virtual ModRefResult getModRefInfo(ImmutableCallSite CS,
389                                      const Location &Loc);
390
391   /// getModRefInfo (for call sites) - A convenience wrapper.
392   ModRefResult getModRefInfo(ImmutableCallSite CS,
393                              const Value *P, uint64_t Size) {
394     return getModRefInfo(CS, Location(P, Size));
395   }
396
397   /// getModRefInfo (for calls) - Return information about whether
398   /// a particular call modifies or reads the specified memory location.
399   ModRefResult getModRefInfo(const CallInst *C, const Location &Loc) {
400     return getModRefInfo(ImmutableCallSite(C), Loc);
401   }
402
403   /// getModRefInfo (for calls) - A convenience wrapper.
404   ModRefResult getModRefInfo(const CallInst *C, const Value *P, uint64_t Size) {
405     return getModRefInfo(C, Location(P, Size));
406   }
407
408   /// getModRefInfo (for invokes) - Return information about whether
409   /// a particular invoke modifies or reads the specified memory location.
410   ModRefResult getModRefInfo(const InvokeInst *I,
411                              const Location &Loc) {
412     return getModRefInfo(ImmutableCallSite(I), Loc);
413   }
414
415   /// getModRefInfo (for invokes) - A convenience wrapper.
416   ModRefResult getModRefInfo(const InvokeInst *I,
417                              const Value *P, uint64_t Size) {
418     return getModRefInfo(I, Location(P, Size));
419   }
420
421   /// getModRefInfo (for loads) - Return information about whether
422   /// a particular load modifies or reads the specified memory location.
423   ModRefResult getModRefInfo(const LoadInst *L, const Location &Loc);
424
425   /// getModRefInfo (for loads) - A convenience wrapper.
426   ModRefResult getModRefInfo(const LoadInst *L, const Value *P, uint64_t Size) {
427     return getModRefInfo(L, Location(P, Size));
428   }
429
430   /// getModRefInfo (for stores) - Return information about whether
431   /// a particular store modifies or reads the specified memory location.
432   ModRefResult getModRefInfo(const StoreInst *S, const Location &Loc);
433
434   /// getModRefInfo (for stores) - A convenience wrapper.
435   ModRefResult getModRefInfo(const StoreInst *S, const Value *P, uint64_t Size){
436     return getModRefInfo(S, Location(P, Size));
437   }
438
439   /// getModRefInfo (for fences) - Return information about whether
440   /// a particular store modifies or reads the specified memory location.
441   ModRefResult getModRefInfo(const FenceInst *S, const Location &Loc) {
442     // Conservatively correct.  (We could possibly be a bit smarter if
443     // Loc is a alloca that doesn't escape.)
444     return ModRef;
445   }
446
447   /// getModRefInfo (for fences) - A convenience wrapper.
448   ModRefResult getModRefInfo(const FenceInst *S, const Value *P, uint64_t Size){
449     return getModRefInfo(S, Location(P, Size));
450   }
451
452   /// getModRefInfo (for cmpxchges) - Return information about whether
453   /// a particular cmpxchg modifies or reads the specified memory location.
454   ModRefResult getModRefInfo(const AtomicCmpXchgInst *CX, const Location &Loc);
455
456   /// getModRefInfo (for cmpxchges) - A convenience wrapper.
457   ModRefResult getModRefInfo(const AtomicCmpXchgInst *CX,
458                              const Value *P, unsigned Size) {
459     return getModRefInfo(CX, Location(P, Size));
460   }
461
462   /// getModRefInfo (for atomicrmws) - Return information about whether
463   /// a particular atomicrmw modifies or reads the specified memory location.
464   ModRefResult getModRefInfo(const AtomicRMWInst *RMW, const Location &Loc);
465
466   /// getModRefInfo (for atomicrmws) - A convenience wrapper.
467   ModRefResult getModRefInfo(const AtomicRMWInst *RMW,
468                              const Value *P, unsigned Size) {
469     return getModRefInfo(RMW, Location(P, Size));
470   }
471
472   /// getModRefInfo (for va_args) - Return information about whether
473   /// a particular va_arg modifies or reads the specified memory location.
474   ModRefResult getModRefInfo(const VAArgInst* I, const Location &Loc);
475
476   /// getModRefInfo (for va_args) - A convenience wrapper.
477   ModRefResult getModRefInfo(const VAArgInst* I, const Value* P, uint64_t Size){
478     return getModRefInfo(I, Location(P, Size));
479   }
480
481   /// getModRefInfo - Return information about whether two call sites may refer
482   /// to the same set of memory locations.  See 
483   ///   http://llvm.org/docs/AliasAnalysis.html#ModRefInfo
484   /// for details.
485   virtual ModRefResult getModRefInfo(ImmutableCallSite CS1,
486                                      ImmutableCallSite CS2);
487
488   /// callCapturesBefore - Return information about whether a particular call 
489   /// site modifies or reads the specified memory location.
490   ModRefResult callCapturesBefore(const Instruction *I,
491                                   const AliasAnalysis::Location &MemLoc,
492                                   DominatorTree *DT);
493
494   /// callCapturesBefore - A convenience wrapper.
495   ModRefResult callCapturesBefore(const Instruction *I, const Value *P,
496                                   uint64_t Size, DominatorTree *DT) {
497     return callCapturesBefore(I, Location(P, Size), DT);
498   }
499
500   //===--------------------------------------------------------------------===//
501   /// Higher level methods for querying mod/ref information.
502   ///
503
504   /// canBasicBlockModify - Return true if it is possible for execution of the
505   /// specified basic block to modify the location Loc.
506   bool canBasicBlockModify(const BasicBlock &BB, const Location &Loc);
507
508   /// canBasicBlockModify - A convenience wrapper.
509   bool canBasicBlockModify(const BasicBlock &BB, const Value *P, uint64_t Size){
510     return canBasicBlockModify(BB, Location(P, Size));
511   }
512
513   /// canInstructionRangeModRef - Return true if it is possible for the
514   /// execution of the specified instructions to mod\ref (according to the
515   /// mode) the location Loc. The instructions to consider are all
516   /// of the instructions in the range of [I1,I2] INCLUSIVE.
517   /// I1 and I2 must be in the same basic block.
518   bool canInstructionRangeModRef(const Instruction &I1,
519                                 const Instruction &I2, const Location &Loc,
520                                 const ModRefResult Mode);
521
522   /// canInstructionRangeModRef - A convenience wrapper.
523   bool canInstructionRangeModRef(const Instruction &I1,
524                                  const Instruction &I2, const Value *Ptr,
525                                  uint64_t Size, const ModRefResult Mode) {
526     return canInstructionRangeModRef(I1, I2, Location(Ptr, Size), Mode);
527   }
528
529   //===--------------------------------------------------------------------===//
530   /// Methods that clients should call when they transform the program to allow
531   /// alias analyses to update their internal data structures.  Note that these
532   /// methods may be called on any instruction, regardless of whether or not
533   /// they have pointer-analysis implications.
534   ///
535
536   /// deleteValue - This method should be called whenever an LLVM Value is
537   /// deleted from the program, for example when an instruction is found to be
538   /// redundant and is eliminated.
539   ///
540   virtual void deleteValue(Value *V);
541
542   /// copyValue - This method should be used whenever a preexisting value in the
543   /// program is copied or cloned, introducing a new value.  Note that analysis
544   /// implementations should tolerate clients that use this method to introduce
545   /// the same value multiple times: if the analysis already knows about a
546   /// value, it should ignore the request.
547   ///
548   virtual void copyValue(Value *From, Value *To);
549
550   /// addEscapingUse - This method should be used whenever an escaping use is
551   /// added to a pointer value.  Analysis implementations may either return
552   /// conservative responses for that value in the future, or may recompute
553   /// some or all internal state to continue providing precise responses.
554   ///
555   /// Escaping uses are considered by anything _except_ the following:
556   ///  - GEPs or bitcasts of the pointer
557   ///  - Loads through the pointer
558   ///  - Stores through (but not of) the pointer
559   virtual void addEscapingUse(Use &U);
560
561   /// replaceWithNewValue - This method is the obvious combination of the two
562   /// above, and it provided as a helper to simplify client code.
563   ///
564   void replaceWithNewValue(Value *Old, Value *New) {
565     copyValue(Old, New);
566     deleteValue(Old);
567   }
568 };
569
570 // Specialize DenseMapInfo for Location.
571 template<>
572 struct DenseMapInfo<AliasAnalysis::Location> {
573   static inline AliasAnalysis::Location getEmptyKey() {
574     return AliasAnalysis::Location(DenseMapInfo<const Value *>::getEmptyKey(),
575                                    0);
576   }
577   static inline AliasAnalysis::Location getTombstoneKey() {
578     return AliasAnalysis::Location(
579         DenseMapInfo<const Value *>::getTombstoneKey(), 0);
580   }
581   static unsigned getHashValue(const AliasAnalysis::Location &Val) {
582     return DenseMapInfo<const Value *>::getHashValue(Val.Ptr) ^
583            DenseMapInfo<uint64_t>::getHashValue(Val.Size) ^
584            DenseMapInfo<AAMDNodes>::getHashValue(Val.AATags);
585   }
586   static bool isEqual(const AliasAnalysis::Location &LHS,
587                       const AliasAnalysis::Location &RHS) {
588     return LHS.Ptr == RHS.Ptr &&
589            LHS.Size == RHS.Size &&
590            LHS.AATags == RHS.AATags;
591   }
592 };
593
594 /// isNoAliasCall - Return true if this pointer is returned by a noalias
595 /// function.
596 bool isNoAliasCall(const Value *V);
597
598 /// isNoAliasArgument - Return true if this is an argument with the noalias
599 /// attribute.
600 bool isNoAliasArgument(const Value *V);
601
602 /// isIdentifiedObject - Return true if this pointer refers to a distinct and
603 /// identifiable object.  This returns true for:
604 ///    Global Variables and Functions (but not Global Aliases)
605 ///    Allocas
606 ///    ByVal and NoAlias Arguments
607 ///    NoAlias returns (e.g. calls to malloc)
608 ///
609 bool isIdentifiedObject(const Value *V);
610
611 /// isIdentifiedFunctionLocal - Return true if V is umabigously identified
612 /// at the function-level. Different IdentifiedFunctionLocals can't alias.
613 /// Further, an IdentifiedFunctionLocal can not alias with any function
614 /// arguments other than itself, which is not necessarily true for
615 /// IdentifiedObjects.
616 bool isIdentifiedFunctionLocal(const Value *V);
617
618 } // End llvm namespace
619
620 #endif