NoAliasAnalysis.cpp 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. //===- NoAliasAnalysis.cpp - Minimal Alias Analysis Impl ------------------===//
  2. //
  3. // The LLVM Compiler Infrastructure
  4. //
  5. // This file is distributed under the University of Illinois Open Source
  6. // License. See LICENSE.TXT for details.
  7. //
  8. //===----------------------------------------------------------------------===//
  9. //
  10. // This file defines the default implementation of the Alias Analysis interface
  11. // that simply returns "I don't know" for all queries.
  12. //
  13. //===----------------------------------------------------------------------===//
  14. #include "llvm/Analysis/Passes.h"
  15. #include "llvm/Analysis/AliasAnalysis.h"
  16. #include "llvm/IR/DataLayout.h"
  17. #include "llvm/IR/LLVMContext.h"
  18. #include "llvm/IR/Module.h"
  19. #include "llvm/Pass.h"
  20. using namespace llvm;
  21. namespace {
  22. /// NoAA - This class implements the -no-aa pass, which always returns "I
  23. /// don't know" for alias queries. NoAA is unlike other alias analysis
  24. /// implementations, in that it does not chain to a previous analysis. As
  25. /// such it doesn't follow many of the rules that other alias analyses must.
  26. ///
  27. struct NoAA : public ImmutablePass, public AliasAnalysis {
  28. static char ID; // Class identification, replacement for typeinfo
  29. NoAA() : ImmutablePass(ID) {
  30. initializeNoAAPass(*PassRegistry::getPassRegistry());
  31. }
  32. void getAnalysisUsage(AnalysisUsage &AU) const override {}
  33. bool doInitialization(Module &M) override {
  34. // Note: NoAA does not call InitializeAliasAnalysis because it's
  35. // special and does not support chaining.
  36. DL = &M.getDataLayout();
  37. return true;
  38. }
  39. AliasResult alias(const MemoryLocation &LocA,
  40. const MemoryLocation &LocB) override {
  41. return MayAlias;
  42. }
  43. ModRefBehavior getModRefBehavior(ImmutableCallSite CS) override {
  44. return UnknownModRefBehavior;
  45. }
  46. ModRefBehavior getModRefBehavior(const Function *F) override {
  47. return UnknownModRefBehavior;
  48. }
  49. bool pointsToConstantMemory(const MemoryLocation &Loc,
  50. bool OrLocal) override {
  51. return false;
  52. }
  53. ModRefResult getArgModRefInfo(ImmutableCallSite CS,
  54. unsigned ArgIdx) override {
  55. return ModRef;
  56. }
  57. ModRefResult getModRefInfo(ImmutableCallSite CS,
  58. const MemoryLocation &Loc) override {
  59. return ModRef;
  60. }
  61. ModRefResult getModRefInfo(ImmutableCallSite CS1,
  62. ImmutableCallSite CS2) override {
  63. return ModRef;
  64. }
  65. void deleteValue(Value *V) override {}
  66. void addEscapingUse(Use &U) override {}
  67. /// getAdjustedAnalysisPointer - This method is used when a pass implements
  68. /// an analysis interface through multiple inheritance. If needed, it
  69. /// should override this to adjust the this pointer as needed for the
  70. /// specified pass info.
  71. void *getAdjustedAnalysisPointer(const void *ID) override {
  72. if (ID == &AliasAnalysis::ID)
  73. return (AliasAnalysis*)this;
  74. return this;
  75. }
  76. };
  77. } // End of anonymous namespace
  78. // Register this pass...
  79. char NoAA::ID = 0;
  80. INITIALIZE_AG_PASS(NoAA, AliasAnalysis, "no-aa",
  81. "No Alias Analysis (always returns 'may' alias)",
  82. true, true, true)
  83. ImmutablePass *llvm::createNoAAPass() { return new NoAA(); }