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