LLVM 20.0.0git
NVPTXAliasAnalysis.cpp
Go to the documentation of this file.
1//===--------------------- NVPTXAliasAnalysis.cpp--------------------------===//
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 NVPTX address space based alias analysis pass.
10//===----------------------------------------------------------------------===//
11
12#include "NVPTXAliasAnalysis.h"
14#include "NVPTX.h"
18
19using namespace llvm;
20
21#define DEBUG_TYPE "NVPTX-aa"
22
24 "nvptx-traverse-address-aliasing-limit", cl::Hidden,
25 cl::desc("Depth limit for finding address space through traversal"),
26 cl::init(6));
27
28AnalysisKey NVPTXAA::Key;
29
32
34 "NVPTX Address space based Alias Analysis", false, true)
35
37 "NVPTX Address space based Alias Analysis Wrapper", false, true)
38
40 return new NVPTXAAWrapperPass();
41}
42
44 return new NVPTXExternalAAWrapper();
45}
46
49}
50
52 AU.setPreservesAll();
53}
54
55static unsigned getAddressSpace(const Value *V, unsigned MaxLookup) {
56 // Find the first non-generic address space traversing the UD chain.
57 // It is undefined behaviour if a pointer belongs to more than one
58 // non-overlapping address spaces along a valid execution path.
59 auto GetAS = [](const Value *V) -> unsigned {
60 if (const auto *PTy = dyn_cast<PointerType>(V->getType()))
61 return PTy->getAddressSpace();
63 };
64 while (MaxLookup-- && GetAS(V) == ADDRESS_SPACE_GENERIC) {
65 const Value *NewV = getUnderlyingObject(V, 1);
66 if (NewV == V)
67 break;
68 V = NewV;
69 }
70 return GetAS(V);
71}
72
73static AliasResult::Kind getAliasResult(unsigned AS1, unsigned AS2) {
74 if ((AS1 == ADDRESS_SPACE_GENERIC) || (AS2 == ADDRESS_SPACE_GENERIC))
76
77 // PTX s6.4.1.1. Generic Addressing:
78 // A generic address maps to global memory unless it falls within
79 // the window for const, local, or shared memory. The Kernel
80 // Function Parameters (.param) window is contained within the
81 // .global window.
82 //
83 // Therefore a global pointer may alias with a param pointer on some
84 // GPUs via addrspacecast(param->generic->global) when cvta.param
85 // instruction is used (PTX 7.7+ and SM_70+).
86 //
87 // TODO: cvta.param is not yet supported. We need to change aliasing
88 // rules once it is added.
89
90 return (AS1 == AS2 ? AliasResult::MayAlias : AliasResult::NoAlias);
91}
92
94 const MemoryLocation &Loc2, AAQueryInfo &AAQI,
95 const Instruction *) {
98
99 return getAliasResult(AS1, AS2);
100}
101
102// TODO: .param address space may be writable in presence of cvta.param, but
103// this instruction is currently not supported. NVPTXLowerArgs also does not
104// allow any writes to .param pointers.
105static bool isConstOrParam(unsigned AS) {
106 return AS == AddressSpace::ADDRESS_SPACE_CONST ||
107 AS == AddressSpace::ADDRESS_SPACE_PARAM;
108}
109
111 AAQueryInfo &AAQI,
112 bool IgnoreLocals) {
115
116 return ModRefInfo::ModRef;
117}
basic Basic Alias true
block Block Frequency Analysis
static cl::opt< unsigned > TraverseAddressSpacesLimit("nvptx-traverse-address-aliasing-limit", cl::Hidden, cl::desc("Depth limit for finding address space through traversal"), cl::init(6))
nvptx aa NVPTX Address space based Alias Analysis Wrapper
static AliasResult::Kind getAliasResult(unsigned AS1, unsigned AS2)
nvptx aa wrapper
static bool isConstOrParam(unsigned AS)
static unsigned getAddressSpace(const Value *V, unsigned MaxLookup)
This is the NVPTX address space based alias analysis pass.
#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.
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.
ImmutablePass class - This class is used to provide information that does not need to be run.
Definition: Pass.h:281
Representation for a specific memory location.
const Value * Ptr
The address of the start of the location.
AliasResult alias(const MemoryLocation &LocA, const MemoryLocation &LocB, AAQueryInfo &AAQI, const Instruction *CtxI=nullptr)
ModRefInfo getModRefInfoMask(const MemoryLocation &Loc, AAQueryInfo &AAQI, bool IgnoreLocals)
Legacy wrapper pass to provide the NVPTXAAResult object.
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - This function should be overriden by passes that need analysis information to do t...
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
LLVM Value Representation.
Definition: Value.h:74
TargetPassConfig.
initializer< Ty > init(const Ty &Val)
Definition: CommandLine.h:443
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
const Value * getUnderlyingObject(const Value *V, unsigned MaxLookup=6)
This method strips off any GEP address adjustments, pointer casts or llvm.threadlocal....
ImmutablePass * createNVPTXExternalAAWrapperPass()
void initializeNVPTXAAWrapperPassPass(PassRegistry &)
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 * createNVPTXAAWrapperPass()
A special type used by analysis passes to provide an address that identifies that particular analysis...
Definition: Analysis.h:28