| 1 | //===- ObjCARCAliasAnalysis.h - ObjC ARC Alias Analysis ---------*- C++ -*-===// |
| 2 | // |
| 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 |
| 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 | |
| 27 | namespace llvm { |
| 28 | namespace objcarc { |
| 29 | |
| 30 | /// This is a simple alias analysis implementation that uses knowledge |
| 31 | /// of ARC constructs to answer queries. |
| 32 | /// |
| 33 | /// TODO: This class could be generalized to know about other ObjC-specific |
| 34 | /// tricks. Such as knowing that ivars in the non-fragile ABI are non-aliasing |
| 35 | /// even though their offsets are dynamic. |
| 36 | class ObjCARCAAResult : public AAResultBase { |
| 37 | const DataLayout &DL; |
| 38 | |
| 39 | public: |
| 40 | explicit ObjCARCAAResult(const DataLayout &DL) : DL(DL) {} |
| 41 | ObjCARCAAResult(ObjCARCAAResult &&Arg) |
| 42 | : AAResultBase(std::move(Arg)), DL(Arg.DL) {} |
| 43 | |
| 44 | /// Handle invalidation events from the new pass manager. |
| 45 | /// |
| 46 | /// By definition, this result is stateless and so remains valid. |
| 47 | bool invalidate(Function &, const PreservedAnalyses &, |
| 48 | FunctionAnalysisManager::Invalidator &) { |
| 49 | return false; |
| 50 | } |
| 51 | |
| 52 | AliasResult alias(const MemoryLocation &LocA, const MemoryLocation &LocB, |
| 53 | AAQueryInfo &AAQI, const Instruction *CtxI); |
| 54 | ModRefInfo getModRefInfoMask(const MemoryLocation &Loc, AAQueryInfo &AAQI, |
| 55 | bool IgnoreLocals); |
| 56 | |
| 57 | using AAResultBase::getMemoryEffects; |
| 58 | MemoryEffects getMemoryEffects(const Function *F); |
| 59 | |
| 60 | using AAResultBase::getModRefInfo; |
| 61 | ModRefInfo getModRefInfo(const CallBase *Call, const MemoryLocation &Loc, |
| 62 | AAQueryInfo &AAQI); |
| 63 | }; |
| 64 | |
| 65 | /// Analysis pass providing a never-invalidated alias analysis result. |
| 66 | class ObjCARCAA : public AnalysisInfoMixin<ObjCARCAA> { |
| 67 | friend AnalysisInfoMixin<ObjCARCAA>; |
| 68 | static AnalysisKey Key; |
| 69 | |
| 70 | public: |
| 71 | typedef ObjCARCAAResult Result; |
| 72 | |
| 73 | ObjCARCAAResult run(Function &F, FunctionAnalysisManager &AM); |
| 74 | }; |
| 75 | |
| 76 | } // namespace objcarc |
| 77 | } // namespace llvm |
| 78 | |
| 79 | #endif |
| 80 | |