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