Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 1 | //===- ObjCARCAliasAnalysis.h - ObjC ARC Alias Analysis ---------*- C++ -*-===// |
| 2 | // |
Andrew Walbran | 16937d0 | 2019-10-22 13:54:20 +0100 | [diff] [blame] | 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | /// \file |
| 9 | /// This file declares a simple ARC-aware AliasAnalysis using special knowledge |
| 10 | /// of Objective C to enhance other optimization passes which rely on the Alias |
| 11 | /// Analysis infrastructure. |
| 12 | /// |
| 13 | /// WARNING: This file knows about certain library functions. It recognizes them |
| 14 | /// by name, and hardwires knowledge of their semantics. |
| 15 | /// |
| 16 | /// WARNING: This file knows about how certain Objective-C library functions are |
| 17 | /// used. Naive LLVM IR transformations which would otherwise be |
| 18 | /// behavior-preserving may break these assumptions. |
| 19 | /// |
| 20 | //===----------------------------------------------------------------------===// |
| 21 | |
| 22 | #ifndef LLVM_ANALYSIS_OBJCARCALIASANALYSIS_H |
| 23 | #define LLVM_ANALYSIS_OBJCARCALIASANALYSIS_H |
| 24 | |
| 25 | #include "llvm/Analysis/AliasAnalysis.h" |
| 26 | #include "llvm/Pass.h" |
| 27 | |
| 28 | namespace llvm { |
| 29 | namespace objcarc { |
| 30 | |
Andrew Scull | cdfcccc | 2018-10-05 20:58:37 +0100 | [diff] [blame] | 31 | /// This is a simple alias analysis implementation that uses knowledge |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 32 | /// of ARC constructs to answer queries. |
| 33 | /// |
| 34 | /// TODO: This class could be generalized to know about other ObjC-specific |
| 35 | /// tricks. Such as knowing that ivars in the non-fragile ABI are non-aliasing |
| 36 | /// even though their offsets are dynamic. |
| 37 | class ObjCARCAAResult : public AAResultBase<ObjCARCAAResult> { |
| 38 | friend AAResultBase<ObjCARCAAResult>; |
| 39 | |
| 40 | const DataLayout &DL; |
| 41 | |
| 42 | public: |
| 43 | explicit ObjCARCAAResult(const DataLayout &DL) : AAResultBase(), DL(DL) {} |
| 44 | ObjCARCAAResult(ObjCARCAAResult &&Arg) |
| 45 | : AAResultBase(std::move(Arg)), DL(Arg.DL) {} |
| 46 | |
| 47 | /// Handle invalidation events from the new pass manager. |
| 48 | /// |
| 49 | /// By definition, this result is stateless and so remains valid. |
| 50 | bool invalidate(Function &, const PreservedAnalyses &, |
| 51 | FunctionAnalysisManager::Invalidator &) { |
| 52 | return false; |
| 53 | } |
| 54 | |
Andrew Walbran | 3d2c197 | 2020-04-07 12:24:26 +0100 | [diff] [blame] | 55 | AliasResult alias(const MemoryLocation &LocA, const MemoryLocation &LocB, |
| 56 | AAQueryInfo &AAQI); |
| 57 | bool pointsToConstantMemory(const MemoryLocation &Loc, AAQueryInfo &AAQI, |
| 58 | bool OrLocal); |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 59 | |
| 60 | using AAResultBase::getModRefBehavior; |
| 61 | FunctionModRefBehavior getModRefBehavior(const Function *F); |
| 62 | |
| 63 | using AAResultBase::getModRefInfo; |
Andrew Walbran | 3d2c197 | 2020-04-07 12:24:26 +0100 | [diff] [blame] | 64 | ModRefInfo getModRefInfo(const CallBase *Call, const MemoryLocation &Loc, |
| 65 | AAQueryInfo &AAQI); |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 66 | }; |
| 67 | |
| 68 | /// Analysis pass providing a never-invalidated alias analysis result. |
| 69 | class ObjCARCAA : public AnalysisInfoMixin<ObjCARCAA> { |
| 70 | friend AnalysisInfoMixin<ObjCARCAA>; |
| 71 | static AnalysisKey Key; |
| 72 | |
| 73 | public: |
| 74 | typedef ObjCARCAAResult Result; |
| 75 | |
| 76 | ObjCARCAAResult run(Function &F, FunctionAnalysisManager &AM); |
| 77 | }; |
| 78 | |
| 79 | /// Legacy wrapper pass to provide the ObjCARCAAResult object. |
| 80 | class ObjCARCAAWrapperPass : public ImmutablePass { |
| 81 | std::unique_ptr<ObjCARCAAResult> Result; |
| 82 | |
| 83 | public: |
| 84 | static char ID; |
| 85 | |
| 86 | ObjCARCAAWrapperPass(); |
| 87 | |
| 88 | ObjCARCAAResult &getResult() { return *Result; } |
| 89 | const ObjCARCAAResult &getResult() const { return *Result; } |
| 90 | |
| 91 | bool doInitialization(Module &M) override; |
| 92 | bool doFinalization(Module &M) override; |
| 93 | void getAnalysisUsage(AnalysisUsage &AU) const override; |
| 94 | }; |
| 95 | |
| 96 | } // namespace objcarc |
| 97 | } // namespace llvm |
| 98 | |
| 99 | #endif |