1 | //===- AMDGPUAliasAnalysis --------------------------------------*- 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 is the AMGPU address space based alias analysis pass. |
10 | //===----------------------------------------------------------------------===// |
11 | |
12 | #ifndef LLVM_LIB_TARGET_AMDGPU_AMDGPUALIASANALYSIS_H |
13 | #define LLVM_LIB_TARGET_AMDGPU_AMDGPUALIASANALYSIS_H |
14 | |
15 | #include "llvm/Analysis/AliasAnalysis.h" |
16 | #include "llvm/IR/Module.h" |
17 | |
18 | namespace llvm { |
19 | |
20 | class DataLayout; |
21 | class MemoryLocation; |
22 | |
23 | /// A simple AA result that uses TBAA metadata to answer queries. |
24 | class AMDGPUAAResult : public AAResultBase { |
25 | const DataLayout &DL; |
26 | |
27 | public: |
28 | explicit AMDGPUAAResult(const DataLayout &DL) : DL(DL) {} |
29 | AMDGPUAAResult(AMDGPUAAResult &&Arg) |
30 | : AAResultBase(std::move(Arg)), DL(Arg.DL) {} |
31 | |
32 | /// Handle invalidation events from the new pass manager. |
33 | /// |
34 | /// By definition, this result is stateless and so remains valid. |
35 | bool invalidate(Function &, const PreservedAnalyses &, |
36 | FunctionAnalysisManager::Invalidator &Inv) { |
37 | return false; |
38 | } |
39 | |
40 | AliasResult alias(const MemoryLocation &LocA, const MemoryLocation &LocB, |
41 | AAQueryInfo &AAQI, const Instruction *CtxI); |
42 | ModRefInfo getModRefInfoMask(const MemoryLocation &Loc, AAQueryInfo &AAQI, |
43 | bool IgnoreLocals); |
44 | }; |
45 | |
46 | /// Analysis pass providing a never-invalidated alias analysis result. |
47 | class AMDGPUAA : public AnalysisInfoMixin<AMDGPUAA> { |
48 | friend AnalysisInfoMixin<AMDGPUAA>; |
49 | |
50 | static AnalysisKey Key; |
51 | |
52 | public: |
53 | using Result = AMDGPUAAResult; |
54 | |
55 | AMDGPUAAResult run(Function &F, AnalysisManager<Function> &AM) { |
56 | return AMDGPUAAResult(F.getDataLayout()); |
57 | } |
58 | }; |
59 | |
60 | /// Legacy wrapper pass to provide the AMDGPUAAResult object. |
61 | class AMDGPUAAWrapperPass : public ImmutablePass { |
62 | std::unique_ptr<AMDGPUAAResult> Result; |
63 | |
64 | public: |
65 | static char ID; |
66 | |
67 | AMDGPUAAWrapperPass(); |
68 | |
69 | AMDGPUAAResult &getResult() { return *Result; } |
70 | const AMDGPUAAResult &getResult() const { return *Result; } |
71 | |
72 | bool doInitialization(Module &M) override { |
73 | Result.reset(p: new AMDGPUAAResult(M.getDataLayout())); |
74 | return false; |
75 | } |
76 | |
77 | bool doFinalization(Module &M) override { |
78 | Result.reset(); |
79 | return false; |
80 | } |
81 | |
82 | void getAnalysisUsage(AnalysisUsage &AU) const override; |
83 | }; |
84 | |
85 | // Wrapper around ExternalAAWrapperPass so that the default constructor gets the |
86 | // callback. |
87 | class AMDGPUExternalAAWrapper : public ExternalAAWrapperPass { |
88 | public: |
89 | static char ID; |
90 | |
91 | AMDGPUExternalAAWrapper() : ExternalAAWrapperPass( |
92 | [](Pass &P, Function &, AAResults &AAR) { |
93 | if (auto *WrapperPass = P.getAnalysisIfAvailable<AMDGPUAAWrapperPass>()) |
94 | AAR.addAAResult(AAResult&: WrapperPass->getResult()); |
95 | }) {} |
96 | }; |
97 | |
98 | } // end namespace llvm |
99 | |
100 | #endif // LLVM_LIB_TARGET_AMDGPU_AMDGPUALIASANALYSIS_H |
101 | |