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