LLVM  8.0.1
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...
38 
40  "AMDGPU Address space based Alias Analysis", false, true)
41 
43  "AMDGPU Address space based Alias Analysis Wrapper", false, true)
44 
46  return new AMDGPUAAWrapperPass();
47 }
48 
50  return new AMDGPUExternalAAWrapper();
51 }
52 
54  AU.setPreservesAll();
55 }
56 
57 // These arrays are indexed by address space value enum elements 0 ... to 6
58 static const AliasResult ASAliasRules[7][7] = {
59  /* Flat Global Region Group Constant Private Constant 32-bit */
60  /* Flat */ {MayAlias, MayAlias, MayAlias, MayAlias, MayAlias, MayAlias, MayAlias},
61  /* Global */ {MayAlias, MayAlias, NoAlias , NoAlias , MayAlias, NoAlias , MayAlias},
62  /* Region */ {MayAlias, NoAlias , NoAlias , NoAlias, MayAlias, NoAlias , MayAlias},
63  /* Group */ {MayAlias, NoAlias , NoAlias , MayAlias, NoAlias , NoAlias , NoAlias},
64  /* Constant */ {MayAlias, MayAlias, MayAlias, NoAlias , NoAlias, NoAlias , MayAlias},
65  /* Private */ {MayAlias, NoAlias , NoAlias , NoAlias , NoAlias , MayAlias, NoAlias},
66  /* Constant 32-bit */ {MayAlias, MayAlias, MayAlias, NoAlias , MayAlias, NoAlias , NoAlias}
67 };
68 
69 static AliasResult getAliasResult(unsigned AS1, unsigned AS2) {
70  static_assert(AMDGPUAS::MAX_AMDGPU_ADDRESS <= 6, "Addr space out of range");
71 
73  return MayAlias;
74 
75  return ASAliasRules[AS1][AS2];
76 }
77 
79  const MemoryLocation &LocB) {
80  unsigned asA = LocA.Ptr->getType()->getPointerAddressSpace();
81  unsigned asB = LocB.Ptr->getType()->getPointerAddressSpace();
82 
83  AliasResult Result = getAliasResult(asA, asB);
84  if (Result == NoAlias)
85  return Result;
86 
87  // Forward the query to the next alias analysis.
88  return AAResultBase::alias(LocA, LocB);
89 }
90 
92  bool OrLocal) {
93  const Value *Base = GetUnderlyingObject(Loc.Ptr, DL);
94  unsigned AS = Base->getType()->getPointerAddressSpace();
95  if (AS == AMDGPUAS::CONSTANT_ADDRESS ||
97  return true;
98  }
99 
100  if (const GlobalVariable *GV = dyn_cast<GlobalVariable>(Base)) {
101  if (GV->isConstant())
102  return true;
103  } else if (const Argument *Arg = dyn_cast<Argument>(Base)) {
104  const Function *F = Arg->getParent();
105 
106  // Only assume constant memory for arguments on kernels.
107  switch (F->getCallingConv()) {
108  default:
109  return AAResultBase::pointsToConstantMemory(Loc, OrLocal);
119  break;
120  }
121 
122  unsigned ArgNo = Arg->getArgNo();
123  /* On an argument, ReadOnly attribute indicates that the function does
124  not write through this pointer argument, even though it may write
125  to the memory that the pointer points to.
126  On an argument, ReadNone attribute indicates that the function does
127  not dereference that pointer argument, even though it may read or write
128  the memory that the pointer points to if accessed through other pointers.
129  */
130  if (F->hasParamAttribute(ArgNo, Attribute::NoAlias) &&
133  return true;
134  }
135  }
136  return AAResultBase::pointsToConstantMemory(Loc, OrLocal);
137 }
This class represents an incoming formal argument to a Function.
Definition: Argument.h:30
This class represents lattice values for constants.
Definition: AllocatorList.h:24
bool pointsToConstantMemory(const MemoryLocation &Loc, bool OrLocal)
Address space for 32-bit constant memory.
Definition: AMDGPU.h:263
The two locations do not alias at all.
Definition: AliasAnalysis.h:84
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
block Block Frequency true
Calling convention used for Mesa/AMDPAL geometry shaders.
Definition: CallingConv.h:192
amdgpu aa AMDGPU Address space based Alias Analysis Wrapper
Address space for constant memory (VTX2)
Definition: AMDGPU.h:259
Calling convention used for Mesa/AMDPAL compute shaders.
Definition: CallingConv.h:198
SPIR_KERNEL - Calling convention for SPIR kernel functions.
Definition: CallingConv.h:137
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)
Calling convention used for AMDPAL shader stage before geometry shader if geometry is in use...
Definition: CallingConv.h:221
Type * getType() const
All values are typed, get the type of this value.
Definition: Value.h:245
AliasResult alias(const MemoryLocation &LocA, const MemoryLocation &LocB)
Calling convention used for Mesa vertex shaders, or AMDPAL last shader stage before rasterization (ve...
Definition: CallingConv.h:189
AliasResult
The possible results of an alias query.
Definition: AliasAnalysis.h:78
static AliasResult getAliasResult(unsigned AS1, unsigned AS2)
Represent the analysis usage information of a pass.
Legacy wrapper pass to provide the AMDGPUAAResult object.
Calling convention used for AMDPAL vertex shader if tessellation is in use.
Definition: CallingConv.h:216
Calling convention used for Mesa/AMDPAL pixel shaders.
Definition: CallingConv.h:195
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:86
const Value * Ptr
The address of the start of the location.
Representation for a specific memory location.
TargetPassConfig.
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()
void setPreservesAll()
Set by analyses that do not transform their input at all.
amdgpu Simplify well known AMD library false Value Value * Arg
INITIALIZE_PASS(AMDGPUAAWrapperPass, "amdgpu-aa", "AMDGPU Address space based Alias Analysis", false, true) INITIALIZE_PASS(AMDGPUExternalAAWrapper
block Block Frequency Analysis
This file provides utility analysis objects describing memory locations.
Calling convention used for Mesa/AMDPAL hull shaders (= tessellation control shaders).
Definition: CallingConv.h:208
ImmutablePass * createAMDGPUExternalAAWrapperPass()
static const AliasResult ASAliasRules[7][7]
LLVM Value Representation.
Definition: Value.h:73
bool pointsToConstantMemory(const MemoryLocation &Loc, bool OrLocal)
amdgpu aa wrapper
Calling convention for AMDGPU code object kernels.
Definition: CallingConv.h:201