LLVM  10.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 7
57 static const AliasResult ASAliasRules[8][8] = {
58  /* Flat Global Region Group Constant Private Constant 32-bit Buffer Fat Ptr */
59  /* Flat */ {MayAlias, MayAlias, NoAlias, MayAlias, MayAlias, MayAlias, MayAlias, MayAlias},
60  /* Global */ {MayAlias, MayAlias, NoAlias , NoAlias , MayAlias, NoAlias , MayAlias, MayAlias},
61  /* Region */ {NoAlias, NoAlias , MayAlias, NoAlias , NoAlias, NoAlias , NoAlias, NoAlias},
62  /* Group */ {MayAlias, NoAlias , NoAlias , MayAlias, NoAlias , NoAlias , NoAlias , NoAlias},
63  /* Constant */ {MayAlias, MayAlias, NoAlias, NoAlias , NoAlias , NoAlias , MayAlias, MayAlias},
64  /* Private */ {MayAlias, NoAlias , NoAlias , NoAlias , NoAlias , MayAlias, NoAlias , NoAlias},
65  /* Constant 32-bit */ {MayAlias, MayAlias, NoAlias, NoAlias , MayAlias, NoAlias , NoAlias , MayAlias},
66  /* Buffer Fat Ptr */ {MayAlias, MayAlias, NoAlias , NoAlias , MayAlias, NoAlias , MayAlias, MayAlias}
67 };
68 
69 static AliasResult getAliasResult(unsigned AS1, unsigned AS2) {
70  static_assert(AMDGPUAS::MAX_AMDGPU_ADDRESS <= 7, "Addr space out of range");
71 
73  return MayAlias;
74 
75  return ASAliasRules[AS1][AS2];
76 }
77 
79  const MemoryLocation &LocB,
80  AAQueryInfo &AAQI) {
81  unsigned asA = LocA.Ptr->getType()->getPointerAddressSpace();
82  unsigned asB = LocB.Ptr->getType()->getPointerAddressSpace();
83 
84  AliasResult Result = getAliasResult(asA, asB);
85  if (Result == NoAlias)
86  return Result;
87 
88  // Forward the query to the next alias analysis.
89  return AAResultBase::alias(LocA, LocB, AAQI);
90 }
91 
93  AAQueryInfo &AAQI, bool OrLocal) {
94  const Value *Base = GetUnderlyingObject(Loc.Ptr, DL);
95  unsigned AS = Base->getType()->getPointerAddressSpace();
96  if (AS == AMDGPUAS::CONSTANT_ADDRESS ||
98  return true;
99  }
100 
101  if (const GlobalVariable *GV = dyn_cast<GlobalVariable>(Base)) {
102  if (GV->isConstant())
103  return true;
104  } else if (const Argument *Arg = dyn_cast<Argument>(Base)) {
105  const Function *F = Arg->getParent();
106 
107  // Only assume constant memory for arguments on kernels.
108  switch (F->getCallingConv()) {
109  default:
110  return AAResultBase::pointsToConstantMemory(Loc, AAQI, OrLocal);
120  break;
121  }
122 
123  unsigned ArgNo = Arg->getArgNo();
124  /* On an argument, ReadOnly attribute indicates that the function does
125  not write through this pointer argument, even though it may write
126  to the memory that the pointer points to.
127  On an argument, ReadNone attribute indicates that the function does
128  not dereference that pointer argument, even though it may read or write
129  the memory that the pointer points to if accessed through other pointers.
130  */
131  if (F->hasParamAttribute(ArgNo, Attribute::NoAlias) &&
132  (F->hasParamAttribute(ArgNo, Attribute::ReadNone) ||
133  F->hasParamAttribute(ArgNo, Attribute::ReadOnly))) {
134  return true;
135  }
136  }
137  return AAResultBase::pointsToConstantMemory(Loc, AAQI, OrLocal);
138 }
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
This class stores info we want to provide to or retain within an alias query.
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:580
Calling convention used for Mesa/AMDPAL hull shaders (= tessellation control shaders).
Definition: CallingConv.h:207
block Block Frequency true
AliasResult alias(const MemoryLocation &LocA, const MemoryLocation &LocB, AAQueryInfo &AAQI)
Address space for constant memory (VTX2).
Definition: AMDGPU.h:273
amdgpu aa AMDGPU Address space based Alias Analysis Wrapper
bool pointsToConstantMemory(const MemoryLocation &Loc, AAQueryInfo &AAQI, bool OrLocal)
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:400
Calling convention used for Mesa/AMDPAL compute shaders.
Definition: CallingConv.h:197
Calling convention used for Mesa/AMDPAL geometry shaders.
Definition: CallingConv.h:191
Type * getType() const
All values are typed, get the type of this value.
Definition: Value.h:245
AliasResult
The possible results of an alias query.
Definition: AliasAnalysis.h:78
static AliasResult getAliasResult(unsigned AS1, unsigned AS2)
AliasResult alias(const MemoryLocation &LocA, const MemoryLocation &LocB, AAQueryInfo &AAQI)
bool pointsToConstantMemory(const MemoryLocation &Loc, AAQueryInfo &AAQI, bool OrLocal)
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...
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.
Calling convention used for Mesa/AMDPAL pixel shaders.
Definition: CallingConv.h:194
Address space for 32-bit constant memory.
Definition: AMDGPU.h:277
Calling convention for AMDGPU code object kernels.
Definition: CallingConv.h:200
TargetPassConfig.
ImmutablePass class - This class is used to provide information that does not need to be run...
Definition: Pass.h:255
CallingConv::ID getCallingConv() const
getCallingConv()/setCallingConv(CC) - These method get and set the calling convention of this functio...
Definition: Function.h:212
SPIR_KERNEL - Calling convention for SPIR kernel functions.
Definition: CallingConv.h:136
ImmutablePass * createAMDGPUAAWrapperPass()
static const AliasResult ASAliasRules[8][8]
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:188
Calling convention used for AMDPAL vertex shader if tessellation is in use.
Definition: CallingConv.h:215
INITIALIZE_PASS(AMDGPUAAWrapperPass, "amdgpu-aa", "AMDGPU Address space based Alias Analysis", false, true) INITIALIZE_PASS(AMDGPUExternalAAWrapper
This file provides utility analysis objects describing memory locations.
ImmutablePass * createAMDGPUExternalAAWrapperPass()
LLVM Value Representation.
Definition: Value.h:73
amdgpu aa wrapper
Calling convention used for AMDPAL shader stage before geometry shader if geometry is in use...
Definition: CallingConv.h:220