LLVM API Documentation

ObjCARCAliasAnalysis.h
Go to the documentation of this file.
00001 //===- ObjCARCAliasAnalysis.h - ObjC ARC Optimization -*- C++ -*-----------===//
00002 //
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file is distributed under the University of Illinois Open Source
00006 // License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 /// \file
00010 /// This file declares a simple ARC-aware AliasAnalysis using special knowledge
00011 /// of Objective C to enhance other optimization passes which rely on the Alias
00012 /// Analysis infrastructure.
00013 ///
00014 /// WARNING: This file knows about certain library functions. It recognizes them
00015 /// by name, and hardwires knowledge of their semantics.
00016 ///
00017 /// WARNING: This file knows about how certain Objective-C library functions are
00018 /// used. Naive LLVM IR transformations which would otherwise be
00019 /// behavior-preserving may break these assumptions.
00020 ///
00021 //===----------------------------------------------------------------------===//
00022 
00023 #ifndef LLVM_LIB_TRANSFORMS_OBJCARC_OBJCARCALIASANALYSIS_H
00024 #define LLVM_LIB_TRANSFORMS_OBJCARC_OBJCARCALIASANALYSIS_H
00025 
00026 #include "llvm/Analysis/AliasAnalysis.h"
00027 #include "llvm/Pass.h"
00028 
00029 namespace llvm {
00030 namespace objcarc {
00031 
00032   /// \brief This is a simple alias analysis implementation that uses knowledge
00033   /// of ARC constructs to answer queries.
00034   ///
00035   /// TODO: This class could be generalized to know about other ObjC-specific
00036   /// tricks. Such as knowing that ivars in the non-fragile ABI are non-aliasing
00037   /// even though their offsets are dynamic.
00038   class ObjCARCAliasAnalysis : public ImmutablePass,
00039                                public AliasAnalysis {
00040   public:
00041     static char ID; // Class identification, replacement for typeinfo
00042     ObjCARCAliasAnalysis() : ImmutablePass(ID) {
00043       initializeObjCARCAliasAnalysisPass(*PassRegistry::getPassRegistry());
00044     }
00045 
00046   private:
00047     void initializePass() override {
00048       InitializeAliasAnalysis(this);
00049     }
00050 
00051     /// This method is used when a pass implements an analysis interface through
00052     /// multiple inheritance.  If needed, it should override this to adjust the
00053     /// this pointer as needed for the specified pass info.
00054     void *getAdjustedAnalysisPointer(const void *PI) override {
00055       if (PI == &AliasAnalysis::ID)
00056         return static_cast<AliasAnalysis *>(this);
00057       return this;
00058     }
00059 
00060     void getAnalysisUsage(AnalysisUsage &AU) const override;
00061     AliasResult alias(const Location &LocA, const Location &LocB) override;
00062     bool pointsToConstantMemory(const Location &Loc, bool OrLocal) override;
00063     ModRefBehavior getModRefBehavior(ImmutableCallSite CS) override;
00064     ModRefBehavior getModRefBehavior(const Function *F) override;
00065     ModRefResult getModRefInfo(ImmutableCallSite CS,
00066                                const Location &Loc) override;
00067     ModRefResult getModRefInfo(ImmutableCallSite CS1,
00068                                ImmutableCallSite CS2) override;
00069   };
00070 
00071 } // namespace objcarc
00072 } // namespace llvm
00073 
00074 #endif