LLVM 22.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
36
40
42
46
48 const MemoryLocation &LocB, AAQueryInfo &AAQI,
49 const Instruction *) {
50 unsigned asA = LocA.Ptr->getType()->getPointerAddressSpace();
51 unsigned asB = LocB.Ptr->getType()->getPointerAddressSpace();
52
53 if (!AMDGPU::addrspacesMayAlias(asA, asB))
55
56 // In general, FLAT (generic) pointers could be aliased to LOCAL or PRIVATE
57 // pointers. However, as LOCAL or PRIVATE pointers point to local objects, in
58 // certain cases, it's still viable to check whether a FLAT pointer won't
59 // alias to a LOCAL or PRIVATE pointer.
60 MemoryLocation A = LocA;
61 MemoryLocation B = LocB;
62 // Canonicalize the location order to simplify the following alias check.
63 if (asA != AMDGPUAS::FLAT_ADDRESS) {
64 std::swap(asA, asB);
65 std::swap(A, B);
66 }
67 if (asA == AMDGPUAS::FLAT_ADDRESS &&
69 const auto *ObjA =
70 getUnderlyingObject(A.Ptr->stripPointerCastsForAliasAnalysis());
71 if (const LoadInst *LI = dyn_cast<LoadInst>(ObjA)) {
72 // If a generic pointer is loaded from the constant address space, it
73 // could only be a GLOBAL or CONSTANT one as that address space is solely
74 // prepared on the host side, where only GLOBAL or CONSTANT variables are
75 // visible. Note that this even holds for regular functions.
76 if (LI->getPointerAddressSpace() == AMDGPUAS::CONSTANT_ADDRESS)
78 } else if (const Argument *Arg = dyn_cast<Argument>(ObjA)) {
79 const Function *F = Arg->getParent();
80 switch (F->getCallingConv()) {
82 // In the kernel function, kernel arguments won't alias to (local)
83 // variables in shared or private address space.
84 const auto *ObjB =
85 getUnderlyingObject(B.Ptr->stripPointerCastsForAliasAnalysis());
86 return ObjA != ObjB && isIdentifiedObject(ObjB) ? AliasResult::NoAlias
88 }
89 default:
90 // TODO: In the regular function, if that local variable in the
91 // location B is not captured, that argument pointer won't alias to it
92 // as well.
93 break;
94 }
95 }
96 }
97
99}
100
102 AAQueryInfo &AAQI,
103 bool IgnoreLocals) {
104 unsigned AS = Loc.Ptr->getType()->getPointerAddressSpace();
105 if (AS == AMDGPUAS::CONSTANT_ADDRESS ||
108
109 const Value *Base = getUnderlyingObject(Loc.Ptr);
110 AS = Base->getType()->getPointerAddressSpace();
111 if (AS == AMDGPUAS::CONSTANT_ADDRESS ||
114
115 return ModRefInfo::ModRef;
116}
This is the AMGPU address space based alias analysis pass.
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
#define F(x, y, z)
Definition MD5.cpp:55
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
Definition PassSupport.h:56
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.
@ MayAlias
The two locations may or may not alias.
@ NoAlias
The two locations do not alias at all.
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:32
ImmutablePass class - This class is used to provide information that does not need to be run.
Definition Pass.h:285
ImmutablePass(char &pid)
Definition Pass.h:287
An instruction for reading from memory.
Representation for a specific memory location.
const Value * Ptr
The address of the start of the location.
LLVM_ABI unsigned getPointerAddressSpace() const
Get the address space of this pointer or pointer vector type.
LLVM Value Representation.
Definition Value.h:75
Type * getType() const
All values are typed, get the type of this value.
Definition Value.h:256
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:574
@ AMDGPU_KERNEL
Used for AMDGPU code object kernels.
This is an optimization pass for GlobalISel generic memory operations.
ImmutablePass * createAMDGPUAAWrapperPass()
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:649
ModRefInfo
Flags indicating whether a memory access modifies or references memory.
Definition ModRef.h:28
@ ModRef
The access may reference and may modify the value stored in memory.
Definition ModRef.h:36
@ NoModRef
The access neither references nor modifies the value stored in memory.
Definition ModRef.h:30
ImmutablePass * createAMDGPUExternalAAWrapperPass()
LLVM_ABI const Value * getUnderlyingObject(const Value *V, unsigned MaxLookup=MaxLookupSearchDepth)
This method strips off any GEP address adjustments, pointer casts or llvm.threadlocal....
LLVM_ABI bool isIdentifiedObject(const Value *V)
Return true if this pointer refers to a distinct and identifiable object.
void swap(llvm::BitVector &LHS, llvm::BitVector &RHS)
Implement std::swap in terms of BitVector swap.
Definition BitVector.h:853
A special type used by analysis passes to provide an address that identifies that particular analysis...
Definition Analysis.h:29