LLVM  4.0.0
AliasAnalysis.cpp
Go to the documentation of this file.
1 //===- AliasAnalysis.cpp - Generic Alias Analysis Interface Implementation -==//
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 implements the generic AliasAnalysis interface which is used as the
11 // common interface used by all clients and implementations of alias analysis.
12 //
13 // This file also implements the default version of the AliasAnalysis interface
14 // that is to be used when no other implementation is specified. This does some
15 // simple tests that detect obvious cases: two different global pointers cannot
16 // alias, a global cannot alias a malloc, two different mallocs cannot alias,
17 // etc.
18 //
19 // This alias analysis implementation really isn't very good for anything, but
20 // it is very fast, and makes a nice clean default implementation. Because it
21 // handles lots of little corner cases, other, more complex, alias analysis
22 // implementations may choose to rely on this pass to resolve these simple and
23 // easy cases.
24 //
25 //===----------------------------------------------------------------------===//
26 
29 #include "llvm/Analysis/CFG.h"
40 #include "llvm/IR/BasicBlock.h"
41 #include "llvm/IR/DataLayout.h"
42 #include "llvm/IR/Dominators.h"
43 #include "llvm/IR/Function.h"
44 #include "llvm/IR/Instructions.h"
45 #include "llvm/IR/IntrinsicInst.h"
46 #include "llvm/IR/LLVMContext.h"
47 #include "llvm/IR/Type.h"
48 #include "llvm/Pass.h"
49 using namespace llvm;
50 
51 /// Allow disabling BasicAA from the AA results. This is particularly useful
52 /// when testing to isolate a single AA implementation.
53 static cl::opt<bool> DisableBasicAA("disable-basicaa", cl::Hidden,
54  cl::init(false));
55 
57  : TLI(Arg.TLI), AAs(std::move(Arg.AAs)), AADeps(std::move(Arg.AADeps)) {
58  for (auto &AA : AAs)
59  AA->setAAResults(this);
60 }
61 
63 // FIXME; It would be nice to at least clear out the pointers back to this
64 // aggregation here, but we end up with non-nesting lifetimes in the legacy
65 // pass manager that prevent this from working. In the legacy pass manager
66 // we'll end up with dangling references here in some cases.
67 #if 0
68  for (auto &AA : AAs)
69  AA->setAAResults(nullptr);
70 #endif
71 }
72 
75  // Check if the AA manager itself has been invalidated.
76  auto PAC = PA.getChecker<AAManager>();
77  if (!PAC.preserved() && !PAC.preservedSet<AllAnalysesOn<Function>>())
78  return true; // The manager needs to be blown away, clear everything.
79 
80  // Check all of the dependencies registered.
81  for (AnalysisKey *ID : AADeps)
82  if (Inv.invalidate(ID, F, PA))
83  return true;
84 
85  // Everything we depend on is still fine, so are we. Nothing to invalidate.
86  return false;
87 }
88 
89 //===----------------------------------------------------------------------===//
90 // Default chaining methods
91 //===----------------------------------------------------------------------===//
92 
94  const MemoryLocation &LocB) {
95  for (const auto &AA : AAs) {
96  auto Result = AA->alias(LocA, LocB);
97  if (Result != MayAlias)
98  return Result;
99  }
100  return MayAlias;
101 }
102 
104  bool OrLocal) {
105  for (const auto &AA : AAs)
106  if (AA->pointsToConstantMemory(Loc, OrLocal))
107  return true;
108 
109  return false;
110 }
111 
113  ModRefInfo Result = MRI_ModRef;
114 
115  for (const auto &AA : AAs) {
116  Result = ModRefInfo(Result & AA->getArgModRefInfo(CS, ArgIdx));
117 
118  // Early-exit the moment we reach the bottom of the lattice.
119  if (Result == MRI_NoModRef)
120  return Result;
121  }
122 
123  return Result;
124 }
125 
127  // We may have two calls
128  if (auto CS = ImmutableCallSite(I)) {
129  // Check if the two calls modify the same memory
130  return getModRefInfo(CS, Call);
131  } else if (I->isFenceLike()) {
132  // If this is a fence, just return MRI_ModRef.
133  return MRI_ModRef;
134  } else {
135  // Otherwise, check if the call modifies or references the
136  // location this memory access defines. The best we can say
137  // is that if the call references what this instruction
138  // defines, it must be clobbered by this location.
139  const MemoryLocation DefLoc = MemoryLocation::get(I);
140  if (getModRefInfo(Call, DefLoc) != MRI_NoModRef)
141  return MRI_ModRef;
142  }
143  return MRI_NoModRef;
144 }
145 
147  const MemoryLocation &Loc) {
148  ModRefInfo Result = MRI_ModRef;
149 
150  for (const auto &AA : AAs) {
151  Result = ModRefInfo(Result & AA->getModRefInfo(CS, Loc));
152 
153  // Early-exit the moment we reach the bottom of the lattice.
154  if (Result == MRI_NoModRef)
155  return Result;
156  }
157 
158  // Try to refine the mod-ref info further using other API entry points to the
159  // aggregate set of AA results.
160  auto MRB = getModRefBehavior(CS);
161  if (MRB == FMRB_DoesNotAccessMemory ||
163  return MRI_NoModRef;
164 
165  if (onlyReadsMemory(MRB))
166  Result = ModRefInfo(Result & MRI_Ref);
167  else if (doesNotReadMemory(MRB))
168  Result = ModRefInfo(Result & MRI_Mod);
169 
171  bool DoesAlias = false;
172  ModRefInfo AllArgsMask = MRI_NoModRef;
173  if (doesAccessArgPointees(MRB)) {
174  for (auto AI = CS.arg_begin(), AE = CS.arg_end(); AI != AE; ++AI) {
175  const Value *Arg = *AI;
176  if (!Arg->getType()->isPointerTy())
177  continue;
178  unsigned ArgIdx = std::distance(CS.arg_begin(), AI);
179  MemoryLocation ArgLoc = MemoryLocation::getForArgument(CS, ArgIdx, TLI);
180  AliasResult ArgAlias = alias(ArgLoc, Loc);
181  if (ArgAlias != NoAlias) {
182  ModRefInfo ArgMask = getArgModRefInfo(CS, ArgIdx);
183  DoesAlias = true;
184  AllArgsMask = ModRefInfo(AllArgsMask | ArgMask);
185  }
186  }
187  }
188  if (!DoesAlias)
189  return MRI_NoModRef;
190  Result = ModRefInfo(Result & AllArgsMask);
191  }
192 
193  // If Loc is a constant memory location, the call definitely could not
194  // modify the memory location.
195  if ((Result & MRI_Mod) &&
196  pointsToConstantMemory(Loc, /*OrLocal*/ false))
197  Result = ModRefInfo(Result & ~MRI_Mod);
198 
199  return Result;
200 }
201 
203  ImmutableCallSite CS2) {
204  ModRefInfo Result = MRI_ModRef;
205 
206  for (const auto &AA : AAs) {
207  Result = ModRefInfo(Result & AA->getModRefInfo(CS1, CS2));
208 
209  // Early-exit the moment we reach the bottom of the lattice.
210  if (Result == MRI_NoModRef)
211  return Result;
212  }
213 
214  // Try to refine the mod-ref info further using other API entry points to the
215  // aggregate set of AA results.
216 
217  // If CS1 or CS2 are readnone, they don't interact.
218  auto CS1B = getModRefBehavior(CS1);
219  if (CS1B == FMRB_DoesNotAccessMemory)
220  return MRI_NoModRef;
221 
222  auto CS2B = getModRefBehavior(CS2);
223  if (CS2B == FMRB_DoesNotAccessMemory)
224  return MRI_NoModRef;
225 
226  // If they both only read from memory, there is no dependence.
227  if (onlyReadsMemory(CS1B) && onlyReadsMemory(CS2B))
228  return MRI_NoModRef;
229 
230  // If CS1 only reads memory, the only dependence on CS2 can be
231  // from CS1 reading memory written by CS2.
232  if (onlyReadsMemory(CS1B))
233  Result = ModRefInfo(Result & MRI_Ref);
234  else if (doesNotReadMemory(CS1B))
235  Result = ModRefInfo(Result & MRI_Mod);
236 
237  // If CS2 only access memory through arguments, accumulate the mod/ref
238  // information from CS1's references to the memory referenced by
239  // CS2's arguments.
240  if (onlyAccessesArgPointees(CS2B)) {
242  if (doesAccessArgPointees(CS2B)) {
243  for (auto I = CS2.arg_begin(), E = CS2.arg_end(); I != E; ++I) {
244  const Value *Arg = *I;
245  if (!Arg->getType()->isPointerTy())
246  continue;
247  unsigned CS2ArgIdx = std::distance(CS2.arg_begin(), I);
248  auto CS2ArgLoc = MemoryLocation::getForArgument(CS2, CS2ArgIdx, TLI);
249 
250  // ArgMask indicates what CS2 might do to CS2ArgLoc, and the dependence
251  // of CS1 on that location is the inverse.
252  ModRefInfo ArgMask = getArgModRefInfo(CS2, CS2ArgIdx);
253  if (ArgMask == MRI_Mod)
254  ArgMask = MRI_ModRef;
255  else if (ArgMask == MRI_Ref)
256  ArgMask = MRI_Mod;
257 
258  ArgMask = ModRefInfo(ArgMask & getModRefInfo(CS1, CS2ArgLoc));
259 
260  R = ModRefInfo((R | ArgMask) & Result);
261  if (R == Result)
262  break;
263  }
264  }
265  return R;
266  }
267 
268  // If CS1 only accesses memory through arguments, check if CS2 references
269  // any of the memory referenced by CS1's arguments. If not, return NoModRef.
270  if (onlyAccessesArgPointees(CS1B)) {
272  if (doesAccessArgPointees(CS1B)) {
273  for (auto I = CS1.arg_begin(), E = CS1.arg_end(); I != E; ++I) {
274  const Value *Arg = *I;
275  if (!Arg->getType()->isPointerTy())
276  continue;
277  unsigned CS1ArgIdx = std::distance(CS1.arg_begin(), I);
278  auto CS1ArgLoc = MemoryLocation::getForArgument(CS1, CS1ArgIdx, TLI);
279 
280  // ArgMask indicates what CS1 might do to CS1ArgLoc; if CS1 might Mod
281  // CS1ArgLoc, then we care about either a Mod or a Ref by CS2. If CS1
282  // might Ref, then we care only about a Mod by CS2.
283  ModRefInfo ArgMask = getArgModRefInfo(CS1, CS1ArgIdx);
284  ModRefInfo ArgR = getModRefInfo(CS2, CS1ArgLoc);
285  if (((ArgMask & MRI_Mod) != MRI_NoModRef &&
286  (ArgR & MRI_ModRef) != MRI_NoModRef) ||
287  ((ArgMask & MRI_Ref) != MRI_NoModRef &&
288  (ArgR & MRI_Mod) != MRI_NoModRef))
289  R = ModRefInfo((R | ArgMask) & Result);
290 
291  if (R == Result)
292  break;
293  }
294  }
295  return R;
296  }
297 
298  return Result;
299 }
300 
303 
304  for (const auto &AA : AAs) {
305  Result = FunctionModRefBehavior(Result & AA->getModRefBehavior(CS));
306 
307  // Early-exit the moment we reach the bottom of the lattice.
308  if (Result == FMRB_DoesNotAccessMemory)
309  return Result;
310  }
311 
312  return Result;
313 }
314 
317 
318  for (const auto &AA : AAs) {
319  Result = FunctionModRefBehavior(Result & AA->getModRefBehavior(F));
320 
321  // Early-exit the moment we reach the bottom of the lattice.
322  if (Result == FMRB_DoesNotAccessMemory)
323  return Result;
324  }
325 
326  return Result;
327 }
328 
329 //===----------------------------------------------------------------------===//
330 // Helper method implementation
331 //===----------------------------------------------------------------------===//
332 
334  const MemoryLocation &Loc) {
335  // Be conservative in the face of volatile/atomic.
336  if (!L->isUnordered())
337  return MRI_ModRef;
338 
339  // If the load address doesn't alias the given address, it doesn't read
340  // or write the specified memory.
341  if (Loc.Ptr && !alias(MemoryLocation::get(L), Loc))
342  return MRI_NoModRef;
343 
344  // Otherwise, a load just reads.
345  return MRI_Ref;
346 }
347 
349  const MemoryLocation &Loc) {
350  // Be conservative in the face of volatile/atomic.
351  if (!S->isUnordered())
352  return MRI_ModRef;
353 
354  if (Loc.Ptr) {
355  // If the store address cannot alias the pointer in question, then the
356  // specified memory cannot be modified by the store.
357  if (!alias(MemoryLocation::get(S), Loc))
358  return MRI_NoModRef;
359 
360  // If the pointer is a pointer to constant memory, then it could not have
361  // been modified by this store.
362  if (pointsToConstantMemory(Loc))
363  return MRI_NoModRef;
364  }
365 
366  // Otherwise, a store just writes.
367  return MRI_Mod;
368 }
369 
371  const MemoryLocation &Loc) {
372 
373  if (Loc.Ptr) {
374  // If the va_arg address cannot alias the pointer in question, then the
375  // specified memory cannot be accessed by the va_arg.
376  if (!alias(MemoryLocation::get(V), Loc))
377  return MRI_NoModRef;
378 
379  // If the pointer is a pointer to constant memory, then it could not have
380  // been modified by this va_arg.
381  if (pointsToConstantMemory(Loc))
382  return MRI_NoModRef;
383  }
384 
385  // Otherwise, a va_arg reads and writes.
386  return MRI_ModRef;
387 }
388 
390  const MemoryLocation &Loc) {
391  if (Loc.Ptr) {
392  // If the pointer is a pointer to constant memory,
393  // then it could not have been modified by this catchpad.
394  if (pointsToConstantMemory(Loc))
395  return MRI_NoModRef;
396  }
397 
398  // Otherwise, a catchpad reads and writes.
399  return MRI_ModRef;
400 }
401 
403  const MemoryLocation &Loc) {
404  if (Loc.Ptr) {
405  // If the pointer is a pointer to constant memory,
406  // then it could not have been modified by this catchpad.
407  if (pointsToConstantMemory(Loc))
408  return MRI_NoModRef;
409  }
410 
411  // Otherwise, a catchret reads and writes.
412  return MRI_ModRef;
413 }
414 
416  const MemoryLocation &Loc) {
417  // Acquire/Release cmpxchg has properties that matter for arbitrary addresses.
419  return MRI_ModRef;
420 
421  // If the cmpxchg address does not alias the location, it does not access it.
422  if (Loc.Ptr && !alias(MemoryLocation::get(CX), Loc))
423  return MRI_NoModRef;
424 
425  return MRI_ModRef;
426 }
427 
429  const MemoryLocation &Loc) {
430  // Acquire/Release atomicrmw has properties that matter for arbitrary addresses.
432  return MRI_ModRef;
433 
434  // If the atomicrmw address does not alias the location, it does not access it.
435  if (Loc.Ptr && !alias(MemoryLocation::get(RMW), Loc))
436  return MRI_NoModRef;
437 
438  return MRI_ModRef;
439 }
440 
441 /// \brief Return information about whether a particular call site modifies
442 /// or reads the specified memory location \p MemLoc before instruction \p I
443 /// in a BasicBlock. A ordered basic block \p OBB can be used to speed up
444 /// instruction-ordering queries inside the BasicBlock containing \p I.
445 /// FIXME: this is really just shoring-up a deficiency in alias analysis.
446 /// BasicAA isn't willing to spend linear time determining whether an alloca
447 /// was captured before or after this particular call, while we are. However,
448 /// with a smarter AA in place, this test is just wasting compile time.
450  const MemoryLocation &MemLoc,
451  DominatorTree *DT,
452  OrderedBasicBlock *OBB) {
453  if (!DT)
454  return MRI_ModRef;
455 
456  const Value *Object =
458  if (!isIdentifiedObject(Object) || isa<GlobalValue>(Object) ||
459  isa<Constant>(Object))
460  return MRI_ModRef;
461 
462  ImmutableCallSite CS(I);
463  if (!CS.getInstruction() || CS.getInstruction() == Object)
464  return MRI_ModRef;
465 
466  if (llvm::PointerMayBeCapturedBefore(Object, /* ReturnCaptures */ true,
467  /* StoreCaptures */ true, I, DT,
468  /* include Object */ true,
469  /* OrderedBasicBlock */ OBB))
470  return MRI_ModRef;
471 
472  unsigned ArgNo = 0;
474  for (auto CI = CS.data_operands_begin(), CE = CS.data_operands_end();
475  CI != CE; ++CI, ++ArgNo) {
476  // Only look at the no-capture or byval pointer arguments. If this
477  // pointer were passed to arguments that were neither of these, then it
478  // couldn't be no-capture.
479  if (!(*CI)->getType()->isPointerTy() ||
480  (!CS.doesNotCapture(ArgNo) &&
481  ArgNo < CS.getNumArgOperands() && !CS.isByValArgument(ArgNo)))
482  continue;
483 
484  // If this is a no-capture pointer argument, see if we can tell that it
485  // is impossible to alias the pointer we're checking. If not, we have to
486  // assume that the call could touch the pointer, even though it doesn't
487  // escape.
488  if (isNoAlias(MemoryLocation(*CI), MemoryLocation(Object)))
489  continue;
490  if (CS.doesNotAccessMemory(ArgNo))
491  continue;
492  if (CS.onlyReadsMemory(ArgNo)) {
493  R = MRI_Ref;
494  continue;
495  }
496  return MRI_ModRef;
497  }
498  return R;
499 }
500 
501 /// canBasicBlockModify - Return true if it is possible for execution of the
502 /// specified basic block to modify the location Loc.
503 ///
505  const MemoryLocation &Loc) {
506  return canInstructionRangeModRef(BB.front(), BB.back(), Loc, MRI_Mod);
507 }
508 
509 /// canInstructionRangeModRef - Return true if it is possible for the
510 /// execution of the specified instructions to mod\ref (according to the
511 /// mode) the location Loc. The instructions to consider are all
512 /// of the instructions in the range of [I1,I2] INCLUSIVE.
513 /// I1 and I2 must be in the same basic block.
515  const Instruction &I2,
516  const MemoryLocation &Loc,
517  const ModRefInfo Mode) {
518  assert(I1.getParent() == I2.getParent() &&
519  "Instructions not in same basic block!");
522  ++E; // Convert from inclusive to exclusive range.
523 
524  for (; I != E; ++I) // Check every instruction in range
525  if (getModRefInfo(&*I, Loc) & Mode)
526  return true;
527  return false;
528 }
529 
530 // Provide a definition for the root virtual destructor.
532 
533 // Provide a definition for the static object used to identify passes.
534 AnalysisKey AAManager::Key;
535 
536 namespace {
537 /// A wrapper pass for external alias analyses. This just squirrels away the
538 /// callback used to run any analyses and register their results.
539 struct ExternalAAWrapperPass : ImmutablePass {
540  typedef std::function<void(Pass &, Function &, AAResults &)> CallbackT;
541 
542  CallbackT CB;
543 
544  static char ID;
545 
546  ExternalAAWrapperPass() : ImmutablePass(ID) {
548  }
549  explicit ExternalAAWrapperPass(CallbackT CB)
550  : ImmutablePass(ID), CB(std::move(CB)) {
552  }
553 
554  void getAnalysisUsage(AnalysisUsage &AU) const override {
555  AU.setPreservesAll();
556  }
557 };
558 }
559 
561 INITIALIZE_PASS(ExternalAAWrapperPass, "external-aa", "External Alias Analysis",
562  false, true)
563 
565 llvm::createExternalAAWrapperPass(ExternalAAWrapperPass::CallbackT Callback) {
566  return new ExternalAAWrapperPass(std::move(Callback));
567 }
568 
571 }
572 
573 char AAResultsWrapperPass::ID = 0;
574 
576  "Function Alias Analysis Results", false, true)
580 INITIALIZE_PASS_DEPENDENCY(ExternalAAWrapperPass)
582 INITIALIZE_PASS_DEPENDENCY(ObjCARCAAWrapperPass)
587  "Function Alias Analysis Results", false, true)
588 
590  return new AAResultsWrapperPass();
591 }
592 
593 /// Run the wrapper pass to rebuild an aggregation over known AA passes.
594 ///
595 /// This is the legacy pass manager's interface to the new-style AA results
596 /// aggregation object. Because this is somewhat shoe-horned into the legacy
597 /// pass manager, we hard code all the specific alias analyses available into
598 /// it. While the particular set enabled is configured via commandline flags,
599 /// adding a new alias analysis to LLVM will require adding support for it to
600 /// this list.
602  // NB! This *must* be reset before adding new AA results to the new
603  // AAResults object because in the legacy pass manager, each instance
604  // of these will refer to the *same* immutable analyses, registering and
605  // unregistering themselves with them. We need to carefully tear down the
606  // previous object first, in this case replacing it with an empty one, before
607  // registering new results.
608  AAR.reset(
609  new AAResults(getAnalysis<TargetLibraryInfoWrapperPass>().getTLI()));
610 
611  // BasicAA is always available for function analyses. Also, we add it first
612  // so that it can trump TBAA results when it proves MustAlias.
613  // FIXME: TBAA should have an explicit mode to support this and then we
614  // should reconsider the ordering here.
615  if (!DisableBasicAA)
616  AAR->addAAResult(getAnalysis<BasicAAWrapperPass>().getResult());
617 
618  // Populate the results with the currently available AAs.
619  if (auto *WrapperPass = getAnalysisIfAvailable<ScopedNoAliasAAWrapperPass>())
620  AAR->addAAResult(WrapperPass->getResult());
621  if (auto *WrapperPass = getAnalysisIfAvailable<TypeBasedAAWrapperPass>())
622  AAR->addAAResult(WrapperPass->getResult());
623  if (auto *WrapperPass =
624  getAnalysisIfAvailable<objcarc::ObjCARCAAWrapperPass>())
625  AAR->addAAResult(WrapperPass->getResult());
626  if (auto *WrapperPass = getAnalysisIfAvailable<GlobalsAAWrapperPass>())
627  AAR->addAAResult(WrapperPass->getResult());
628  if (auto *WrapperPass = getAnalysisIfAvailable<SCEVAAWrapperPass>())
629  AAR->addAAResult(WrapperPass->getResult());
630  if (auto *WrapperPass = getAnalysisIfAvailable<CFLAndersAAWrapperPass>())
631  AAR->addAAResult(WrapperPass->getResult());
632  if (auto *WrapperPass = getAnalysisIfAvailable<CFLSteensAAWrapperPass>())
633  AAR->addAAResult(WrapperPass->getResult());
634 
635  // If available, run an external AA providing callback over the results as
636  // well.
637  if (auto *WrapperPass = getAnalysisIfAvailable<ExternalAAWrapperPass>())
638  if (WrapperPass->CB)
639  WrapperPass->CB(*this, F, *AAR);
640 
641  // Analyses don't mutate the IR, so return false.
642  return false;
643 }
644 
646  AU.setPreservesAll();
649 
650  // We also need to mark all the alias analysis passes we will potentially
651  // probe in runOnFunction as used here to ensure the legacy pass manager
652  // preserves them. This hard coding of lists of alias analyses is specific to
653  // the legacy pass manager.
661 }
662 
664  BasicAAResult &BAR) {
666 
667  // Add in our explicitly constructed BasicAA results.
668  if (!DisableBasicAA)
669  AAR.addAAResult(BAR);
670 
671  // Populate the results with the other currently available AAs.
672  if (auto *WrapperPass =
674  AAR.addAAResult(WrapperPass->getResult());
675  if (auto *WrapperPass = P.getAnalysisIfAvailable<TypeBasedAAWrapperPass>())
676  AAR.addAAResult(WrapperPass->getResult());
677  if (auto *WrapperPass =
679  AAR.addAAResult(WrapperPass->getResult());
680  if (auto *WrapperPass = P.getAnalysisIfAvailable<GlobalsAAWrapperPass>())
681  AAR.addAAResult(WrapperPass->getResult());
682  if (auto *WrapperPass = P.getAnalysisIfAvailable<CFLAndersAAWrapperPass>())
683  AAR.addAAResult(WrapperPass->getResult());
684  if (auto *WrapperPass = P.getAnalysisIfAvailable<CFLSteensAAWrapperPass>())
685  AAR.addAAResult(WrapperPass->getResult());
686 
687  return AAR;
688 }
689 
690 bool llvm::isNoAliasCall(const Value *V) {
691  if (auto CS = ImmutableCallSite(V))
692  return CS.paramHasAttr(0, Attribute::NoAlias);
693  return false;
694 }
695 
697  if (const Argument *A = dyn_cast<Argument>(V))
698  return A->hasNoAliasAttr();
699  return false;
700 }
701 
703  if (isa<AllocaInst>(V))
704  return true;
705  if (isa<GlobalValue>(V) && !isa<GlobalAlias>(V))
706  return true;
707  if (isNoAliasCall(V))
708  return true;
709  if (const Argument *A = dyn_cast<Argument>(V))
710  return A->hasNoAliasAttr() || A->hasByValAttr();
711  return false;
712 }
713 
715  return isa<AllocaInst>(V) || isNoAliasCall(V) || isNoAliasArgument(V);
716 }
717 
719  // This function needs to be in sync with llvm::createLegacyPMAAResults -- if
720  // more alias analyses are added to llvm::createLegacyPMAAResults, they need
721  // to be added here also.
729 }
Legacy wrapper pass to provide the GlobalsAAResult object.
MachineLoop * L
Pass interface - Implemented by all 'passes'.
Definition: Pass.h:81
IterTy arg_end() const
Definition: CallSite.h:532
bool invalidate(IRUnitT &IR, const PreservedAnalyses &PA)
Trigger the invalidation of some other analysis pass if not already handled and return whether it was...
Definition: PassManager.h:543
void addAAResult(AAResultT &AAResult)
Register a specific AA result.
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
LLVM Argument representation.
Definition: Argument.h:34
const Instruction & back() const
Definition: BasicBlock.h:242
SI Whole Quad Mode
bool isFenceLike() const
Return true if this instruction behaves like a memory fence: it can load or store to memory location ...
Definition: Instruction.h:429
This is the interface for LLVM's inclusion-based alias analysis implemented with CFL graph reachabili...
bool doesNotCapture(unsigned OpNo) const
Determine whether this data operand is not captured.
Definition: CallSite.h:550
This is the interface for a simple mod/ref and alias analysis over globals.
AtomicOrdering getSuccessOrdering() const
Returns the ordering constraint on this cmpxchg.
Definition: Instructions.h:585
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:504
bool isNoAlias(const MemoryLocation &LocA, const MemoryLocation &LocB)
A trivial helper function to check to see if the specified pointers are no-alias. ...
This is the interface for a metadata-based scoped no-alias analysis.
Function Alias Analysis Results
This is the AA result object for the basic, local, and stateless alias analysis.
bool onlyReadsMemory(ImmutableCallSite CS)
Checks if the specified call is known to only read from non-volatile memory (or not access memory at ...
bool onlyReadsMemory() const
Determine if the call does not access or only reads memory.
Definition: CallSite.h:429
INITIALIZE_PASS_BEGIN(AAResultsWrapperPass,"aa","Function Alias Analysis Results", false, true) INITIALIZE_PASS_END(AAResultsWrapperPass
static bool onlyAccessesInaccessibleOrArgMem(FunctionModRefBehavior MRB)
Checks if functions with the specified behavior are known to read and write at most from memory that ...
const Instruction & front() const
Definition: BasicBlock.h:240
The two locations do not alias at all.
Definition: AliasAnalysis.h:79
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:164
an instruction that atomically reads a memory location, combines it with another value, and then stores the result back.
Definition: Instructions.h:669
void initializeExternalAAWrapperPassPass(PassRegistry &)
The access modifies the value stored in memory.
The two locations may or may not alias. This is the least precise result.
Definition: AliasAnalysis.h:81
This indicates that the function could not be classified into one of the behaviors above...
Legacy wrapper pass to provide the TypeBasedAAResult object.
AliasResult alias(const MemoryLocation &LocA, const MemoryLocation &LocB)
The main low level interface to the alias analysis implementation.
AnalysisUsage & addRequired()
The only memory references in this function (if it has any) are references of memory that is otherwis...
#define INITIALIZE_PASS_DEPENDENCY(depName)
Definition: PassSupport.h:53
ModRefInfo
Flags indicating whether a memory access modifies or references memory.
Definition: AliasAnalysis.h:94
This is the interface for a SCEV-based alias analysis.
FunctionPass * createAAResultsWrapperPass()
static bool doesNotReadMemory(FunctionModRefBehavior MRB)
Checks if functions with the specified behavior are known to only write memory (or not access memory ...
bool isUnordered() const
Definition: Instructions.h:264
AnalysisType * getAnalysisIfAvailable() const
getAnalysisIfAvailable<AnalysisType>() - Subclasses use this function to get analysis information tha...
The access references the value stored in memory.
Definition: AliasAnalysis.h:98
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...
bool isIdentifiedObject(const Value *V)
Return true if this pointer refers to a distinct and identifiable object.
void initializeAAResultsWrapperPassPass(PassRegistry &)
IterTy data_operands_begin() const
data_operands_begin/data_operands_end - Return iterators iterating over the call / invoke argument li...
Definition: CallSite.h:238
AtomicOrdering getOrdering() const
Returns the ordering constraint on this RMW.
Definition: Instructions.h:767
#define F(x, y, z)
Definition: MD5.cpp:51
FunctionModRefBehavior
Summary of how a function affects memory in the program.
Function Alias Analysis false
bool runOnFunction(Function &F) override
Run the wrapper pass to rebuild an aggregation over known AA passes.
Legacy wrapper pass to provide the CFLSteensAAResult object.
An instruction for storing to memory.
Definition: Instructions.h:300
static cl::opt< bool > DisableBasicAA("disable-basicaa", cl::Hidden, cl::init(false))
Allow disabling BasicAA from the AA results.
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree...
Definition: Dominators.h:96
static GCRegistry::Add< CoreCLRGC > E("coreclr","CoreCLR-compatible GC")
bool invalidate(Function &F, const PreservedAnalyses &PA, FunctionAnalysisManager::Invalidator &Inv)
Handle invalidation events in the new pass manager.
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 ...
The access neither references nor modifies the value stored in memory.
Definition: AliasAnalysis.h:96
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...
Legacy wrapper pass to provide the ScopedNoAliasAAResult object.
#define P(N)
static MemoryLocation get(const LoadInst *LI)
Return a location with information about the memory reference by the given instruction.
This is the interface for LLVM's unification-based alias analysis implemented with CFL graph reachabi...
initializer< Ty > init(const Ty &Val)
Definition: CommandLine.h:395
A set of analyses that are preserved following a run of a transformation pass.
Definition: PassManager.h:107
This is the interface for a metadata-based TBAA.
LLVM Basic Block Representation.
Definition: BasicBlock.h:51
bool canInstructionRangeModRef(const Instruction &I1, const Instruction &I2, const MemoryLocation &Loc, const ModRefInfo Mode)
Check if it is possible for the execution of the specified instructions to mod(according to the mode)...
A manager for alias analyses.
Legacy wrapper pass to provide the CFLAndersAAResult object.
AliasResult
The possible results of an alias query.
Definition: AliasAnalysis.h:73
FunctionModRefBehavior getModRefBehavior(ImmutableCallSite CS)
Return the behavior of the given call site.
Represent the analysis usage information of a pass.
PreservedAnalysisChecker getChecker() const
Build a checker for this PreservedAnalyses and the specified analysis type.
Definition: PassManager.h:250
bool isByValArgument(unsigned ArgNo) const
Determine whether this argument is passed by value.
Definition: CallSite.h:555
static bool doesAccessArgPointees(FunctionModRefBehavior MRB)
Checks if functions with the specified behavior are known to potentially read or write from objects p...
INITIALIZE_PASS_END(RegBankSelect, DEBUG_TYPE,"Assign register bank of generic virtual registers", false, false) RegBankSelect
FunctionPass class - This class is used to implement most global optimizations.
Definition: Pass.h:298
self_iterator getIterator()
Definition: ilist_node.h:81
bool isUnordered() const
Definition: Instructions.h:385
bool isPointerTy() const
True if this is an instance of PointerType.
Definition: Type.h:213
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...
Value * GetUnderlyingObject(Value *V, const DataLayout &DL, unsigned MaxLookup=6)
This method strips off any GEP address adjustments and pointer casts from the specified value...
This file declares a simple ARC-aware AliasAnalysis using special knowledge of Objective C to enhance...
This function does not perform any non-local loads or stores to memory.
static MemoryLocation getForArgument(ImmutableCallSite CS, unsigned ArgIdx, const TargetLibraryInfo &TLI)
Return a location representing a particular argument of a call.
bool isIdentifiedFunctionLocal(const Value *V)
Return true if V is umabigously identified at the function-level.
bool doesNotAccessMemory() const
Determine if the call does not access memory.
Definition: CallSite.h:421
const Value * Ptr
The address of the start of the location.
IterTy arg_begin() const
Definition: CallSite.h:528
Representation for a specific memory location.
AnalysisType & getAnalysis() const
getAnalysis<AnalysisType>() - This function is used by subclasses to get to the analysis information ...
Iterator for intrusive lists based on ilist_node.
Legacy wrapper pass to provide the SCEVAAResult object.
ImmutablePass class - This class is used to provide information that does not need to be run...
Definition: Pass.h:266
InstrTy * getInstruction() const
Definition: CallSite.h:93
static bool isStrongerThanMonotonic(AtomicOrdering ao)
const Module * getModule() const
Return the module owning the function this instruction belongs to or nullptr it the function does not...
Definition: Instruction.cpp:58
Type * getType() const
All values are typed, get the type of this value.
Definition: Value.h:230
unsigned getNumArgOperands() const
Definition: CallSite.h:288
ModRefInfo callCapturesBefore(const Instruction *I, const MemoryLocation &MemLoc, DominatorTree *DT, OrderedBasicBlock *OBB=nullptr)
Return information about whether a particular call site modifies or reads the specified memory locati...
ModRefInfo getModRefInfo(ImmutableCallSite CS, const MemoryLocation &Loc)
getModRefInfo (for call sites) - Return information about whether a particular call site modifies or ...
void setPreservesAll()
Set by analyses that do not transform their input at all.
AAResults(const TargetLibraryInfo &TLI)
Basic Alias true
const DataLayout & getDataLayout() const
Get the data layout for the module's target platform.
Definition: Module.cpp:384
static bool onlyAccessesArgPointees(FunctionModRefBehavior MRB)
Checks if functions with the specified behavior are known to read and write at most from objects poin...
block Block Frequency Analysis
INITIALIZE_PASS(ExternalAAWrapperPass,"external-aa","External Alias Analysis", false, true) ImmutablePass *llvm
ImmutableCallSite - establish a view to a call site for examination.
Definition: CallSite.h:665
The access both references and modifies the value stored in memory.
#define I(x, y, z)
Definition: MD5.cpp:54
API to communicate dependencies between analyses during invalidation.
Definition: PassManager.h:525
bool PointerMayBeCapturedBefore(const Value *V, bool ReturnCaptures, bool StoreCaptures, const Instruction *I, DominatorTree *DT, bool IncludeI=false, OrderedBasicBlock *OBB=nullptr)
PointerMayBeCapturedBefore - Return true if this pointer value may be captured by the enclosing funct...
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
This templated class represents "all analyses that operate over \<a particular IR unit\>" (e...
Definition: PassManager.h:361
AnalysisUsage & addUsedIfAvailable()
Add the specified Pass class to the set of analyses used by this pass.
LLVM Value Representation.
Definition: Value.h:71
Legacy wrapper pass to provide the ObjCARCAAResult object.
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - This function should be overriden by passes that need analysis information to do t...
This is the interface for LLVM's primary stateless and local alias analysis.
bool isNoAliasArgument(const Value *V)
Return true if this is an argument with the noalias attribute.
A wrapper pass to provide the legacy pass manager access to a suitably prepared AAResults object...
IterTy data_operands_end() const
Definition: CallSite.h:242
static GCRegistry::Add< ErlangGC > A("erlang","erlang-compatible garbage collector")
bool canBasicBlockModify(const BasicBlock &BB, const MemoryLocation &Loc)
Check if it is possible for execution of the specified basic block to modify the location Loc...
A special type used by analysis passes to provide an address that identifies that particular analysis...
Definition: PassManager.h:64
const BasicBlock * getParent() const
Definition: Instruction.h:62
ModRefInfo getArgModRefInfo(ImmutableCallSite CS, unsigned ArgIdx)
Get the ModRef info associated with a pointer argument of a callsite.
Legacy wrapper pass to provide the BasicAAResult object.