LLVM 17.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"
16#include "llvm/IR/CallingConv.h"
18
19using namespace llvm;
20
21#define DEBUG_TYPE "NVPTX-aa"
22
23AnalysisKey NVPTXAA::Key;
24
27
29 "NVPTX Address space based Alias Analysis", false, true)
30
32 "NVPTX Address space based Alias Analysis Wrapper", false, true)
33
35 return new NVPTXAAWrapperPass();
36}
37
39 return new NVPTXExternalAAWrapper();
40}
41
44}
45
47 AU.setPreservesAll();
48}
49
50static AliasResult::Kind getAliasResult(unsigned AS1, unsigned AS2) {
51 if ((AS1 == ADDRESS_SPACE_GENERIC) || (AS2 == ADDRESS_SPACE_GENERIC))
53
54 // PTX s6.4.1.1. Generic Addressing:
55 // A generic address maps to global memory unless it falls within
56 // the window for const, local, or shared memory. The Kernel
57 // Function Parameters (.param) window is contained within the
58 // .global window.
59 //
60 // Therefore a global pointer may alias with a param pointer on some
61 // GPUs via addrspacecast(param->generic->global) when cvta.param
62 // instruction is used (PTX 7.7+ and SM_70+).
63 //
64 // TODO: cvta.param is not yet supported. We need to change aliasing
65 // rules once it is added.
66
67 return (AS1 == AS2 ? AliasResult::MayAlias : AliasResult::NoAlias);
68}
69
71 const MemoryLocation &Loc2, AAQueryInfo &AAQI,
72 const Instruction *) {
73 unsigned AS1 = Loc1.Ptr->getType()->getPointerAddressSpace();
74 unsigned AS2 = Loc2.Ptr->getType()->getPointerAddressSpace();
75
76 return getAliasResult(AS1, AS2);
77}
78
79// TODO: .param address space may be writable in presence of cvta.param, but
80// this instruction is currently not supported. NVPTXLowerArgs also does not
81// allow any writes to .param pointers.
82static bool isConstOrParam(unsigned AS) {
85}
86
88 AAQueryInfo &AAQI,
89 bool IgnoreLocals) {
92
93 const Value *Base = getUnderlyingObject(Loc.Ptr);
94 if (isConstOrParam(Base->getType()->getPointerAddressSpace()))
96
97 return AAResultBase::getModRefInfoMask(Loc, AAQI, IgnoreLocals);
98}
static AliasResult getAliasResult(unsigned AS1, unsigned AS2)
basic Basic Alias true
block Block Frequency Analysis
nvptx aa NVPTX Address space based Alias Analysis Wrapper
nvptx aa wrapper
static bool isConstOrParam(unsigned AS)
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.
ModRefInfo getModRefInfoMask(const MemoryLocation &Loc, AAQueryInfo &AAQI, bool IgnoreLocals)
The possible results of an alias query.
Definition: AliasAnalysis.h:83
@ 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.
ImmutablePass class - This class is used to provide information that does not need to be run.
Definition: Pass.h:282
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...
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.
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
@ ADDRESS_SPACE_GENERIC
Definition: NVPTXBaseInfo.h:22
@ ADDRESS_SPACE_CONST
Definition: NVPTXBaseInfo.h:25
@ ADDRESS_SPACE_PARAM
Definition: NVPTXBaseInfo.h:29
const Value * getUnderlyingObject(const Value *V, unsigned MaxLookup=6)
This method strips off any GEP address adjustments and pointer casts from the specified value,...
ImmutablePass * createNVPTXExternalAAWrapperPass()
void initializeNVPTXAAWrapperPassPass(PassRegistry &)
ModRefInfo
Flags indicating whether a memory access modifies or references memory.
Definition: ModRef.h:27
@ 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: PassManager.h:69