LLVM  9.0.0svn
AMDGPUAliasAnalysis.cpp
Go to the documentation of this file.
1 //===- AMDGPUAliasAnalysis ------------------------------------------------===//
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 //===----------------------------------------------------------------------===//
11 
12 #include "AMDGPUAliasAnalysis.h"
13 #include "AMDGPU.h"
14 #include "llvm/ADT/Triple.h"
18 #include "llvm/IR/Argument.h"
19 #include "llvm/IR/Attributes.h"
20 #include "llvm/IR/CallingConv.h"
21 #include "llvm/IR/Function.h"
22 #include "llvm/IR/GlobalVariable.h"
23 #include "llvm/IR/Type.h"
24 #include "llvm/IR/Value.h"
25 #include "llvm/Pass.h"
26 #include "llvm/Support/Casting.h"
28 #include <cassert>
29 
30 using namespace llvm;
31 
32 #define DEBUG_TYPE "amdgpu-aa"
33 
34 // Register this pass...
37 
39  "AMDGPU Address space based Alias Analysis", false, true)
40 
42  "AMDGPU Address space based Alias Analysis Wrapper", false, true)
43 
45  return new AMDGPUAAWrapperPass();
46 }
47 
49  return new AMDGPUExternalAAWrapper();
50 }
51 
53  AU.setPreservesAll();
54 }
55 
56 // These arrays are indexed by address space value enum elements 0 ... to 6
57 static const AliasResult ASAliasRules[7][7] = {
58  /* Flat Global Region Group Constant Private Constant 32-bit */
59  /* Flat */ {MayAlias, MayAlias, MayAlias, MayAlias, MayAlias, MayAlias, MayAlias},
60  /* Global */ {MayAlias, MayAlias, NoAlias , NoAlias , MayAlias, NoAlias , MayAlias},
61  /* Region */ {MayAlias, NoAlias , NoAlias , NoAlias, MayAlias, NoAlias , MayAlias},
62  /* Group */ {MayAlias, NoAlias , NoAlias , MayAlias, NoAlias , NoAlias , NoAlias},
63  /* Constant */ {MayAlias, MayAlias, MayAlias, NoAlias , NoAlias, NoAlias , MayAlias},
64  /* Private */ {MayAlias, NoAlias , NoAlias , NoAlias , NoAlias , MayAlias, NoAlias},
65  /* Constant 32-bit */ {MayAlias, MayAlias, MayAlias, NoAlias , MayAlias, NoAlias , NoAlias}
66 };
67 
68 static AliasResult getAliasResult(unsigned AS1, unsigned AS2) {
69  static_assert(AMDGPUAS::MAX_AMDGPU_ADDRESS <= 6, "Addr space out of range");
70 
72  return MayAlias;
73 
74  return ASAliasRules[AS1][AS2];
75 }
76 
78  const MemoryLocation &LocB) {
79  unsigned asA = LocA.Ptr->getType()->getPointerAddressSpace();
80  unsigned asB = LocB.Ptr->getType()->getPointerAddressSpace();
81 
82  AliasResult Result = getAliasResult(asA, asB);
83  if (Result == NoAlias)
84  return Result;
85 
86  // Forward the query to the next alias analysis.
87  return AAResultBase::alias(LocA, LocB);
88 }
89 
91  bool OrLocal) {
92  const Value *Base = GetUnderlyingObject(Loc.Ptr, DL);
93  unsigned AS = Base->getType()->getPointerAddressSpace();
94  if (AS == AMDGPUAS::CONSTANT_ADDRESS ||
96  return true;
97  }
98 
99  if (const GlobalVariable *GV = dyn_cast<GlobalVariable>(Base)) {
100  if (GV->isConstant())
101  return true;
102  } else if (const Argument *Arg = dyn_cast<Argument>(Base)) {
103  const Function *F = Arg->getParent();
104 
105  // Only assume constant memory for arguments on kernels.
106  switch (F->getCallingConv()) {
107  default:
108  return AAResultBase::pointsToConstantMemory(Loc, OrLocal);
118  break;
119  }
120 
121  unsigned ArgNo = Arg->getArgNo();
122  /* On an argument, ReadOnly attribute indicates that the function does
123  not write through this pointer argument, even though it may write
124  to the memory that the pointer points to.
125  On an argument, ReadNone attribute indicates that the function does
126  not dereference that pointer argument, even though it may read or write
127  the memory that the pointer points to if accessed through other pointers.
128  */
129  if (F->hasParamAttribute(ArgNo, Attribute::NoAlias) &&
130  (F->hasParamAttribute(ArgNo, Attribute::ReadNone) ||
131  F->hasParamAttribute(ArgNo, Attribute::ReadOnly))) {
132  return true;
133  }
134  }
135  return AAResultBase::pointsToConstantMemory(Loc, OrLocal);
136 }
This class represents an incoming formal argument to a Function.
Definition: Argument.h:29
This class represents lattice values for constants.
Definition: AllocatorList.h:23
Calling convention for AMDGPU code object kernels.
Definition: CallingConv.h:200
bool pointsToConstantMemory(const MemoryLocation &Loc, bool OrLocal)
The two locations do not alias at all.
Definition: AliasAnalysis.h:83
Calling convention used for Mesa/AMDPAL pixel shaders.
Definition: CallingConv.h:194
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - This function should be overriden by passes that need analysis information to do t...
Address space for 32-bit constant memory.
Definition: AMDGPU.h:262
F(f)
unsigned getPointerAddressSpace() const
Get the address space of this pointer or pointer vector type.
Definition: DerivedTypes.h:534
block Block Frequency true
Calling convention used for Mesa/AMDPAL hull shaders (= tessellation control shaders).
Definition: CallingConv.h:207
amdgpu aa AMDGPU Address space based Alias Analysis Wrapper
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:397
AliasResult alias(const MemoryLocation &LocA, const MemoryLocation &LocB)
Type * getType() const
All values are typed, get the type of this value.
Definition: Value.h:244
AliasResult alias(const MemoryLocation &LocA, const MemoryLocation &LocB)
AliasResult
The possible results of an alias query.
Definition: AliasAnalysis.h:77
static AliasResult getAliasResult(unsigned AS1, unsigned AS2)
Calling convention used for AMDPAL vertex shader if tessellation is in use.
Definition: CallingConv.h:215
Represent the analysis usage information of a pass.
Legacy wrapper pass to provide the AMDGPUAAResult object.
amdgpu Simplify well known AMD library false FunctionCallee Value * Arg
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...
SPIR_KERNEL - Calling convention for SPIR kernel functions.
Definition: CallingConv.h:136
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:85
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:255
Address space for constant memory (VTX2)
Definition: AMDGPU.h:258
CallingConv::ID getCallingConv() const
getCallingConv()/setCallingConv(CC) - These method get and set the calling convention of this functio...
Definition: Function.h:212
Calling convention used for Mesa vertex shaders, or AMDPAL last shader stage before rasterization (ve...
Definition: CallingConv.h:188
ImmutablePass * createAMDGPUAAWrapperPass()
Calling convention used for Mesa/AMDPAL compute shaders.
Definition: CallingConv.h:197
void setPreservesAll()
Set by analyses that do not transform their input at all.
Calling convention used for AMDPAL shader stage before geometry shader if geometry is in use...
Definition: CallingConv.h:220
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.
ImmutablePass * createAMDGPUExternalAAWrapperPass()
static const AliasResult ASAliasRules[7][7]
LLVM Value Representation.
Definition: Value.h:72
bool pointsToConstantMemory(const MemoryLocation &Loc, bool OrLocal)
amdgpu aa wrapper
Calling convention used for Mesa/AMDPAL geometry shaders.
Definition: CallingConv.h:191