Revert r354244 "[DAGCombiner] Eliminate dead stores to stack."
[llvm-complete.git] / lib / Target / AMDGPU / AMDGPUAliasAnalysis.h
blob0e01a4698af3694e027e1e6ad36b73c4bb3d6c0d
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 //===----------------------------------------------------------------------===//
12 #ifndef LLVM_LIB_TARGET_AMDGPU_AMDGPUALIASANALYSIS_H
13 #define LLVM_LIB_TARGET_AMDGPU_AMDGPUALIASANALYSIS_H
15 #include "AMDGPU.h"
16 #include "llvm/ADT/Triple.h"
17 #include "llvm/Analysis/AliasAnalysis.h"
18 #include "llvm/IR/Function.h"
19 #include "llvm/IR/Module.h"
20 #include "llvm/Pass.h"
21 #include <algorithm>
22 #include <memory>
24 namespace llvm {
26 class DataLayout;
27 class MDNode;
28 class MemoryLocation;
30 /// A simple AA result that uses TBAA metadata to answer queries.
31 class AMDGPUAAResult : public AAResultBase<AMDGPUAAResult> {
32 friend AAResultBase<AMDGPUAAResult>;
34 const DataLayout &DL;
36 public:
37 explicit AMDGPUAAResult(const DataLayout &DL, Triple T) : AAResultBase(),
38 DL(DL) {}
39 AMDGPUAAResult(AMDGPUAAResult &&Arg)
40 : AAResultBase(std::move(Arg)), DL(Arg.DL) {}
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; }
47 AliasResult alias(const MemoryLocation &LocA, const MemoryLocation &LocB);
48 bool pointsToConstantMemory(const MemoryLocation &Loc, bool OrLocal);
50 private:
51 bool Aliases(const MDNode *A, const MDNode *B) const;
52 bool PathAliases(const MDNode *A, const MDNode *B) const;
55 /// Analysis pass providing a never-invalidated alias analysis result.
56 class AMDGPUAA : public AnalysisInfoMixin<AMDGPUAA> {
57 friend AnalysisInfoMixin<AMDGPUAA>;
59 static char PassID;
61 public:
62 using Result = AMDGPUAAResult;
64 AMDGPUAAResult run(Function &F, AnalysisManager<Function> &AM) {
65 return AMDGPUAAResult(F.getParent()->getDataLayout(),
66 Triple(F.getParent()->getTargetTriple()));
70 /// Legacy wrapper pass to provide the AMDGPUAAResult object.
71 class AMDGPUAAWrapperPass : public ImmutablePass {
72 std::unique_ptr<AMDGPUAAResult> Result;
74 public:
75 static char ID;
77 AMDGPUAAWrapperPass() : ImmutablePass(ID) {
78 initializeAMDGPUAAWrapperPassPass(*PassRegistry::getPassRegistry());
81 AMDGPUAAResult &getResult() { return *Result; }
82 const AMDGPUAAResult &getResult() const { return *Result; }
84 bool doInitialization(Module &M) override {
85 Result.reset(new AMDGPUAAResult(M.getDataLayout(),
86 Triple(M.getTargetTriple())));
87 return false;
90 bool doFinalization(Module &M) override {
91 Result.reset();
92 return false;
95 void getAnalysisUsage(AnalysisUsage &AU) const override;
98 // Wrapper around ExternalAAWrapperPass so that the default constructor gets the
99 // callback.
100 class AMDGPUExternalAAWrapper : public ExternalAAWrapperPass {
101 public:
102 static char ID;
104 AMDGPUExternalAAWrapper() : ExternalAAWrapperPass(
105 [](Pass &P, Function &, AAResults &AAR) {
106 if (auto *WrapperPass = P.getAnalysisIfAvailable<AMDGPUAAWrapperPass>())
107 AAR.addAAResult(WrapperPass->getResult());
108 }) {}
111 } // end namespace llvm
113 #endif // LLVM_LIB_TARGET_AMDGPU_AMDGPUALIASANALYSIS_H