Eugene Zelenko | d16eff8 | 2017-08-08 23:53:55 +0000 | [diff] [blame] | 1 | //===- AMDGPUAliasAnalysis --------------------------------------*- C++ -*-===// |
Stanislav Mekhanoshin | 8e45acf | 2017-03-17 23:56:58 +0000 | [diff] [blame] | 2 | // |
Chandler Carruth | 2946cd7 | 2019-01-19 08:50:56 +0000 | [diff] [blame] | 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 |
Stanislav Mekhanoshin | 8e45acf | 2017-03-17 23:56:58 +0000 | [diff] [blame] | 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | /// \file |
| 9 | /// This is the AMGPU address space based alias analysis pass. |
| 10 | //===----------------------------------------------------------------------===// |
| 11 | |
Eugene Zelenko | d16eff8 | 2017-08-08 23:53:55 +0000 | [diff] [blame] | 12 | #ifndef LLVM_LIB_TARGET_AMDGPU_AMDGPUALIASANALYSIS_H |
| 13 | #define LLVM_LIB_TARGET_AMDGPU_AMDGPUALIASANALYSIS_H |
Stanislav Mekhanoshin | 8e45acf | 2017-03-17 23:56:58 +0000 | [diff] [blame] | 14 | |
Yaxun Liu | 1a14bfa | 2017-03-27 14:04:01 +0000 | [diff] [blame] | 15 | #include "AMDGPU.h" |
Eugene Zelenko | d16eff8 | 2017-08-08 23:53:55 +0000 | [diff] [blame] | 16 | #include "llvm/ADT/Triple.h" |
Stanislav Mekhanoshin | 8e45acf | 2017-03-17 23:56:58 +0000 | [diff] [blame] | 17 | #include "llvm/Analysis/AliasAnalysis.h" |
| 18 | #include "llvm/IR/Function.h" |
| 19 | #include "llvm/IR/Module.h" |
| 20 | #include "llvm/Pass.h" |
Eugene Zelenko | d16eff8 | 2017-08-08 23:53:55 +0000 | [diff] [blame] | 21 | #include <algorithm> |
| 22 | #include <memory> |
Stanislav Mekhanoshin | 8e45acf | 2017-03-17 23:56:58 +0000 | [diff] [blame] | 23 | |
| 24 | namespace llvm { |
| 25 | |
Eugene Zelenko | d16eff8 | 2017-08-08 23:53:55 +0000 | [diff] [blame] | 26 | class DataLayout; |
| 27 | class MDNode; |
| 28 | class MemoryLocation; |
| 29 | |
Stanislav Mekhanoshin | 8e45acf | 2017-03-17 23:56:58 +0000 | [diff] [blame] | 30 | /// A simple AA result that uses TBAA metadata to answer queries. |
| 31 | class AMDGPUAAResult : public AAResultBase<AMDGPUAAResult> { |
| 32 | friend AAResultBase<AMDGPUAAResult>; |
| 33 | |
| 34 | const DataLayout &DL; |
| 35 | |
| 36 | public: |
Yaxun Liu | 1a14bfa | 2017-03-27 14:04:01 +0000 | [diff] [blame] | 37 | explicit AMDGPUAAResult(const DataLayout &DL, Triple T) : AAResultBase(), |
Matt Arsenault | 796b0e7 | 2018-09-11 04:00:49 +0000 | [diff] [blame] | 38 | DL(DL) {} |
Stanislav Mekhanoshin | 8e45acf | 2017-03-17 23:56:58 +0000 | [diff] [blame] | 39 | AMDGPUAAResult(AMDGPUAAResult &&Arg) |
Matt Arsenault | 796b0e7 | 2018-09-11 04:00:49 +0000 | [diff] [blame] | 40 | : AAResultBase(std::move(Arg)), DL(Arg.DL) {} |
Stanislav Mekhanoshin | 8e45acf | 2017-03-17 23:56:58 +0000 | [diff] [blame] | 41 | |
| 42 | /// Handle invalidation events from the new pass manager. |
| 43 | /// |
| 44 | /// By definition, this result is stateless and so remains valid. |
| 45 | bool invalidate(Function &, const PreservedAnalyses &) { return false; } |
| 46 | |
Alina Sbirlea | bfc779e | 2019-03-22 17:22:19 +0000 | [diff] [blame] | 47 | AliasResult alias(const MemoryLocation &LocA, const MemoryLocation &LocB, |
| 48 | AAQueryInfo &AAQI); |
| 49 | bool pointsToConstantMemory(const MemoryLocation &Loc, AAQueryInfo &AAQI, |
| 50 | bool OrLocal); |
Stanislav Mekhanoshin | 8e45acf | 2017-03-17 23:56:58 +0000 | [diff] [blame] | 51 | |
| 52 | private: |
| 53 | bool Aliases(const MDNode *A, const MDNode *B) const; |
| 54 | bool PathAliases(const MDNode *A, const MDNode *B) const; |
| 55 | }; |
| 56 | |
| 57 | /// Analysis pass providing a never-invalidated alias analysis result. |
| 58 | class AMDGPUAA : public AnalysisInfoMixin<AMDGPUAA> { |
| 59 | friend AnalysisInfoMixin<AMDGPUAA>; |
Eugene Zelenko | d16eff8 | 2017-08-08 23:53:55 +0000 | [diff] [blame] | 60 | |
Stanislav Mekhanoshin | 8e45acf | 2017-03-17 23:56:58 +0000 | [diff] [blame] | 61 | static char PassID; |
| 62 | |
| 63 | public: |
Eugene Zelenko | d16eff8 | 2017-08-08 23:53:55 +0000 | [diff] [blame] | 64 | using Result = AMDGPUAAResult; |
Stanislav Mekhanoshin | 8e45acf | 2017-03-17 23:56:58 +0000 | [diff] [blame] | 65 | |
| 66 | AMDGPUAAResult run(Function &F, AnalysisManager<Function> &AM) { |
Yaxun Liu | 1a14bfa | 2017-03-27 14:04:01 +0000 | [diff] [blame] | 67 | return AMDGPUAAResult(F.getParent()->getDataLayout(), |
| 68 | Triple(F.getParent()->getTargetTriple())); |
Stanislav Mekhanoshin | 8e45acf | 2017-03-17 23:56:58 +0000 | [diff] [blame] | 69 | } |
| 70 | }; |
| 71 | |
| 72 | /// Legacy wrapper pass to provide the AMDGPUAAResult object. |
| 73 | class AMDGPUAAWrapperPass : public ImmutablePass { |
| 74 | std::unique_ptr<AMDGPUAAResult> Result; |
| 75 | |
| 76 | public: |
| 77 | static char ID; |
| 78 | |
| 79 | AMDGPUAAWrapperPass() : ImmutablePass(ID) { |
| 80 | initializeAMDGPUAAWrapperPassPass(*PassRegistry::getPassRegistry()); |
| 81 | } |
| 82 | |
| 83 | AMDGPUAAResult &getResult() { return *Result; } |
| 84 | const AMDGPUAAResult &getResult() const { return *Result; } |
| 85 | |
| 86 | bool doInitialization(Module &M) override { |
Yaxun Liu | 1a14bfa | 2017-03-27 14:04:01 +0000 | [diff] [blame] | 87 | Result.reset(new AMDGPUAAResult(M.getDataLayout(), |
| 88 | Triple(M.getTargetTriple()))); |
Stanislav Mekhanoshin | 8e45acf | 2017-03-17 23:56:58 +0000 | [diff] [blame] | 89 | return false; |
| 90 | } |
Eugene Zelenko | d16eff8 | 2017-08-08 23:53:55 +0000 | [diff] [blame] | 91 | |
Stanislav Mekhanoshin | 8e45acf | 2017-03-17 23:56:58 +0000 | [diff] [blame] | 92 | bool doFinalization(Module &M) override { |
| 93 | Result.reset(); |
| 94 | return false; |
| 95 | } |
Eugene Zelenko | d16eff8 | 2017-08-08 23:53:55 +0000 | [diff] [blame] | 96 | |
Stanislav Mekhanoshin | 8e45acf | 2017-03-17 23:56:58 +0000 | [diff] [blame] | 97 | void getAnalysisUsage(AnalysisUsage &AU) const override; |
| 98 | }; |
| 99 | |
Matt Arsenault | 8ba740a | 2018-11-07 20:26:42 +0000 | [diff] [blame] | 100 | // Wrapper around ExternalAAWrapperPass so that the default constructor gets the |
| 101 | // callback. |
| 102 | class AMDGPUExternalAAWrapper : public ExternalAAWrapperPass { |
| 103 | public: |
| 104 | static char ID; |
| 105 | |
| 106 | AMDGPUExternalAAWrapper() : ExternalAAWrapperPass( |
| 107 | [](Pass &P, Function &, AAResults &AAR) { |
| 108 | if (auto *WrapperPass = P.getAnalysisIfAvailable<AMDGPUAAWrapperPass>()) |
| 109 | AAR.addAAResult(WrapperPass->getResult()); |
| 110 | }) {} |
| 111 | }; |
| 112 | |
Eugene Zelenko | d16eff8 | 2017-08-08 23:53:55 +0000 | [diff] [blame] | 113 | } // end namespace llvm |
| 114 | |
| 115 | #endif // LLVM_LIB_TARGET_AMDGPU_AMDGPUALIASANALYSIS_H |