Line data Source code
1 : //===- AMDGPUAliasAnalysis --------------------------------------*- C++ -*-===//
2 : //
3 : // The LLVM Compiler Infrastructure
4 : //
5 : // This file is distributed under the University of Illinois Open Source
6 : // License. See LICENSE.TXT for details.
7 : //
8 : //===----------------------------------------------------------------------===//
9 : /// \file
10 : /// This is the AMGPU address space based alias analysis pass.
11 : //===----------------------------------------------------------------------===//
12 :
13 : #ifndef LLVM_LIB_TARGET_AMDGPU_AMDGPUALIASANALYSIS_H
14 : #define LLVM_LIB_TARGET_AMDGPU_AMDGPUALIASANALYSIS_H
15 :
16 : #include "AMDGPU.h"
17 : #include "llvm/ADT/Triple.h"
18 : #include "llvm/Analysis/AliasAnalysis.h"
19 : #include "llvm/IR/Function.h"
20 : #include "llvm/IR/Module.h"
21 : #include "llvm/Pass.h"
22 : #include <algorithm>
23 : #include <memory>
24 :
25 : namespace llvm {
26 :
27 : class DataLayout;
28 : class MDNode;
29 : class MemoryLocation;
30 :
31 : /// A simple AA result that uses TBAA metadata to answer queries.
32 : class AMDGPUAAResult : public AAResultBase<AMDGPUAAResult> {
33 : friend AAResultBase<AMDGPUAAResult>;
34 :
35 : const DataLayout &DL;
36 :
37 : public:
38 2315 : explicit AMDGPUAAResult(const DataLayout &DL, Triple T) : AAResultBase(),
39 2315 : DL(DL) {}
40 : AMDGPUAAResult(AMDGPUAAResult &&Arg)
41 : : AAResultBase(std::move(Arg)), DL(Arg.DL) {}
42 :
43 : /// Handle invalidation events from the new pass manager.
44 : ///
45 : /// By definition, this result is stateless and so remains valid.
46 : bool invalidate(Function &, const PreservedAnalyses &) { return false; }
47 :
48 : AliasResult alias(const MemoryLocation &LocA, const MemoryLocation &LocB);
49 : bool pointsToConstantMemory(const MemoryLocation &Loc, bool OrLocal);
50 :
51 : private:
52 : bool Aliases(const MDNode *A, const MDNode *B) const;
53 : bool PathAliases(const MDNode *A, const MDNode *B) const;
54 : };
55 :
56 : /// Analysis pass providing a never-invalidated alias analysis result.
57 : class AMDGPUAA : public AnalysisInfoMixin<AMDGPUAA> {
58 : friend AnalysisInfoMixin<AMDGPUAA>;
59 :
60 : static char PassID;
61 :
62 : public:
63 : using Result = AMDGPUAAResult;
64 :
65 : AMDGPUAAResult run(Function &F, AnalysisManager<Function> &AM) {
66 : return AMDGPUAAResult(F.getParent()->getDataLayout(),
67 : Triple(F.getParent()->getTargetTriple()));
68 : }
69 : };
70 :
71 : /// Legacy wrapper pass to provide the AMDGPUAAResult object.
72 : class AMDGPUAAWrapperPass : public ImmutablePass {
73 : std::unique_ptr<AMDGPUAAResult> Result;
74 :
75 : public:
76 : static char ID;
77 :
78 4666 : AMDGPUAAWrapperPass() : ImmutablePass(ID) {
79 2333 : initializeAMDGPUAAWrapperPassPass(*PassRegistry::getPassRegistry());
80 2333 : }
81 :
82 : AMDGPUAAResult &getResult() { return *Result; }
83 : const AMDGPUAAResult &getResult() const { return *Result; }
84 :
85 2315 : bool doInitialization(Module &M) override {
86 2315 : Result.reset(new AMDGPUAAResult(M.getDataLayout(),
87 2315 : Triple(M.getTargetTriple())));
88 2315 : return false;
89 : }
90 :
91 2306 : bool doFinalization(Module &M) override {
92 : Result.reset();
93 2306 : return false;
94 : }
95 :
96 : void getAnalysisUsage(AnalysisUsage &AU) const override;
97 : };
98 :
99 : } // end namespace llvm
100 :
101 : #endif // LLVM_LIB_TARGET_AMDGPU_AMDGPUALIASANALYSIS_H
|