LLVM 20.0.0git
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"
16
17using namespace llvm;
18
19#define DEBUG_TYPE "amdgpu-aa"
20
21AnalysisKey AMDGPUAA::Key;
22
23// Register this pass...
26
28 "AMDGPU Address space based Alias Analysis", false, true)
29
31 "AMDGPU Address space based Alias Analysis Wrapper", false, true)
32
34 return new AMDGPUAAWrapperPass();
35}
36
38 return new AMDGPUExternalAAWrapper();
39}
40
43}
44
46 AU.setPreservesAll();
47}
48
50 const MemoryLocation &LocB, AAQueryInfo &AAQI,
51 const Instruction *) {
52 unsigned asA = LocA.Ptr->getType()->getPointerAddressSpace();
53 unsigned asB = LocB.Ptr->getType()->getPointerAddressSpace();
54
55 if (!AMDGPU::addrspacesMayAlias(asA, asB))
57
58 // In general, FLAT (generic) pointers could be aliased to LOCAL or PRIVATE
59 // pointers. However, as LOCAL or PRIVATE pointers point to local objects, in
60 // certain cases, it's still viable to check whether a FLAT pointer won't
61 // alias to a LOCAL or PRIVATE pointer.
62 MemoryLocation A = LocA;
63 MemoryLocation B = LocB;
64 // Canonicalize the location order to simplify the following alias check.
65 if (asA != AMDGPUAS::FLAT_ADDRESS) {
66 std::swap(asA, asB);
67 std::swap(A, B);
68 }
69 if (asA == AMDGPUAS::FLAT_ADDRESS &&
71 const auto *ObjA =
72 getUnderlyingObject(A.Ptr->stripPointerCastsForAliasAnalysis());
73 if (const LoadInst *LI = dyn_cast<LoadInst>(ObjA)) {
74 // If a generic pointer is loaded from the constant address space, it
75 // could only be a GLOBAL or CONSTANT one as that address space is solely
76 // prepared on the host side, where only GLOBAL or CONSTANT variables are
77 // visible. Note that this even holds for regular functions.
78 if (LI->getPointerAddressSpace() == AMDGPUAS::CONSTANT_ADDRESS)
80 } else if (const Argument *Arg = dyn_cast<Argument>(ObjA)) {
81 const Function *F = Arg->getParent();
82 switch (F->getCallingConv()) {
84 // In the kernel function, kernel arguments won't alias to (local)
85 // variables in shared or private address space.
87 default:
88 // TODO: In the regular function, if that local variable in the
89 // location B is not captured, that argument pointer won't alias to it
90 // as well.
91 break;
92 }
93 }
94 }
95
97}
98
100 AAQueryInfo &AAQI,
101 bool IgnoreLocals) {
102 unsigned AS = Loc.Ptr->getType()->getPointerAddressSpace();
103 if (AS == AMDGPUAS::CONSTANT_ADDRESS ||
106
107 const Value *Base = getUnderlyingObject(Loc.Ptr);
108 AS = Base->getType()->getPointerAddressSpace();
109 if (AS == AMDGPUAS::CONSTANT_ADDRESS ||
112
113 return ModRefInfo::ModRef;
114}
amdgpu aa AMDGPU Address space based Alias Analysis Wrapper
amdgpu aa wrapper
This is the AMGPU address space based alias analysis pass.
basic Basic Alias true
block Block Frequency Analysis
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
#define F(x, y, z)
Definition: MD5.cpp:55
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
Definition: PassSupport.h:38
This class stores info we want to provide to or retain within an alias query.
AliasResult alias(const MemoryLocation &LocA, const MemoryLocation &LocB, AAQueryInfo &AAQI, const Instruction *CtxI)
ModRefInfo getModRefInfoMask(const MemoryLocation &Loc, AAQueryInfo &AAQI, bool IgnoreLocals)
Legacy wrapper pass to provide the AMDGPUAAResult object.
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - This function should be overriden by passes that need analysis information to do t...
The possible results of an alias query.
Definition: AliasAnalysis.h:77
@ MayAlias
The two locations may or may not alias.
Definition: AliasAnalysis.h:98
@ NoAlias
The two locations do not alias at all.
Definition: AliasAnalysis.h:95
Represent the analysis usage information of a pass.
void setPreservesAll()
Set by analyses that do not transform their input at all.
This class represents an incoming formal argument to a Function.
Definition: Argument.h:31
ImmutablePass class - This class is used to provide information that does not need to be run.
Definition: Pass.h:281
An instruction for reading from memory.
Definition: Instructions.h:174
Representation for a specific memory location.
const Value * Ptr
The address of the start of the location.
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
unsigned getPointerAddressSpace() const
Get the address space of this pointer or pointer vector type.
LLVM Value Representation.
Definition: Value.h:74
Type * getType() const
All values are typed, get the type of this value.
Definition: Value.h:255
TargetPassConfig.
@ CONSTANT_ADDRESS_32BIT
Address space for 32-bit constant memory.
@ LOCAL_ADDRESS
Address space for local memory.
@ CONSTANT_ADDRESS
Address space for constant memory (VTX2).
@ FLAT_ADDRESS
Address space for flat memory.
@ PRIVATE_ADDRESS
Address space for private memory.
static bool addrspacesMayAlias(unsigned AS1, unsigned AS2)
Definition: AMDGPU.h:467
@ AMDGPU_KERNEL
Used for AMDGPU code object kernels.
Definition: CallingConv.h:200
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
ImmutablePass * createAMDGPUAAWrapperPass()
void initializeAMDGPUAAWrapperPassPass(PassRegistry &)
const Value * getUnderlyingObject(const Value *V, unsigned MaxLookup=6)
This method strips off any GEP address adjustments, pointer casts or llvm.threadlocal....
ModRefInfo
Flags indicating whether a memory access modifies or references memory.
Definition: ModRef.h:27
@ ModRef
The access may reference and may modify the value stored in memory.
@ NoModRef
The access neither references nor modifies the value stored in memory.
ImmutablePass * createAMDGPUExternalAAWrapperPass()
void swap(llvm::BitVector &LHS, llvm::BitVector &RHS)
Implement std::swap in terms of BitVector swap.
Definition: BitVector.h:860
A special type used by analysis passes to provide an address that identifies that particular analysis...
Definition: Analysis.h:28