1 //===- ObjCARCAliasAnalysis.h - ObjC ARC Alias Analysis ---------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
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.
14 /// WARNING: This file knows about certain library functions. It recognizes them
15 /// by name, and hardwires knowledge of their semantics.
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.
21 //===----------------------------------------------------------------------===//
23 #ifndef LLVM_ANALYSIS_OBJCARCALIASANALYSIS_H
24 #define LLVM_ANALYSIS_OBJCARCALIASANALYSIS_H
26 #include "llvm/Analysis/AliasAnalysis.h"
27 #include "llvm/Analysis/TargetLibraryInfo.h"
28 #include "llvm/Pass.h"
33 /// \brief This is a simple alias analysis implementation that uses knowledge
34 /// of ARC constructs to answer queries.
36 /// TODO: This class could be generalized to know about other ObjC-specific
37 /// tricks. Such as knowing that ivars in the non-fragile ABI are non-aliasing
38 /// even though their offsets are dynamic.
39 class ObjCARCAAResult : public AAResultBase<ObjCARCAAResult> {
40 friend AAResultBase<ObjCARCAAResult>;
45 explicit ObjCARCAAResult(const DataLayout &DL, const TargetLibraryInfo &TLI)
46 : AAResultBase(TLI), DL(DL) {}
47 ObjCARCAAResult(ObjCARCAAResult &&Arg)
48 : AAResultBase(std::move(Arg)), DL(Arg.DL) {}
50 /// Handle invalidation events from the new pass manager.
52 /// By definition, this result is stateless and so remains valid.
53 bool invalidate(Function &, const PreservedAnalyses &) { return false; }
55 AliasResult alias(const MemoryLocation &LocA, const MemoryLocation &LocB);
56 bool pointsToConstantMemory(const MemoryLocation &Loc, bool OrLocal);
58 using AAResultBase::getModRefBehavior;
59 FunctionModRefBehavior getModRefBehavior(const Function *F);
61 using AAResultBase::getModRefInfo;
62 ModRefInfo getModRefInfo(ImmutableCallSite CS, const MemoryLocation &Loc);
65 /// Analysis pass providing a never-invalidated alias analysis result.
68 typedef ObjCARCAAResult Result;
70 /// \brief Opaque, unique identifier for this analysis pass.
71 static void *ID() { return (void *)&PassID; }
73 ObjCARCAAResult run(Function &F, AnalysisManager<Function> *AM);
75 /// \brief Provide access to a name for this pass for debugging purposes.
76 static StringRef name() { return "ObjCARCAA"; }
82 /// Legacy wrapper pass to provide the ObjCARCAAResult object.
83 class ObjCARCAAWrapperPass : public ImmutablePass {
84 std::unique_ptr<ObjCARCAAResult> Result;
89 ObjCARCAAWrapperPass();
91 ObjCARCAAResult &getResult() { return *Result; }
92 const ObjCARCAAResult &getResult() const { return *Result; }
94 bool doInitialization(Module &M) override;
95 bool doFinalization(Module &M) override;
96 void getAnalysisUsage(AnalysisUsage &AU) const override;
99 } // namespace objcarc