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