LLVM  9.0.0svn
AliasAnalysis.h
Go to the documentation of this file.
1 //===- llvm/Analysis/AliasAnalysis.h - Alias Analysis Interface -*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file defines the generic AliasAnalysis interface, which is used as the
10 // common interface used by all clients of alias analysis information, and
11 // implemented by all alias analysis implementations. Mod/Ref information is
12 // also captured by this interface.
13 //
14 // Implementations of this interface must implement the various virtual methods,
15 // which automatically provides functionality for the entire suite of client
16 // APIs.
17 //
18 // This API identifies memory regions with the MemoryLocation class. The pointer
19 // component specifies the base memory address of the region. The Size specifies
20 // the maximum size (in address units) of the memory region, or
21 // MemoryLocation::UnknownSize if the size is not known. The TBAA tag
22 // identifies the "type" of the memory reference; see the
23 // 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/None.h"
41 #include "llvm/ADT/Optional.h"
42 #include "llvm/ADT/SmallVector.h"
45 #include "llvm/IR/Function.h"
46 #include "llvm/IR/Instruction.h"
47 #include "llvm/IR/Instructions.h"
48 #include "llvm/IR/PassManager.h"
49 #include "llvm/Pass.h"
50 #include <cstdint>
51 #include <functional>
52 #include <memory>
53 #include <vector>
54 
55 namespace llvm {
56 
57 class AnalysisUsage;
58 class BasicAAResult;
59 class BasicBlock;
60 class DominatorTree;
61 class OrderedBasicBlock;
62 class Value;
63 
64 /// The possible results of an alias query.
65 ///
66 /// These results are always computed between two MemoryLocation objects as
67 /// a query to some alias analysis.
68 ///
69 /// Note that these are unscoped enumerations because we would like to support
70 /// implicitly testing a result for the existence of any possible aliasing with
71 /// a conversion to bool, but an "enum class" doesn't support this. The
72 /// canonical names from the literature are suffixed and unique anyways, and so
73 /// they serve as global constants in LLVM for these results.
74 ///
75 /// See docs/AliasAnalysis.html for more information on the specific meanings
76 /// of these values.
77 enum AliasResult : uint8_t {
78  /// The two locations do not alias at all.
79  ///
80  /// This value is arranged to convert to false, while all other values
81  /// convert to true. This allows a boolean context to convert the result to
82  /// a binary flag indicating whether there is the possibility of aliasing.
83  NoAlias = 0,
84  /// The two locations may or may not alias. This is the least precise result.
86  /// The two locations alias, but only due to a partial overlap.
88  /// The two locations precisely alias each other.
90 };
91 
92 /// << operator for AliasResult.
94 
95 /// Flags indicating whether a memory access modifies or references memory.
96 ///
97 /// This is no access at all, a modification, a reference, or both
98 /// a modification and a reference. These are specifically structured such that
99 /// they form a three bit matrix and bit-tests for 'mod' or 'ref' or 'must'
100 /// work with any of the possible values.
101 enum class ModRefInfo : uint8_t {
102  /// Must is provided for completeness, but no routines will return only
103  /// Must today. See definition of Must below.
104  Must = 0,
105  /// The access may reference the value stored in memory,
106  /// a mustAlias relation was found, and no mayAlias or partialAlias found.
107  MustRef = 1,
108  /// The access may modify the value stored in memory,
109  /// a mustAlias relation was found, and no mayAlias or partialAlias found.
110  MustMod = 2,
111  /// The access may reference, modify or both the value stored in memory,
112  /// a mustAlias relation was found, and no mayAlias or partialAlias found.
114  /// The access neither references nor modifies the value stored in memory.
115  NoModRef = 4,
116  /// The access may reference the value stored in memory.
117  Ref = NoModRef | MustRef,
118  /// The access may modify the value stored in memory.
119  Mod = NoModRef | MustMod,
120  /// The access may reference and may modify the value stored in memory.
121  ModRef = Ref | Mod,
122 
123  /// About Must:
124  /// Must is set in a best effort manner.
125  /// We usually do not try our best to infer Must, instead it is merely
126  /// another piece of "free" information that is presented when available.
127  /// Must set means there was certainly a MustAlias found. For calls,
128  /// where multiple arguments are checked (argmemonly), this translates to
129  /// only MustAlias or NoAlias was found.
130  /// Must is not set for RAR accesses, even if the two locations must
131  /// alias. The reason is that two read accesses translate to an early return
132  /// of NoModRef. An additional alias check to set Must may be
133  /// expensive. Other cases may also not set Must(e.g. callCapturesBefore).
134  /// We refer to Must being *set* when the most significant bit is *cleared*.
135  /// Conversely we *clear* Must information by *setting* the Must bit to 1.
136 };
137 
139  return (static_cast<int>(MRI) & static_cast<int>(ModRefInfo::MustModRef)) ==
140  static_cast<int>(ModRefInfo::Must);
141 }
143  return static_cast<int>(MRI) & static_cast<int>(ModRefInfo::MustModRef);
144 }
146  return (static_cast<int>(MRI) & static_cast<int>(ModRefInfo::MustModRef)) ==
147  static_cast<int>(ModRefInfo::MustModRef);
148 }
149 LLVM_NODISCARD inline bool isModSet(const ModRefInfo MRI) {
150  return static_cast<int>(MRI) & static_cast<int>(ModRefInfo::MustMod);
151 }
152 LLVM_NODISCARD inline bool isRefSet(const ModRefInfo MRI) {
153  return static_cast<int>(MRI) & static_cast<int>(ModRefInfo::MustRef);
154 }
156  return !(static_cast<int>(MRI) & static_cast<int>(ModRefInfo::NoModRef));
157 }
158 
160  return ModRefInfo(static_cast<int>(MRI) |
161  static_cast<int>(ModRefInfo::MustMod));
162 }
164  return ModRefInfo(static_cast<int>(MRI) |
165  static_cast<int>(ModRefInfo::MustRef));
166 }
168  return ModRefInfo(static_cast<int>(MRI) &
169  static_cast<int>(ModRefInfo::MustModRef));
170 }
172  return ModRefInfo(static_cast<int>(MRI) |
173  static_cast<int>(ModRefInfo::MustModRef));
174 }
176  return ModRefInfo(static_cast<int>(MRI) & static_cast<int>(ModRefInfo::Ref));
177 }
179  return ModRefInfo(static_cast<int>(MRI) & static_cast<int>(ModRefInfo::Mod));
180 }
182  return ModRefInfo(static_cast<int>(MRI) |
183  static_cast<int>(ModRefInfo::NoModRef));
184 }
186  const ModRefInfo MRI2) {
187  return ModRefInfo(static_cast<int>(MRI1) | static_cast<int>(MRI2));
188 }
190  const ModRefInfo MRI2) {
191  return ModRefInfo(static_cast<int>(MRI1) & static_cast<int>(MRI2));
192 }
193 
194 /// The locations at which a function might access memory.
195 ///
196 /// These are primarily used in conjunction with the \c AccessKind bits to
197 /// describe both the nature of access and the locations of access for a
198 /// function call.
200  /// Base case is no access to memory.
202  /// Access to memory via argument pointers.
204  /// Memory that is inaccessible via LLVM IR.
206  /// Access to any memory.
208 };
209 
210 /// Summary of how a function affects memory in the program.
211 ///
212 /// Loads from constant globals are not considered memory accesses for this
213 /// interface. Also, functions may freely modify stack space local to their
214 /// invocation without having to report it through these interfaces.
216  /// This function does not perform any non-local loads or stores to memory.
217  ///
218  /// This property corresponds to the GCC 'const' attribute.
219  /// This property corresponds to the LLVM IR 'readnone' attribute.
220  /// This property corresponds to the IntrNoMem LLVM intrinsic flag.
222  FMRL_Nowhere | static_cast<int>(ModRefInfo::NoModRef),
223 
224  /// The only memory references in this function (if it has any) are
225  /// non-volatile loads from objects pointed to by its pointer-typed
226  /// arguments, with arbitrary offsets.
227  ///
228  /// This property corresponds to the IntrReadArgMem LLVM intrinsic flag.
230  FMRL_ArgumentPointees | static_cast<int>(ModRefInfo::Ref),
231 
232  /// The only memory references in this function (if it has any) are
233  /// non-volatile loads and stores from objects pointed to by its
234  /// pointer-typed arguments, with arbitrary offsets.
235  ///
236  /// This property corresponds to the IntrArgMemOnly LLVM intrinsic flag.
238  FMRL_ArgumentPointees | static_cast<int>(ModRefInfo::ModRef),
239 
240  /// The only memory references in this function (if it has any) are
241  /// references of memory that is otherwise inaccessible via LLVM IR.
242  ///
243  /// This property corresponds to the LLVM IR inaccessiblememonly attribute.
245  FMRL_InaccessibleMem | static_cast<int>(ModRefInfo::ModRef),
246 
247  /// The function may perform non-volatile loads and stores of objects
248  /// pointed to by its pointer-typed arguments, with arbitrary offsets, and
249  /// it may also perform loads and stores of memory that is otherwise
250  /// inaccessible via LLVM IR.
251  ///
252  /// This property corresponds to the LLVM IR
253  /// inaccessiblemem_or_argmemonly attribute.
256  static_cast<int>(ModRefInfo::ModRef),
257 
258  /// This function does not perform any non-local stores or volatile loads,
259  /// but may read from any memory location.
260  ///
261  /// This property corresponds to the GCC 'pure' attribute.
262  /// This property corresponds to the LLVM IR 'readonly' attribute.
263  /// This property corresponds to the IntrReadMem LLVM intrinsic flag.
265 
266  // This function does not read from memory anywhere, but may write to any
267  // memory location.
268  //
269  // This property corresponds to the LLVM IR 'writeonly' attribute.
270  // This property corresponds to the IntrWriteMem LLVM intrinsic flag.
272 
273  /// This indicates that the function could not be classified into one of the
274  /// behaviors above.
276  FMRL_Anywhere | static_cast<int>(ModRefInfo::ModRef)
277 };
278 
279 // Wrapper method strips bits significant only in FunctionModRefBehavior,
280 // to obtain a valid ModRefInfo. The benefit of using the wrapper is that if
281 // ModRefInfo enum changes, the wrapper can be updated to & with the new enum
282 // entry with all bits set to 1.
285  return ModRefInfo(FMRB & static_cast<int>(ModRefInfo::ModRef));
286 }
287 
288 class AAResults {
289 public:
290  // Make these results default constructable and movable. We have to spell
291  // these out because MSVC won't synthesize them.
292  AAResults(const TargetLibraryInfo &TLI) : TLI(TLI) {}
294  ~AAResults();
295 
296  /// Register a specific AA result.
297  template <typename AAResultT> void addAAResult(AAResultT &AAResult) {
298  // FIXME: We should use a much lighter weight system than the usual
299  // polymorphic pattern because we don't own AAResult. It should
300  // ideally involve two pointers and no separate allocation.
301  AAs.emplace_back(new Model<AAResultT>(AAResult, *this));
302  }
303 
304  /// Register a function analysis ID that the results aggregation depends on.
305  ///
306  /// This is used in the new pass manager to implement the invalidation logic
307  /// where we must invalidate the results aggregation if any of our component
308  /// analyses become invalid.
309  void addAADependencyID(AnalysisKey *ID) { AADeps.push_back(ID); }
310 
311  /// Handle invalidation events in the new pass manager.
312  ///
313  /// The aggregation is invalidated if any of the underlying analyses is
314  /// invalidated.
315  bool invalidate(Function &F, const PreservedAnalyses &PA,
317 
318  //===--------------------------------------------------------------------===//
319  /// \name Alias Queries
320  /// @{
321 
322  /// The main low level interface to the alias analysis implementation.
323  /// Returns an AliasResult indicating whether the two pointers are aliased to
324  /// each other. This is the interface that must be implemented by specific
325  /// alias analysis implementations.
326  AliasResult alias(const MemoryLocation &LocA, const MemoryLocation &LocB);
327 
328  /// A convenience wrapper around the primary \c alias interface.
329  AliasResult alias(const Value *V1, LocationSize V1Size, const Value *V2,
330  LocationSize V2Size) {
331  return alias(MemoryLocation(V1, V1Size), MemoryLocation(V2, V2Size));
332  }
333 
334  /// A convenience wrapper around the primary \c alias interface.
335  AliasResult alias(const Value *V1, const Value *V2) {
336  return alias(V1, LocationSize::unknown(), V2, LocationSize::unknown());
337  }
338 
339  /// A trivial helper function to check to see if the specified pointers are
340  /// no-alias.
341  bool isNoAlias(const MemoryLocation &LocA, const MemoryLocation &LocB) {
342  return alias(LocA, LocB) == NoAlias;
343  }
344 
345  /// A convenience wrapper around the \c isNoAlias helper interface.
346  bool isNoAlias(const Value *V1, LocationSize V1Size, const Value *V2,
347  LocationSize V2Size) {
348  return isNoAlias(MemoryLocation(V1, V1Size), MemoryLocation(V2, V2Size));
349  }
350 
351  /// A convenience wrapper around the \c isNoAlias helper interface.
352  bool isNoAlias(const Value *V1, const Value *V2) {
353  return isNoAlias(MemoryLocation(V1), MemoryLocation(V2));
354  }
355 
356  /// A trivial helper function to check to see if the specified pointers are
357  /// must-alias.
358  bool isMustAlias(const MemoryLocation &LocA, const MemoryLocation &LocB) {
359  return alias(LocA, LocB) == MustAlias;
360  }
361 
362  /// A convenience wrapper around the \c isMustAlias helper interface.
363  bool isMustAlias(const Value *V1, const Value *V2) {
364  return alias(V1, LocationSize::precise(1), V2, LocationSize::precise(1)) ==
365  MustAlias;
366  }
367 
368  /// Checks whether the given location points to constant memory, or if
369  /// \p OrLocal is true whether it points to a local alloca.
370  bool pointsToConstantMemory(const MemoryLocation &Loc, bool OrLocal = false);
371 
372  /// A convenience wrapper around the primary \c pointsToConstantMemory
373  /// interface.
374  bool pointsToConstantMemory(const Value *P, bool OrLocal = false) {
375  return pointsToConstantMemory(MemoryLocation(P), OrLocal);
376  }
377 
378  /// @}
379  //===--------------------------------------------------------------------===//
380  /// \name Simple mod/ref information
381  /// @{
382 
383  /// Get the ModRef info associated with a pointer argument of a call. The
384  /// result's bits are set to indicate the allowed aliasing ModRef kinds. Note
385  /// that these bits do not necessarily account for the overall behavior of
386  /// the function, but rather only provide additional per-argument
387  /// information. This never sets ModRefInfo::Must.
388  ModRefInfo getArgModRefInfo(const CallBase *Call, unsigned ArgIdx);
389 
390  /// Return the behavior of the given call site.
391  FunctionModRefBehavior getModRefBehavior(const CallBase *Call);
392 
393  /// Return the behavior when calling the given function.
394  FunctionModRefBehavior getModRefBehavior(const Function *F);
395 
396  /// Checks if the specified call is known to never read or write memory.
397  ///
398  /// Note that if the call only reads from known-constant memory, it is also
399  /// legal to return true. Also, calls that unwind the stack are legal for
400  /// this predicate.
401  ///
402  /// Many optimizations (such as CSE and LICM) can be performed on such calls
403  /// without worrying about aliasing properties, and many calls have this
404  /// property (e.g. calls to 'sin' and 'cos').
405  ///
406  /// This property corresponds to the GCC 'const' attribute.
407  bool doesNotAccessMemory(const CallBase *Call) {
408  return getModRefBehavior(Call) == FMRB_DoesNotAccessMemory;
409  }
410 
411  /// Checks if the specified function is known to never read or write memory.
412  ///
413  /// Note that if the function only reads from known-constant memory, it is
414  /// also legal to return true. Also, function that unwind the stack are legal
415  /// for this predicate.
416  ///
417  /// Many optimizations (such as CSE and LICM) can be performed on such calls
418  /// to such functions without worrying about aliasing properties, and many
419  /// functions have this property (e.g. 'sin' and 'cos').
420  ///
421  /// This property corresponds to the GCC 'const' attribute.
422  bool doesNotAccessMemory(const Function *F) {
423  return getModRefBehavior(F) == FMRB_DoesNotAccessMemory;
424  }
425 
426  /// Checks if the specified call is known to only read from non-volatile
427  /// memory (or not access memory at all).
428  ///
429  /// Calls that unwind the stack are legal for this predicate.
430  ///
431  /// This property allows many common optimizations to be performed in the
432  /// absence of interfering store instructions, such as CSE of strlen calls.
433  ///
434  /// This property corresponds to the GCC 'pure' attribute.
435  bool onlyReadsMemory(const CallBase *Call) {
436  return onlyReadsMemory(getModRefBehavior(Call));
437  }
438 
439  /// Checks if the specified function is known to only read from non-volatile
440  /// memory (or not access memory at all).
441  ///
442  /// Functions that unwind the stack are legal for this predicate.
443  ///
444  /// This property allows many common optimizations to be performed in the
445  /// absence of interfering store instructions, such as CSE of strlen calls.
446  ///
447  /// This property corresponds to the GCC 'pure' attribute.
448  bool onlyReadsMemory(const Function *F) {
449  return onlyReadsMemory(getModRefBehavior(F));
450  }
451 
452  /// Checks if functions with the specified behavior are known to only read
453  /// from non-volatile memory (or not access memory at all).
455  return !isModSet(createModRefInfo(MRB));
456  }
457 
458  /// Checks if functions with the specified behavior are known to only write
459  /// memory (or not access memory at all).
461  return !isRefSet(createModRefInfo(MRB));
462  }
463 
464  /// Checks if functions with the specified behavior are known to read and
465  /// write at most from objects pointed to by their pointer-typed arguments
466  /// (with arbitrary offsets).
468  return !(MRB & FMRL_Anywhere & ~FMRL_ArgumentPointees);
469  }
470 
471  /// Checks if functions with the specified behavior are known to potentially
472  /// read or write from objects pointed to be their pointer-typed arguments
473  /// (with arbitrary offsets).
475  return isModOrRefSet(createModRefInfo(MRB)) &&
476  (MRB & FMRL_ArgumentPointees);
477  }
478 
479  /// Checks if functions with the specified behavior are known to read and
480  /// write at most from memory that is inaccessible from LLVM IR.
482  return !(MRB & FMRL_Anywhere & ~FMRL_InaccessibleMem);
483  }
484 
485  /// Checks if functions with the specified behavior are known to potentially
486  /// read or write from memory that is inaccessible from LLVM IR.
488  return isModOrRefSet(createModRefInfo(MRB)) && (MRB & FMRL_InaccessibleMem);
489  }
490 
491  /// Checks if functions with the specified behavior are known to read and
492  /// write at most from memory that is inaccessible from LLVM IR or objects
493  /// pointed to by their pointer-typed arguments (with arbitrary offsets).
495  return !(MRB & FMRL_Anywhere &
497  }
498 
499  /// getModRefInfo (for call sites) - Return information about whether
500  /// a particular call site modifies or reads the specified memory location.
501  ModRefInfo getModRefInfo(const CallBase *Call, const MemoryLocation &Loc);
502 
503  /// getModRefInfo (for call sites) - A convenience wrapper.
504  ModRefInfo getModRefInfo(const CallBase *Call, const Value *P,
505  LocationSize Size) {
506  return getModRefInfo(Call, MemoryLocation(P, Size));
507  }
508 
509  /// getModRefInfo (for loads) - Return information about whether
510  /// a particular load modifies or reads the specified memory location.
511  ModRefInfo getModRefInfo(const LoadInst *L, const MemoryLocation &Loc);
512 
513  /// getModRefInfo (for loads) - A convenience wrapper.
515  LocationSize Size) {
516  return getModRefInfo(L, MemoryLocation(P, Size));
517  }
518 
519  /// getModRefInfo (for stores) - Return information about whether
520  /// a particular store modifies or reads the specified memory location.
521  ModRefInfo getModRefInfo(const StoreInst *S, const MemoryLocation &Loc);
522 
523  /// getModRefInfo (for stores) - A convenience wrapper.
525  LocationSize Size) {
526  return getModRefInfo(S, MemoryLocation(P, Size));
527  }
528 
529  /// getModRefInfo (for fences) - Return information about whether
530  /// a particular store modifies or reads the specified memory location.
531  ModRefInfo getModRefInfo(const FenceInst *S, const MemoryLocation &Loc);
532 
533  /// getModRefInfo (for fences) - A convenience wrapper.
535  LocationSize Size) {
536  return getModRefInfo(S, MemoryLocation(P, Size));
537  }
538 
539  /// getModRefInfo (for cmpxchges) - Return information about whether
540  /// a particular cmpxchg modifies or reads the specified memory location.
541  ModRefInfo getModRefInfo(const AtomicCmpXchgInst *CX,
542  const MemoryLocation &Loc);
543 
544  /// getModRefInfo (for cmpxchges) - A convenience wrapper.
546  LocationSize Size) {
547  return getModRefInfo(CX, MemoryLocation(P, Size));
548  }
549 
550  /// getModRefInfo (for atomicrmws) - Return information about whether
551  /// a particular atomicrmw modifies or reads the specified memory location.
552  ModRefInfo getModRefInfo(const AtomicRMWInst *RMW, const MemoryLocation &Loc);
553 
554  /// getModRefInfo (for atomicrmws) - A convenience wrapper.
556  LocationSize Size) {
557  return getModRefInfo(RMW, MemoryLocation(P, Size));
558  }
559 
560  /// getModRefInfo (for va_args) - Return information about whether
561  /// a particular va_arg modifies or reads the specified memory location.
562  ModRefInfo getModRefInfo(const VAArgInst *I, const MemoryLocation &Loc);
563 
564  /// getModRefInfo (for va_args) - A convenience wrapper.
566  LocationSize Size) {
567  return getModRefInfo(I, MemoryLocation(P, Size));
568  }
569 
570  /// getModRefInfo (for catchpads) - Return information about whether
571  /// a particular catchpad modifies or reads the specified memory location.
572  ModRefInfo getModRefInfo(const CatchPadInst *I, const MemoryLocation &Loc);
573 
574  /// getModRefInfo (for catchpads) - A convenience wrapper.
576  LocationSize Size) {
577  return getModRefInfo(I, MemoryLocation(P, Size));
578  }
579 
580  /// getModRefInfo (for catchrets) - Return information about whether
581  /// a particular catchret modifies or reads the specified memory location.
582  ModRefInfo getModRefInfo(const CatchReturnInst *I, const MemoryLocation &Loc);
583 
584  /// getModRefInfo (for catchrets) - A convenience wrapper.
586  LocationSize Size) {
587  return getModRefInfo(I, MemoryLocation(P, Size));
588  }
589 
590  /// Check whether or not an instruction may read or write the optionally
591  /// specified memory location.
592  ///
593  ///
594  /// An instruction that doesn't read or write memory may be trivially LICM'd
595  /// for example.
596  ///
597  /// For function calls, this delegates to the alias-analysis specific
598  /// call-site mod-ref behavior queries. Otherwise it delegates to the specific
599  /// helpers above.
601  const Optional<MemoryLocation> &OptLoc) {
602  if (OptLoc == None) {
603  if (const auto *Call = dyn_cast<CallBase>(I)) {
604  return createModRefInfo(getModRefBehavior(Call));
605  }
606  }
607 
608  const MemoryLocation &Loc = OptLoc.getValueOr(MemoryLocation());
609 
610  switch (I->getOpcode()) {
611  case Instruction::VAArg: return getModRefInfo((const VAArgInst*)I, Loc);
612  case Instruction::Load: return getModRefInfo((const LoadInst*)I, Loc);
613  case Instruction::Store: return getModRefInfo((const StoreInst*)I, Loc);
614  case Instruction::Fence: return getModRefInfo((const FenceInst*)I, Loc);
615  case Instruction::AtomicCmpXchg:
616  return getModRefInfo((const AtomicCmpXchgInst*)I, Loc);
617  case Instruction::AtomicRMW:
618  return getModRefInfo((const AtomicRMWInst*)I, Loc);
619  case Instruction::Call: return getModRefInfo((const CallInst*)I, Loc);
620  case Instruction::Invoke: return getModRefInfo((const InvokeInst*)I,Loc);
621  case Instruction::CatchPad:
622  return getModRefInfo((const CatchPadInst *)I, Loc);
623  case Instruction::CatchRet:
624  return getModRefInfo((const CatchReturnInst *)I, Loc);
625  default:
626  return ModRefInfo::NoModRef;
627  }
628  }
629 
630  /// A convenience wrapper for constructing the memory location.
632  LocationSize Size) {
633  return getModRefInfo(I, MemoryLocation(P, Size));
634  }
635 
636  /// Return information about whether a call and an instruction may refer to
637  /// the same memory locations.
638  ModRefInfo getModRefInfo(Instruction *I, const CallBase *Call);
639 
640  /// Return information about whether two call sites may refer to the same set
641  /// of memory locations. See the AA documentation for details:
642  /// http://llvm.org/docs/AliasAnalysis.html#ModRefInfo
643  ModRefInfo getModRefInfo(const CallBase *Call1, const CallBase *Call2);
644 
645  /// Return information about whether a particular call site modifies
646  /// or reads the specified memory location \p MemLoc before instruction \p I
647  /// in a BasicBlock. An ordered basic block \p OBB can be used to speed up
648  /// instruction ordering queries inside the BasicBlock containing \p I.
649  /// Early exits in callCapturesBefore may lead to ModRefInfo::Must not being
650  /// set.
651  ModRefInfo callCapturesBefore(const Instruction *I,
652  const MemoryLocation &MemLoc, DominatorTree *DT,
653  OrderedBasicBlock *OBB = nullptr);
654 
655  /// A convenience wrapper to synthesize a memory location.
658  OrderedBasicBlock *OBB = nullptr) {
659  return callCapturesBefore(I, MemoryLocation(P, Size), DT, OBB);
660  }
661 
662  /// @}
663  //===--------------------------------------------------------------------===//
664  /// \name Higher level methods for querying mod/ref information.
665  /// @{
666 
667  /// Check if it is possible for execution of the specified basic block to
668  /// modify the location Loc.
669  bool canBasicBlockModify(const BasicBlock &BB, const MemoryLocation &Loc);
670 
671  /// A convenience wrapper synthesizing a memory location.
672  bool canBasicBlockModify(const BasicBlock &BB, const Value *P,
673  LocationSize Size) {
674  return canBasicBlockModify(BB, MemoryLocation(P, Size));
675  }
676 
677  /// Check if it is possible for the execution of the specified instructions
678  /// to mod\ref (according to the mode) the location Loc.
679  ///
680  /// The instructions to consider are all of the instructions in the range of
681  /// [I1,I2] INCLUSIVE. I1 and I2 must be in the same basic block.
682  bool canInstructionRangeModRef(const Instruction &I1, const Instruction &I2,
683  const MemoryLocation &Loc,
684  const ModRefInfo Mode);
685 
686  /// A convenience wrapper synthesizing a memory location.
688  const Value *Ptr, LocationSize Size,
689  const ModRefInfo Mode) {
690  return canInstructionRangeModRef(I1, I2, MemoryLocation(Ptr, Size), Mode);
691  }
692 
693 private:
694  class Concept;
695 
696  template <typename T> class Model;
697 
698  template <typename T> friend class AAResultBase;
699 
700  const TargetLibraryInfo &TLI;
701 
702  std::vector<std::unique_ptr<Concept>> AAs;
703 
704  std::vector<AnalysisKey *> AADeps;
705 };
706 
707 /// Temporary typedef for legacy code that uses a generic \c AliasAnalysis
708 /// pointer or reference.
710 
711 /// A private abstract base class describing the concept of an individual alias
712 /// analysis implementation.
713 ///
714 /// This interface is implemented by any \c Model instantiation. It is also the
715 /// interface which a type used to instantiate the model must provide.
716 ///
717 /// All of these methods model methods by the same name in the \c
718 /// AAResults class. Only differences and specifics to how the
719 /// implementations are called are documented here.
721 public:
722  virtual ~Concept() = 0;
723 
724  /// An update API used internally by the AAResults to provide
725  /// a handle back to the top level aggregation.
726  virtual void setAAResults(AAResults *NewAAR) = 0;
727 
728  //===--------------------------------------------------------------------===//
729  /// \name Alias Queries
730  /// @{
731 
732  /// The main low level interface to the alias analysis implementation.
733  /// Returns an AliasResult indicating whether the two pointers are aliased to
734  /// each other. This is the interface that must be implemented by specific
735  /// alias analysis implementations.
736  virtual AliasResult alias(const MemoryLocation &LocA,
737  const MemoryLocation &LocB) = 0;
738 
739  /// Checks whether the given location points to constant memory, or if
740  /// \p OrLocal is true whether it points to a local alloca.
741  virtual bool pointsToConstantMemory(const MemoryLocation &Loc,
742  bool OrLocal) = 0;
743 
744  /// @}
745  //===--------------------------------------------------------------------===//
746  /// \name Simple mod/ref information
747  /// @{
748 
749  /// Get the ModRef info associated with a pointer argument of a callsite. The
750  /// result's bits are set to indicate the allowed aliasing ModRef kinds. Note
751  /// that these bits do not necessarily account for the overall behavior of
752  /// the function, but rather only provide additional per-argument
753  /// information.
754  virtual ModRefInfo getArgModRefInfo(const CallBase *Call,
755  unsigned ArgIdx) = 0;
756 
757  /// Return the behavior of the given call site.
758  virtual FunctionModRefBehavior getModRefBehavior(const CallBase *Call) = 0;
759 
760  /// Return the behavior when calling the given function.
761  virtual FunctionModRefBehavior getModRefBehavior(const Function *F) = 0;
762 
763  /// getModRefInfo (for call sites) - Return information about whether
764  /// a particular call site modifies or reads the specified memory location.
765  virtual ModRefInfo getModRefInfo(const CallBase *Call,
766  const MemoryLocation &Loc) = 0;
767 
768  /// Return information about whether two call sites may refer to the same set
769  /// of memory locations. See the AA documentation for details:
770  /// http://llvm.org/docs/AliasAnalysis.html#ModRefInfo
771  virtual ModRefInfo getModRefInfo(const CallBase *Call1,
772  const CallBase *Call2) = 0;
773 
774  /// @}
775 };
776 
777 /// A private class template which derives from \c Concept and wraps some other
778 /// type.
779 ///
780 /// This models the concept by directly forwarding each interface point to the
781 /// wrapped type which must implement a compatible interface. This provides
782 /// a type erased binding.
783 template <typename AAResultT> class AAResults::Model final : public Concept {
784  AAResultT &Result;
785 
786 public:
787  explicit Model(AAResultT &Result, AAResults &AAR) : Result(Result) {
788  Result.setAAResults(&AAR);
789  }
790  ~Model() override = default;
791 
792  void setAAResults(AAResults *NewAAR) override { Result.setAAResults(NewAAR); }
793 
794  AliasResult alias(const MemoryLocation &LocA,
795  const MemoryLocation &LocB) override {
796  return Result.alias(LocA, LocB);
797  }
798 
799  bool pointsToConstantMemory(const MemoryLocation &Loc,
800  bool OrLocal) override {
801  return Result.pointsToConstantMemory(Loc, OrLocal);
802  }
803 
804  ModRefInfo getArgModRefInfo(const CallBase *Call, unsigned ArgIdx) override {
805  return Result.getArgModRefInfo(Call, ArgIdx);
806  }
807 
808  FunctionModRefBehavior getModRefBehavior(const CallBase *Call) override {
809  return Result.getModRefBehavior(Call);
810  }
811 
812  FunctionModRefBehavior getModRefBehavior(const Function *F) override {
813  return Result.getModRefBehavior(F);
814  }
815 
816  ModRefInfo getModRefInfo(const CallBase *Call,
817  const MemoryLocation &Loc) override {
818  return Result.getModRefInfo(Call, Loc);
819  }
820 
821  ModRefInfo getModRefInfo(const CallBase *Call1,
822  const CallBase *Call2) override {
823  return Result.getModRefInfo(Call1, Call2);
824  }
825 };
826 
827 /// A CRTP-driven "mixin" base class to help implement the function alias
828 /// analysis results concept.
829 ///
830 /// Because of the nature of many alias analysis implementations, they often
831 /// only implement a subset of the interface. This base class will attempt to
832 /// implement the remaining portions of the interface in terms of simpler forms
833 /// of the interface where possible, and otherwise provide conservatively
834 /// correct fallback implementations.
835 ///
836 /// Implementors of an alias analysis should derive from this CRTP, and then
837 /// override specific methods that they wish to customize. There is no need to
838 /// use virtual anywhere, the CRTP base class does static dispatch to the
839 /// derived type passed into it.
840 template <typename DerivedT> class AAResultBase {
841  // Expose some parts of the interface only to the AAResults::Model
842  // for wrapping. Specifically, this allows the model to call our
843  // setAAResults method without exposing it as a fully public API.
844  friend class AAResults::Model<DerivedT>;
845 
846  /// A pointer to the AAResults object that this AAResult is
847  /// aggregated within. May be null if not aggregated.
848  AAResults *AAR;
849 
850  /// Helper to dispatch calls back through the derived type.
851  DerivedT &derived() { return static_cast<DerivedT &>(*this); }
852 
853  /// A setter for the AAResults pointer, which is used to satisfy the
854  /// AAResults::Model contract.
855  void setAAResults(AAResults *NewAAR) { AAR = NewAAR; }
856 
857 protected:
858  /// This proxy class models a common pattern where we delegate to either the
859  /// top-level \c AAResults aggregation if one is registered, or to the
860  /// current result if none are registered.
862  AAResults *AAR;
863  DerivedT &CurrentResult;
864 
865  public:
866  AAResultsProxy(AAResults *AAR, DerivedT &CurrentResult)
867  : AAR(AAR), CurrentResult(CurrentResult) {}
868 
869  AliasResult alias(const MemoryLocation &LocA, const MemoryLocation &LocB) {
870  return AAR ? AAR->alias(LocA, LocB) : CurrentResult.alias(LocA, LocB);
871  }
872 
873  bool pointsToConstantMemory(const MemoryLocation &Loc, bool OrLocal) {
874  return AAR ? AAR->pointsToConstantMemory(Loc, OrLocal)
875  : CurrentResult.pointsToConstantMemory(Loc, OrLocal);
876  }
877 
878  ModRefInfo getArgModRefInfo(const CallBase *Call, unsigned ArgIdx) {
879  return AAR ? AAR->getArgModRefInfo(Call, ArgIdx)
880  : CurrentResult.getArgModRefInfo(Call, ArgIdx);
881  }
882 
884  return AAR ? AAR->getModRefBehavior(Call)
885  : CurrentResult.getModRefBehavior(Call);
886  }
887 
889  return AAR ? AAR->getModRefBehavior(F) : CurrentResult.getModRefBehavior(F);
890  }
891 
892  ModRefInfo getModRefInfo(const CallBase *Call, const MemoryLocation &Loc) {
893  return AAR ? AAR->getModRefInfo(Call, Loc)
894  : CurrentResult.getModRefInfo(Call, Loc);
895  }
896 
897  ModRefInfo getModRefInfo(const CallBase *Call1, const CallBase *Call2) {
898  return AAR ? AAR->getModRefInfo(Call1, Call2)
899  : CurrentResult.getModRefInfo(Call1, Call2);
900  }
901  };
902 
903  explicit AAResultBase() = default;
904 
905  // Provide all the copy and move constructors so that derived types aren't
906  // constrained.
909 
910  /// Get a proxy for the best AA result set to query at this time.
911  ///
912  /// When this result is part of a larger aggregation, this will proxy to that
913  /// aggregation. When this result is used in isolation, it will just delegate
914  /// back to the derived class's implementation.
915  ///
916  /// Note that callers of this need to take considerable care to not cause
917  /// performance problems when they use this routine, in the case of a large
918  /// number of alias analyses being aggregated, it can be expensive to walk
919  /// back across the chain.
920  AAResultsProxy getBestAAResults() { return AAResultsProxy(AAR, derived()); }
921 
922 public:
923  AliasResult alias(const MemoryLocation &LocA, const MemoryLocation &LocB) {
924  return MayAlias;
925  }
926 
927  bool pointsToConstantMemory(const MemoryLocation &Loc, bool OrLocal) {
928  return false;
929  }
930 
931  ModRefInfo getArgModRefInfo(const CallBase *Call, unsigned ArgIdx) {
932  return ModRefInfo::ModRef;
933  }
934 
937  }
938 
941  }
942 
943  ModRefInfo getModRefInfo(const CallBase *Call, const MemoryLocation &Loc) {
944  return ModRefInfo::ModRef;
945  }
946 
947  ModRefInfo getModRefInfo(const CallBase *Call1, const CallBase *Call2) {
948  return ModRefInfo::ModRef;
949  }
950 };
951 
952 /// Return true if this pointer is returned by a noalias function.
953 bool isNoAliasCall(const Value *V);
954 
955 /// Return true if this is an argument with the noalias attribute.
956 bool isNoAliasArgument(const Value *V);
957 
958 /// Return true if this pointer refers to a distinct and identifiable object.
959 /// This returns true for:
960 /// Global Variables and Functions (but not Global Aliases)
961 /// Allocas
962 /// ByVal and NoAlias Arguments
963 /// NoAlias returns (e.g. calls to malloc)
964 ///
965 bool isIdentifiedObject(const Value *V);
966 
967 /// Return true if V is umabigously identified at the function-level.
968 /// Different IdentifiedFunctionLocals can't alias.
969 /// Further, an IdentifiedFunctionLocal can not alias with any function
970 /// arguments other than itself, which is not necessarily true for
971 /// IdentifiedObjects.
972 bool isIdentifiedFunctionLocal(const Value *V);
973 
974 /// A manager for alias analyses.
975 ///
976 /// This class can have analyses registered with it and when run, it will run
977 /// all of them and aggregate their results into single AA results interface
978 /// that dispatches across all of the alias analysis results available.
979 ///
980 /// Note that the order in which analyses are registered is very significant.
981 /// That is the order in which the results will be aggregated and queried.
982 ///
983 /// This manager effectively wraps the AnalysisManager for registering alias
984 /// analyses. When you register your alias analysis with this manager, it will
985 /// ensure the analysis itself is registered with its AnalysisManager.
986 class AAManager : public AnalysisInfoMixin<AAManager> {
987 public:
988  using Result = AAResults;
989 
990  /// Register a specific AA result.
991  template <typename AnalysisT> void registerFunctionAnalysis() {
992  ResultGetters.push_back(&getFunctionAAResultImpl<AnalysisT>);
993  }
994 
995  /// Register a specific AA result.
996  template <typename AnalysisT> void registerModuleAnalysis() {
997  ResultGetters.push_back(&getModuleAAResultImpl<AnalysisT>);
998  }
999 
1002  for (auto &Getter : ResultGetters)
1003  (*Getter)(F, AM, R);
1004  return R;
1005  }
1006 
1007 private:
1009 
1010  static AnalysisKey Key;
1011 
1013  AAResults &AAResults),
1014  4> ResultGetters;
1015 
1016  template <typename AnalysisT>
1017  static void getFunctionAAResultImpl(Function &F,
1019  AAResults &AAResults) {
1020  AAResults.addAAResult(AM.template getResult<AnalysisT>(F));
1021  AAResults.addAADependencyID(AnalysisT::ID());
1022  }
1023 
1024  template <typename AnalysisT>
1025  static void getModuleAAResultImpl(Function &F, FunctionAnalysisManager &AM,
1026  AAResults &AAResults) {
1027  auto &MAMProxy = AM.getResult<ModuleAnalysisManagerFunctionProxy>(F);
1028  auto &MAM = MAMProxy.getManager();
1029  if (auto *R = MAM.template getCachedResult<AnalysisT>(*F.getParent())) {
1030  AAResults.addAAResult(*R);
1031  MAMProxy
1032  .template registerOuterAnalysisInvalidation<AnalysisT, AAManager>();
1033  }
1034  }
1035 };
1036 
1037 /// A wrapper pass to provide the legacy pass manager access to a suitably
1038 /// prepared AAResults object.
1040  std::unique_ptr<AAResults> AAR;
1041 
1042 public:
1043  static char ID;
1044 
1046 
1047  AAResults &getAAResults() { return *AAR; }
1048  const AAResults &getAAResults() const { return *AAR; }
1049 
1050  bool runOnFunction(Function &F) override;
1051 
1052  void getAnalysisUsage(AnalysisUsage &AU) const override;
1053 };
1054 
1055 /// A wrapper pass for external alias analyses. This just squirrels away the
1056 /// callback used to run any analyses and register their results.
1058  using CallbackT = std::function<void(Pass &, Function &, AAResults &)>;
1059 
1061 
1062  static char ID;
1063 
1066  }
1067 
1069  : ImmutablePass(ID), CB(std::move(CB)) {
1071  }
1072 
1073  void getAnalysisUsage(AnalysisUsage &AU) const override {
1074  AU.setPreservesAll();
1075  }
1076 };
1077 
1079 
1080 /// A wrapper pass around a callback which can be used to populate the
1081 /// AAResults in the AAResultsWrapperPass from an external AA.
1082 ///
1083 /// The callback provided here will be used each time we prepare an AAResults
1084 /// object, and will receive a reference to the function wrapper pass, the
1085 /// function, and the AAResults object to populate. This should be used when
1086 /// setting up a custom pass pipeline to inject a hook into the AA results.
1088  std::function<void(Pass &, Function &, AAResults &)> Callback);
1089 
1090 /// A helper for the legacy pass manager to create a \c AAResults
1091 /// object populated to the best of our ability for a particular function when
1092 /// inside of a \c ModulePass or a \c CallGraphSCCPass.
1093 ///
1094 /// If a \c ModulePass or a \c CallGraphSCCPass calls \p
1095 /// createLegacyPMAAResults, it also needs to call \p addUsedAAAnalyses in \p
1096 /// getAnalysisUsage.
1098 
1099 /// A helper for the legacy pass manager to populate \p AU to add uses to make
1100 /// sure the analyses required by \p createLegacyPMAAResults are available.
1102 
1103 } // end namespace llvm
1104 
1105 #endif // LLVM_ANALYSIS_ALIASANALYSIS_H
The access may reference and may modify the value stored in memory.
Pass interface - Implemented by all &#39;passes&#39;.
Definition: Pass.h:80
LLVM_NODISCARD ModRefInfo unionModRef(const ModRefInfo MRI1, const ModRefInfo MRI2)
ModRefInfo getModRefInfo(const CatchReturnInst *I, const Value *P, LocationSize Size)
getModRefInfo (for catchrets) - A convenience wrapper.
ModRefInfo getModRefInfo(const AtomicRMWInst *RMW, const Value *P, LocationSize Size)
getModRefInfo (for atomicrmws) - A convenience wrapper.
static bool onlyAccessesInaccessibleMem(FunctionModRefBehavior MRB)
Checks if functions with the specified behavior are known to read and write at most from memory that ...
void addAAResult(AAResultT &AAResult)
Register a specific AA result.
The access neither references nor modifies the value stored in memory.
LLVM_NODISCARD ModRefInfo clearMust(const ModRefInfo MRI)
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
SI Whole Quad Mode
PassT::Result & getResult(IRUnitT &IR, ExtraArgTs... ExtraArgs)
Get the result of an analysis pass for a given IR unit.
Definition: PassManager.h:769
This class represents lattice values for constants.
Definition: AllocatorList.h:23
ModRefInfo getModRefInfo(const CatchPadInst *I, const Value *P, LocationSize Size)
getModRefInfo (for catchpads) - A convenience wrapper.
Various leaf nodes.
Definition: ISDOpcodes.h:59
ModRefInfo getArgModRefInfo(const CallBase *Call, unsigned ArgIdx)
AAResultsProxy(AAResults *AAR, DerivedT &CurrentResult)
An instruction for ordering other memory operations.
Definition: Instructions.h:454
bool pointsToConstantMemory(const MemoryLocation &Loc, bool OrLocal)
an instruction that atomically checks whether a specified value is in a memory location, and, if it is, stores a new value there.
Definition: Instructions.h:528
ModRefInfo callCapturesBefore(const Instruction *I, const Value *P, LocationSize Size, DominatorTree *DT, OrderedBasicBlock *OBB=nullptr)
A convenience wrapper to synthesize a memory location.
ModRefInfo getModRefInfo(const FenceInst *S, const Value *P, LocationSize Size)
getModRefInfo (for fences) - A convenience wrapper.
static constexpr LocationSize unknown()
ModRefInfo getModRefInfo(const StoreInst *S, const Value *P, LocationSize Size)
getModRefInfo (for stores) - A convenience wrapper.
bool isNoAlias(const MemoryLocation &LocA, const MemoryLocation &LocB)
A trivial helper function to check to see if the specified pointers are no-alias. ...
AliasResult alias(const MemoryLocation &LocA, const MemoryLocation &LocB)
std::function< void(Pass &, Function &, AAResults &)> CallbackT
bool canInstructionRangeModRef(const Instruction &I1, const Instruction &I2, const Value *Ptr, LocationSize Size, const ModRefInfo Mode)
A convenience wrapper synthesizing a memory location.
constexpr T getValueOr(U &&value) const LLVM_LVALUE_FUNCTION
Definition: Optional.h:173
This class represents a function call, abstracting a target machine&#39;s calling convention.
The two locations do not alias at all.
Definition: AliasAnalysis.h:83
bool doesNotAccessMemory(const Function *F)
Checks if the specified function is known to never read or write memory.
ModRefInfo getArgModRefInfo(const CallBase *Call, unsigned ArgIdx)
FunctionModRefBehavior getModRefBehavior(const CallBase *Call)
void registerModuleAnalysis()
Register a specific AA result.
const AAResults & getAAResults() const
This is the AA result object for the basic, local, and stateless alias analysis.
static LocationSize precise(uint64_t Value)
static bool onlyAccessesInaccessibleOrArgMem(FunctionModRefBehavior MRB)
Checks if functions with the specified behavior are known to read and write at most from memory that ...
bool pointsToConstantMemory(const Value *P, bool OrLocal=false)
A convenience wrapper around the primary pointsToConstantMemory interface.
Base class for all callable instructions (InvokeInst and CallInst) Holds everything related to callin...
Definition: InstrTypes.h:1014
F(f)
bool isNoAliasCall(const Value *V)
Return true if this pointer is returned by a noalias function.
An instruction for reading from memory.
Definition: Instructions.h:167
bool canBasicBlockModify(const BasicBlock &BB, const Value *P, LocationSize Size)
A convenience wrapper synthesizing a memory location.
an instruction that atomically reads a memory location, combines it with another value, and then stores the result back.
Definition: Instructions.h:691
void initializeExternalAAWrapperPassPass(PassRegistry &)
LLVM_NODISCARD bool isModAndRefSet(const ModRefInfo MRI)
Access to any memory.
ModRefInfo getModRefInfo(const Instruction *I, const Optional< MemoryLocation > &OptLoc)
Check whether or not an instruction may read or write the optionally specified memory location...
This indicates that the function could not be classified into one of the behaviors above...
LLVM_NODISCARD ModRefInfo clearMod(const ModRefInfo MRI)
AliasResult alias(const MemoryLocation &LocA, const MemoryLocation &LocB)
The main low level interface to the alias analysis implementation.
ModRefInfo getModRefInfo(const CallBase *Call, const Value *P, LocationSize Size)
getModRefInfo (for call sites) - A convenience wrapper.
The only memory references in this function (if it has any) are references of memory that is otherwis...
Definition: BitVector.h:937
FunctionPass * createAAResultsWrapperPass()
ModRefInfo getModRefInfo(const AtomicCmpXchgInst *CX, const Value *P, LocationSize Size)
getModRefInfo (for cmpxchges) - A convenience wrapper.
static bool doesNotReadMemory(FunctionModRefBehavior MRB)
Checks if functions with the specified behavior are known to only write memory (or not access memory ...
bool isNoAlias(const Value *V1, const Value *V2)
A convenience wrapper around the isNoAlias helper interface.
LLVM_NODISCARD ModRefInfo clearRef(const ModRefInfo MRI)
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - This function should be overriden by passes that need analysis information to do t...
Must is provided for completeness, but no routines will return only Must today.
The access may reference the value stored in memory, a mustAlias relation was found, and no mayAlias or partialAlias found.
The access may reference the value stored in memory.
The only memory references in this function (if it has any) are non-volatile loads from objects point...
AAResults createLegacyPMAAResults(Pass &P, Function &F, BasicAAResult &BAR)
A helper for the legacy pass manager to create a AAResults object populated to the best of our abilit...
The function may perform non-volatile loads and stores of objects pointed to by its pointer-typed arg...
bool isIdentifiedObject(const Value *V)
Return true if this pointer refers to a distinct and identifiable object.
A CRTP-driven "mixin" base class to help implement the function alias analysis results concept...
FunctionModRefBehavior getModRefBehavior(const CallBase *Call)
Return the behavior of the given call site.
AliasResult alias(const Value *V1, const Value *V2)
A convenience wrapper around the primary alias interface.
LLVM_NODISCARD ModRefInfo setRef(const ModRefInfo MRI)
Key
PAL metadata keys.
LLVM_NODISCARD bool isMustSet(const ModRefInfo MRI)
ModRefInfo getModRefInfo(const LoadInst *L, const Value *P, LocationSize Size)
getModRefInfo (for loads) - A convenience wrapper.
Access to memory via argument pointers.
The access may reference, modify or both the value stored in memory, a mustAlias relation was found...
FunctionModRefBehavior
Summary of how a function affects memory in the program.
The access may modify the value stored in memory, a mustAlias relation was found, and no mayAlias or ...
unsigned getOpcode() const
Returns a member of one of the enums like Instruction::Add.
Definition: Instruction.h:125
AAResultBase(AAResultBase &&Arg)
An instruction for storing to memory.
Definition: Instructions.h:320
void registerFunctionAnalysis()
Register a specific AA result.
AliasResult alias(const MemoryLocation &LocA, const MemoryLocation &LocB)
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree...
Definition: Dominators.h:144
bool pointsToConstantMemory(const MemoryLocation &Loc, bool OrLocal)
A private abstract base class describing the concept of an individual alias analysis implementation...
static bool onlyReadsMemory(FunctionModRefBehavior MRB)
Checks if functions with the specified behavior are known to only read from non-volatile memory (or n...
AliasResult
The possible results of an alias query.
Definition: AliasAnalysis.h:77
bool pointsToConstantMemory(const MemoryLocation &Loc, bool OrLocal=false)
Checks whether the given location points to constant memory, or if OrLocal is true whether it points ...
ImmutablePass * createExternalAAWrapperPass(std::function< void(Pass &, Function &, AAResults &)> Callback)
A wrapper pass around a callback which can be used to populate the AAResults in the AAResultsWrapperP...
static bool runOnFunction(Function &F, bool PostInlining)
#define P(N)
bool onlyReadsMemory(const Function *F)
Checks if the specified function is known to only read from non-volatile memory (or not access memory...
AAResultBase(const AAResultBase &Arg)
LLVM_NODISCARD ModRefInfo setMust(const ModRefInfo MRI)
A set of analyses that are preserved following a run of a transformation pass.
Definition: PassManager.h:153
unsigned const MachineRegisterInfo * MRI
LLVM Basic Block Representation.
Definition: BasicBlock.h:57
AliasResult alias(const Value *V1, LocationSize V1Size, const Value *V2, LocationSize V2Size)
A convenience wrapper around the primary alias interface.
A manager for alias analyses.
A CRTP mix-in that provides informational APIs needed for analysis passes.
Definition: PassManager.h:382
ModRefInfo getModRefInfo(const VAArgInst *I, const Value *P, LocationSize Size)
getModRefInfo (for va_args) - A convenience wrapper.
Result run(Function &F, FunctionAnalysisManager &AM)
Represent the analysis usage information of a pass.
void addAADependencyID(AnalysisKey *ID)
Register a function analysis ID that the results aggregation depends on.
FunctionModRefBehavior getModRefBehavior(const CallBase *Call)
ModRefInfo getModRefInfo(const CallBase *Call1, const CallBase *Call2)
static bool doesAccessArgPointees(FunctionModRefBehavior MRB)
Checks if functions with the specified behavior are known to potentially read or write from objects p...
The only memory references in this function (if it has any) are non-volatile loads and stores from ob...
FunctionPass class - This class is used to implement most global optimizations.
Definition: Pass.h:284
amdgpu Simplify well known AMD library false FunctionCallee Value * Arg
bool onlyReadsMemory(const CallBase *Call)
Checks if the specified call is known to only read from non-volatile memory (or not access memory at ...
This class represents the va_arg llvm instruction, which returns an argument of the specified type gi...
void getAAResultsAnalysisUsage(AnalysisUsage &AU)
A helper for the legacy pass manager to populate AU to add uses to make sure the analyses required by...
This function does not perform any non-local loads or stores to memory.
bool isIdentifiedFunctionLocal(const Value *V)
Return true if V is umabigously identified at the function-level.
The two locations may or may not alias. This is the least precise result.
Definition: AliasAnalysis.h:85
FunctionModRefLocation
The locations at which a function might access memory.
Representation for a specific memory location.
The two locations precisely alias each other.
Definition: AliasAnalysis.h:89
ImmutablePass class - This class is used to provide information that does not need to be run...
Definition: Pass.h:255
Memory that is inaccessible via LLVM IR.
An analysis over an "inner" IR unit that provides access to an analysis manager over a "outer" IR uni...
Definition: PassManager.h:1153
LLVM_NODISCARD ModRefInfo setMod(const ModRefInfo MRI)
This is a &#39;vector&#39; (really, a variable-sized array), optimized for the case when the array is small...
Definition: SmallVector.h:839
Provides information about what library functions are available for the current target.
This function does not perform any non-local stores or volatile loads, but may read from any memory l...
The access may modify the value stored in memory.
bool isMustAlias(const Value *V1, const Value *V2)
A convenience wrapper around the isMustAlias helper interface.
This proxy class models a common pattern where we delegate to either the top-level AAResults aggregat...
void setPreservesAll()
Set by analyses that do not transform their input at all.
LLVM_NODISCARD bool isNoModRef(const ModRefInfo MRI)
bool isMustAlias(const MemoryLocation &LocA, const MemoryLocation &LocB)
A trivial helper function to check to see if the specified pointers are must-alias.
AAResults(const TargetLibraryInfo &TLI)
LLVM_NODISCARD bool isModSet(const ModRefInfo MRI)
static bool onlyAccessesArgPointees(FunctionModRefBehavior MRB)
Checks if functions with the specified behavior are known to read and write at most from objects poin...
ModRefInfo getModRefInfo(const CallBase *Call, const MemoryLocation &Loc)
Base case is no access to memory.
bool doesNotAccessMemory(const CallBase *Call)
Checks if the specified call is known to never read or write memory.
This file provides utility analysis objects describing memory locations.
static bool doesAccessInaccessibleMem(FunctionModRefBehavior MRB)
Checks if functions with the specified behavior are known to potentially read or write from memory th...
LLVM_NODISCARD ModRefInfo intersectModRef(const ModRefInfo MRI1, const ModRefInfo MRI2)
#define I(x, y, z)
Definition: MD5.cpp:58
AAResultsProxy getBestAAResults()
Get a proxy for the best AA result set to query at this time.
uint32_t Size
Definition: Profile.cpp:46
raw_ostream & operator<<(raw_ostream &OS, const APInt &I)
Definition: APInt.h:2038
#define LLVM_NODISCARD
LLVM_NODISCARD - Warn if a type or return value is discarded.
Definition: Compiler.h:128
API to communicate dependencies between analyses during invalidation.
Definition: PassManager.h:641
Analysis pass providing the TargetLibraryInfo.
ModRefInfo getModRefInfo(const CallBase *Call, const MemoryLocation &Loc)
ModRefInfo getArgModRefInfo(const CallBase *Call, unsigned ArgIdx)
Get the ModRef info associated with a pointer argument of a call.
Module * getParent()
Get the module that this global value is contained inside of...
Definition: GlobalValue.h:565
LLVM Value Representation.
Definition: Value.h:72
LLVM_NODISCARD ModRefInfo createModRefInfo(const FunctionModRefBehavior FMRB)
This class implements an extremely fast bulk output stream that can only output to a stream...
Definition: raw_ostream.h:45
Invoke instruction.
A wrapper pass for external alias analyses.
ModRefInfo
Flags indicating whether a memory access modifies or references memory.
LLVM_NODISCARD ModRefInfo setModAndRef(const ModRefInfo MRI)
print Print MemDeps of function
FunctionModRefBehavior getModRefBehavior(const Function *F)
bool isNoAlias(const Value *V1, LocationSize V1Size, const Value *V2, LocationSize V2Size)
A convenience wrapper around the isNoAlias helper interface.
A container for analyses that lazily runs them and caches their results.
bool isNoAliasArgument(const Value *V)
Return true if this is an argument with the noalias attribute.
LLVM_NODISCARD bool isModOrRefSet(const ModRefInfo MRI)
A wrapper pass to provide the legacy pass manager access to a suitably prepared AAResults object...
This header defines various interfaces for pass management in LLVM.
ModRefInfo getModRefInfo(const CallBase *Call, const MemoryLocation &Loc)
getModRefInfo (for call sites) - Return information about whether a particular call site modifies or ...
The two locations alias, but only due to a partial overlap.
Definition: AliasAnalysis.h:87
ExternalAAWrapperPass(CallbackT CB)
A special type used by analysis passes to provide an address that identifies that particular analysis...
Definition: PassManager.h:70
ModRefInfo getModRefInfo(const CallBase *Call1, const CallBase *Call2)
FunctionModRefBehavior getModRefBehavior(const Function *F)
ModRefInfo getModRefInfo(const Instruction *I, const Value *P, LocationSize Size)
A convenience wrapper for constructing the memory location.
LLVM_NODISCARD bool isRefSet(const ModRefInfo MRI)