LLVM  13.0.0git
ObjCARCAliasAnalysis.h
Go to the documentation of this file.
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 
26 #include "llvm/Pass.h"
27 
28 namespace llvm {
29 namespace objcarc {
30 
31 /// This is a simple alias analysis implementation that uses knowledge
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> {
39 
40  const DataLayout &DL;
41 
42 public:
43  explicit ObjCARCAAResult(const DataLayout &DL) : AAResultBase(), DL(DL) {}
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.
52  return false;
53  }
54 
55  AliasResult alias(const MemoryLocation &LocA, const MemoryLocation &LocB,
56  AAQueryInfo &AAQI);
57  bool pointsToConstantMemory(const MemoryLocation &Loc, AAQueryInfo &AAQI,
58  bool OrLocal);
59 
62 
64  ModRefInfo getModRefInfo(const CallBase *Call, const MemoryLocation &Loc,
65  AAQueryInfo &AAQI);
66 };
67 
68 /// Analysis pass providing a never-invalidated alias analysis result.
69 class ObjCARCAA : public AnalysisInfoMixin<ObjCARCAA> {
71  static AnalysisKey Key;
72 
73 public:
75 
77 };
78 
79 /// Legacy wrapper pass to provide the ObjCARCAAResult object.
81  std::unique_ptr<ObjCARCAAResult> Result;
82 
83 public:
84  static char ID;
85 
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
llvm::PreservedAnalyses
A set of analyses that are preserved following a run of a transformation pass.
Definition: PassManager.h:155
llvm
Definition: AllocatorList.h:23
llvm::DataLayout
A parsed version of the target data layout string in and methods for querying it.
Definition: DataLayout.h:112
llvm::ImmutablePass
ImmutablePass class - This class is used to provide information that does not need to be run.
Definition: Pass.h:269
llvm::objcarc::ObjCARCAAResult::ObjCARCAAResult
ObjCARCAAResult(ObjCARCAAResult &&Arg)
Definition: ObjCARCAliasAnalysis.h:44
llvm::Function
Definition: Function.h:61
Pass.h
llvm::objcarc::ObjCARCAAResult
This is a simple alias analysis implementation that uses knowledge of ARC constructs to answer querie...
Definition: ObjCARCAliasAnalysis.h:37
llvm::objcarc::ObjCARCAAWrapperPass::getResult
const ObjCARCAAResult & getResult() const
Definition: ObjCARCAliasAnalysis.h:89
llvm::objcarc::ObjCARCAAResult::alias
AliasResult alias(const MemoryLocation &LocA, const MemoryLocation &LocB, AAQueryInfo &AAQI)
Definition: ObjCARCAliasAnalysis.cpp:39
llvm::AliasResult
The possible results of an alias query.
Definition: AliasAnalysis.h:81
F
#define F(x, y, z)
Definition: MD5.cpp:56
AliasAnalysis.h
llvm::objcarc::ObjCARCAAWrapperPass::doInitialization
bool doInitialization(Module &M) override
doInitialization - Virtual method overridden by subclasses to do any necessary initialization before ...
Definition: ObjCARCAliasAnalysis.cpp:155
llvm::objcarc::ObjCARCAAResult::getModRefBehavior
FunctionModRefBehavior getModRefBehavior(const Function *F)
Definition: ObjCARCAliasAnalysis.cpp:97
llvm::objcarc::ObjCARCAAWrapperPass
Legacy wrapper pass to provide the ObjCARCAAResult object.
Definition: ObjCARCAliasAnalysis.h:80
Arg
amdgpu Simplify well known AMD library false FunctionCallee Value * Arg
Definition: AMDGPULibCalls.cpp:205
llvm::AAQueryInfo
This class stores info we want to provide to or retain within an alias query.
Definition: AliasAnalysis.h:414
llvm::AnalysisUsage
Represent the analysis usage information of a pass.
Definition: PassAnalysisSupport.h:47
llvm::AnalysisManager::Invalidator
API to communicate dependencies between analyses during invalidation.
Definition: PassManager.h:670
llvm::objcarc::ObjCARCAAResult::getModRefInfo
ModRefInfo getModRefInfo(const CallBase *Call, const MemoryLocation &Loc, AAQueryInfo &AAQI)
Definition: ObjCARCAliasAnalysis.cpp:111
llvm::objcarc::ObjCARCAAWrapperPass::getAnalysisUsage
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - This function should be overriden by passes that need analysis information to do t...
Definition: ObjCARCAliasAnalysis.cpp:165
llvm::objcarc::ObjCARCAA::Result
ObjCARCAAResult Result
Definition: ObjCARCAliasAnalysis.h:74
llvm::AnalysisKey
A special type used by analysis passes to provide an address that identifies that particular analysis...
Definition: PassManager.h:72
llvm::objcarc::ObjCARCAA
Analysis pass providing a never-invalidated alias analysis result.
Definition: ObjCARCAliasAnalysis.h:69
llvm::objcarc::ObjCARCAAWrapperPass::doFinalization
bool doFinalization(Module &M) override
doFinalization - Virtual method overriden by subclasses to do any necessary clean up after all passes...
Definition: ObjCARCAliasAnalysis.cpp:160
llvm::objcarc::ObjCARCAAWrapperPass::getResult
ObjCARCAAResult & getResult()
Definition: ObjCARCAliasAnalysis.h:88
llvm::objcarc::ObjCARCAAResult::ObjCARCAAResult
ObjCARCAAResult(const DataLayout &DL)
Definition: ObjCARCAliasAnalysis.h:43
llvm::ModRefInfo
ModRefInfo
Flags indicating whether a memory access modifies or references memory.
Definition: AliasAnalysis.h:148
llvm::objcarc::ObjCARCAAWrapperPass::ObjCARCAAWrapperPass
ObjCARCAAWrapperPass()
Definition: ObjCARCAliasAnalysis.cpp:151
llvm::move
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
Definition: STLExtras.h:1540
llvm::Module
A Module instance is used to store all the information related to an LLVM module.
Definition: Module.h:67
llvm::AnalysisInfoMixin
A CRTP mix-in that provides informational APIs needed for analysis passes.
Definition: PassManager.h:391
llvm::AAResultBase::getModRefBehavior
FunctionModRefBehavior getModRefBehavior(const CallBase *Call)
Definition: AliasAnalysis.h:1166
llvm::objcarc::ObjCARCAA::run
ObjCARCAAResult run(Function &F, FunctionAnalysisManager &AM)
Definition: ObjCARCAliasAnalysis.cpp:139
llvm::objcarc::ObjCARCAAResult::invalidate
bool invalidate(Function &, const PreservedAnalyses &, FunctionAnalysisManager::Invalidator &)
Handle invalidation events from the new pass manager.
Definition: ObjCARCAliasAnalysis.h:50
DL
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
Definition: AArch64SLSHardening.cpp:76
llvm::FunctionModRefBehavior
FunctionModRefBehavior
Summary of how a function affects memory in the program.
Definition: AliasAnalysis.h:262
llvm::AAResultBase::getModRefInfo
ModRefInfo getModRefInfo(const CallBase *Call, const MemoryLocation &Loc, AAQueryInfo &AAQI)
Definition: AliasAnalysis.h:1174
std
Definition: BitVector.h:838
llvm::objcarc::ObjCARCAAResult::pointsToConstantMemory
bool pointsToConstantMemory(const MemoryLocation &Loc, AAQueryInfo &AAQI, bool OrLocal)
Definition: ObjCARCAliasAnalysis.cpp:73
llvm::objcarc::ObjCARCAAWrapperPass::ID
static char ID
Definition: ObjCARCAliasAnalysis.h:84
llvm::CallBase
Base class for all callable instructions (InvokeInst and CallInst) Holds everything related to callin...
Definition: InstrTypes.h:1164
llvm::AnalysisManager
A container for analyses that lazily runs them and caches their results.
Definition: InstructionSimplify.h:44
llvm::AAResultBase
A CRTP-driven "mixin" base class to help implement the function alias analysis results concept.
Definition: AliasAnalysis.h:1064
llvm::MemoryLocation
Representation for a specific memory location.
Definition: MemoryLocation.h:209