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