Taints the non-acquire RMW's store address with the load part
[oota-llvm.git] / lib / Target / AMDGPU / AMDGPUAnnotateUniformValues.cpp
1 //===-- AMDGPUAnnotateUniformValues.cpp - ---------------------------------===//
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 //
10 /// \file
11 /// This pass adds amdgpu.uniform metadata to IR values so this information
12 /// can be used during instruction selection.
13 //
14 //===----------------------------------------------------------------------===//
15
16 #include "AMDGPU.h"
17 #include "AMDGPUIntrinsicInfo.h"
18 #include "llvm/Analysis/DivergenceAnalysis.h"
19 #include "llvm/IR/InstVisitor.h"
20 #include "llvm/IR/IRBuilder.h"
21 #include "llvm/Support/Debug.h"
22 #include "llvm/Support/raw_ostream.h"
23
24 #define DEBUG_TYPE "amdgpu-annotate-uniform"
25
26 using namespace llvm;
27
28 namespace {
29
30 class AMDGPUAnnotateUniformValues : public FunctionPass,
31                        public InstVisitor<AMDGPUAnnotateUniformValues> {
32   DivergenceAnalysis *DA;
33
34 public:
35   static char ID;
36   AMDGPUAnnotateUniformValues() :
37     FunctionPass(ID) { }
38   bool doInitialization(Module &M) override;
39   bool runOnFunction(Function &F) override;
40   const char *getPassName() const override { return "AMDGPU Annotate Uniform Values"; }
41   void getAnalysisUsage(AnalysisUsage &AU) const override {
42     AU.addRequired<DivergenceAnalysis>();
43     AU.setPreservesAll();
44  }
45
46   void visitLoadInst(LoadInst &I);
47
48 };
49
50 } // End anonymous namespace
51
52 INITIALIZE_PASS_BEGIN(AMDGPUAnnotateUniformValues, DEBUG_TYPE,
53                       "Add AMDGPU uniform metadata", false, false)
54 INITIALIZE_PASS_DEPENDENCY(DivergenceAnalysis)
55 INITIALIZE_PASS_END(AMDGPUAnnotateUniformValues, DEBUG_TYPE,
56                     "Add AMDGPU uniform metadata", false, false)
57
58 char AMDGPUAnnotateUniformValues::ID = 0;
59
60 void AMDGPUAnnotateUniformValues::visitLoadInst(LoadInst &I) {
61   Value *Ptr = I.getPointerOperand();
62   if (!DA->isUniform(Ptr))
63     return;
64
65   if (Instruction *PtrI = dyn_cast<Instruction>(Ptr))
66     PtrI->setMetadata("amdgpu.uniform", MDNode::get(I.getContext(), {}));
67
68 }
69
70 bool AMDGPUAnnotateUniformValues::doInitialization(Module &M) {
71   return false;
72 }
73
74 bool AMDGPUAnnotateUniformValues::runOnFunction(Function &F) {
75   DA = &getAnalysis<DivergenceAnalysis>();
76   visit(F);
77
78   return true;
79 }
80
81 FunctionPass *
82 llvm::createAMDGPUAnnotateUniformValues() {
83   return new AMDGPUAnnotateUniformValues();
84 }