LLVM  8.0.0svn
AMDGPUAliasAnalysis.cpp
Go to the documentation of this file.
1 //===- AMDGPUAliasAnalysis ------------------------------------------------===//
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 #include "AMDGPUAliasAnalysis.h"
14 #include "AMDGPU.h"
15 #include "llvm/ADT/Triple.h"
19 #include "llvm/IR/Argument.h"
20 #include "llvm/IR/Attributes.h"
21 #include "llvm/IR/CallingConv.h"
22 #include "llvm/IR/Function.h"
23 #include "llvm/IR/GlobalVariable.h"
24 #include "llvm/IR/Type.h"
25 #include "llvm/IR/Value.h"
26 #include "llvm/Pass.h"
27 #include "llvm/Support/Casting.h"
29 #include <cassert>
30 
31 using namespace llvm;
32 
33 #define DEBUG_TYPE "amdgpu-aa"
34 
35 // Register this pass...
37 
39  "AMDGPU Address space based Alias Analysis", false, true)
40 
42  return new AMDGPUAAWrapperPass();
43 }
44 
46  AU.setPreservesAll();
47 }
48 
49 // These arrays are indexed by address space value enum elements 0 ... to 6
50 static const AliasResult ASAliasRules[7][7] = {
51  /* Flat Global Region Group Constant Private Constant 32-bit */
52  /* Flat */ {MayAlias, MayAlias, MayAlias, MayAlias, MayAlias, MayAlias, MayAlias},
53  /* Global */ {MayAlias, MayAlias, NoAlias , NoAlias , MayAlias, NoAlias , MayAlias},
54  /* Region */ {MayAlias, NoAlias , NoAlias , NoAlias, MayAlias, NoAlias , MayAlias},
55  /* Group */ {MayAlias, NoAlias , NoAlias , MayAlias, NoAlias , NoAlias , NoAlias},
56  /* Constant */ {MayAlias, MayAlias, MayAlias, NoAlias , NoAlias, NoAlias , MayAlias},
57  /* Private */ {MayAlias, NoAlias , NoAlias , NoAlias , NoAlias , MayAlias, NoAlias},
58  /* Constant 32-bit */ {MayAlias, MayAlias, MayAlias, NoAlias , MayAlias, NoAlias , NoAlias}
59 };
60 
61 static AliasResult getAliasResult(unsigned AS1, unsigned AS2) {
62  static_assert(AMDGPUAS::MAX_AMDGPU_ADDRESS <= 6, "Addr space out of range");
63 
65  return MayAlias;
66 
67  return ASAliasRules[AS1][AS2];
68 }
69 
71  const MemoryLocation &LocB) {
72  unsigned asA = LocA.Ptr->getType()->getPointerAddressSpace();
73  unsigned asB = LocB.Ptr->getType()->getPointerAddressSpace();
74 
75  AliasResult Result = getAliasResult(asA, asB);
76  if (Result == NoAlias)
77  return Result;
78 
79  // Forward the query to the next alias analysis.
80  return AAResultBase::alias(LocA, LocB);
81 }
82 
84  bool OrLocal) {
85  const Value *Base = GetUnderlyingObject(Loc.Ptr, DL);
86  unsigned AS = Base->getType()->getPointerAddressSpace();
87  if (AS == AMDGPUAS::CONSTANT_ADDRESS ||
89  return true;
90  }
91 
92  if (const GlobalVariable *GV = dyn_cast<GlobalVariable>(Base)) {
93  if (GV->isConstant())
94  return true;
95  } else if (const Argument *Arg = dyn_cast<Argument>(Base)) {
96  const Function *F = Arg->getParent();
97 
98  // Only assume constant memory for arguments on kernels.
99  switch (F->getCallingConv()) {
100  default:
101  return AAResultBase::pointsToConstantMemory(Loc, OrLocal);
111  break;
112  }
113 
114  unsigned ArgNo = Arg->getArgNo();
115  /* On an argument, ReadOnly attribute indicates that the function does
116  not write through this pointer argument, even though it may write
117  to the memory that the pointer points to.
118  On an argument, ReadNone attribute indicates that the function does
119  not dereference that pointer argument, even though it may read or write
120  the memory that the pointer points to if accessed through other pointers.
121  */
122  if (F->hasParamAttribute(ArgNo, Attribute::NoAlias) &&
123  (F->hasParamAttribute(ArgNo, Attribute::ReadNone) ||
124  F->hasParamAttribute(ArgNo, Attribute::ReadOnly))) {
125  return true;
126  }
127  }
128  return AAResultBase::pointsToConstantMemory(Loc, OrLocal);
129 }
This class represents an incoming formal argument to a Function.
Definition: Argument.h:30
Compute iterated dominance frontiers using a linear time algorithm.
Definition: AllocatorList.h:24
bool pointsToConstantMemory(const MemoryLocation &Loc, bool OrLocal)
The two locations do not alias at all.
Definition: AliasAnalysis.h:85
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - This function should be overriden by passes that need analysis information to do t...
F(f)
unsigned getPointerAddressSpace() const
Get the address space of this pointer or pointer vector type.
Definition: DerivedTypes.h:503
Calling convention used for Mesa/AMDPAL pixel shaders.
Definition: CallingConv.h:195
This file contains the simple types necessary to represent the attributes associated with functions a...
bool hasParamAttribute(unsigned ArgNo, Attribute::AttrKind Kind) const
check if an attributes is in the list of attributes.
Definition: Function.h:398
AliasResult alias(const MemoryLocation &LocA, const MemoryLocation &LocB)
Type * getType() const
All values are typed, get the type of this value.
Definition: Value.h:245
Calling convention used for Mesa/AMDPAL compute shaders.
Definition: CallingConv.h:198
Calling convention used for Mesa/AMDPAL hull shaders (= tessellation control shaders).
Definition: CallingConv.h:208
AliasResult alias(const MemoryLocation &LocA, const MemoryLocation &LocB)
Calling convention used for Mesa/AMDPAL geometry shaders.
Definition: CallingConv.h:192
AliasResult
The possible results of an alias query.
Definition: AliasAnalysis.h:79
static AliasResult getAliasResult(unsigned AS1, unsigned AS2)
Represent the analysis usage information of a pass.
SPIR_KERNEL - Calling convention for SPIR kernel functions.
Definition: CallingConv.h:137
Legacy wrapper pass to provide the AMDGPUAAResult object.
Value * GetUnderlyingObject(Value *V, const DataLayout &DL, unsigned MaxLookup=6)
This method strips off any GEP address adjustments and pointer casts from the specified value...
This is the AMGPU address space based alias analysis pass.
The two locations may or may not alias. This is the least precise result.
Definition: AliasAnalysis.h:87
const Value * Ptr
The address of the start of the location.
Representation for a specific memory location.
Calling convention used for AMDPAL vertex shader if tessellation is in use.
Definition: CallingConv.h:216
ImmutablePass class - This class is used to provide information that does not need to be run...
Definition: Pass.h:256
CallingConv::ID getCallingConv() const
getCallingConv()/setCallingConv(CC) - These method get and set the calling convention of this functio...
Definition: Function.h:213
ImmutablePass * createAMDGPUAAWrapperPass()
Address space for 32-bit constant memory.
Definition: AMDGPU.h:241
void setPreservesAll()
Set by analyses that do not transform their input at all.
Calling convention used for Mesa vertex shaders, or AMDPAL last shader stage before rasterization (ve...
Definition: CallingConv.h:189
amdgpu Simplify well known AMD library false Value Value * Arg
This file provides utility analysis objects describing memory locations.
Calling convention used for AMDPAL shader stage before geometry shader if geometry is in use...
Definition: CallingConv.h:221
Calling convention for AMDGPU code object kernels.
Definition: CallingConv.h:201
INITIALIZE_PASS(AMDGPUAAWrapperPass, "amdgpu-aa", "AMDGPU Address space based Alias Analysis", false, true) ImmutablePass *llvm
static const AliasResult ASAliasRules[7][7]
LLVM Value Representation.
Definition: Value.h:73
bool pointsToConstantMemory(const MemoryLocation &Loc, bool OrLocal)
Address space for constant memory (VTX2)
Definition: AMDGPU.h:237