]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/include/llvm/Analysis/ObjCARCAliasAnalysis.h
Merge ^/head r303250 through r308226.
[FreeBSD/FreeBSD.git] / contrib / llvm / include / llvm / Analysis / ObjCARCAliasAnalysis.h
1 //===- ObjCARCAliasAnalysis.h - ObjC ARC Alias Analysis ---------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 /// \file
10 /// This file declares a simple ARC-aware AliasAnalysis using special knowledge
11 /// of Objective C to enhance other optimization passes which rely on the Alias
12 /// Analysis infrastructure.
13 ///
14 /// WARNING: This file knows about certain library functions. It recognizes them
15 /// by name, and hardwires knowledge of their semantics.
16 ///
17 /// WARNING: This file knows about how certain Objective-C library functions are
18 /// used. Naive LLVM IR transformations which would otherwise be
19 /// behavior-preserving may break these assumptions.
20 ///
21 //===----------------------------------------------------------------------===//
22
23 #ifndef LLVM_ANALYSIS_OBJCARCALIASANALYSIS_H
24 #define LLVM_ANALYSIS_OBJCARCALIASANALYSIS_H
25
26 #include "llvm/Analysis/AliasAnalysis.h"
27 #include "llvm/Pass.h"
28
29 namespace llvm {
30 namespace objcarc {
31
32 /// \brief This is a simple alias analysis implementation that uses knowledge
33 /// of ARC constructs to answer queries.
34 ///
35 /// TODO: This class could be generalized to know about other ObjC-specific
36 /// tricks. Such as knowing that ivars in the non-fragile ABI are non-aliasing
37 /// even though their offsets are dynamic.
38 class ObjCARCAAResult : public AAResultBase<ObjCARCAAResult> {
39   friend AAResultBase<ObjCARCAAResult>;
40
41   const DataLayout &DL;
42
43 public:
44   explicit ObjCARCAAResult(const DataLayout &DL) : AAResultBase(), DL(DL) {}
45   ObjCARCAAResult(ObjCARCAAResult &&Arg)
46       : AAResultBase(std::move(Arg)), DL(Arg.DL) {}
47
48   /// Handle invalidation events from the new pass manager.
49   ///
50   /// By definition, this result is stateless and so remains valid.
51   bool invalidate(Function &, const PreservedAnalyses &) { return false; }
52
53   AliasResult alias(const MemoryLocation &LocA, const MemoryLocation &LocB);
54   bool pointsToConstantMemory(const MemoryLocation &Loc, bool OrLocal);
55
56   using AAResultBase::getModRefBehavior;
57   FunctionModRefBehavior getModRefBehavior(const Function *F);
58
59   using AAResultBase::getModRefInfo;
60   ModRefInfo getModRefInfo(ImmutableCallSite CS, const MemoryLocation &Loc);
61 };
62
63 /// Analysis pass providing a never-invalidated alias analysis result.
64 class ObjCARCAA : public AnalysisInfoMixin<ObjCARCAA> {
65   friend AnalysisInfoMixin<ObjCARCAA>;
66   static char PassID;
67
68 public:
69   typedef ObjCARCAAResult Result;
70
71   ObjCARCAAResult run(Function &F, AnalysisManager<Function> &AM);
72 };
73
74 /// Legacy wrapper pass to provide the ObjCARCAAResult object.
75 class ObjCARCAAWrapperPass : public ImmutablePass {
76   std::unique_ptr<ObjCARCAAResult> Result;
77
78 public:
79   static char ID;
80
81   ObjCARCAAWrapperPass();
82
83   ObjCARCAAResult &getResult() { return *Result; }
84   const ObjCARCAAResult &getResult() const { return *Result; }
85
86   bool doInitialization(Module &M) override;
87   bool doFinalization(Module &M) override;
88   void getAnalysisUsage(AnalysisUsage &AU) const override;
89 };
90
91 } // namespace objcarc
92 } // namespace llvm
93
94 #endif