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