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