LLVM 24.0.0git
AMDGPUMemoryUtils.h
Go to the documentation of this file.
1//===- AMDGPUMemoryUtils.h - Memory related helper functions -*- C++ -*----===//
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
9#ifndef LLVM_LIB_TARGET_AMDGPU_UTILS_AMDGPUMEMORYUTILS_H
10#define LLVM_LIB_TARGET_AMDGPU_UTILS_AMDGPUMEMORYUTILS_H
11
12#include "llvm/ADT/ArrayRef.h"
14#include "llvm/ADT/DenseMap.h"
15#include "llvm/ADT/DenseSet.h"
16#include "llvm/ADT/MapVector.h"
17#include "llvm/IR/DebugLoc.h"
18
19namespace llvm {
20
21struct Align;
22class AAResults;
23class DataLayout;
24class GlobalVariable;
25class Instruction;
26class LoadInst;
27class MemoryDef;
28class MemorySSA;
29class MMRAMetadata;
30class Value;
31class Function;
32class CallGraph;
33class Module;
34class TargetExtType;
35
36namespace AMDGPU {
37
38static constexpr unsigned NamedBarrierTypeSizeInBytes = 1;
39
42
43Align getAlign(const DataLayout &DL, const GlobalVariable *GV);
44
45// Get the synthetic aperture number for the given address space, or None (0)
46// if the address space does not have one.
47unsigned getSyntheticApertureNumber(unsigned AS);
48
49// Copy metadata onto a load widened to read a superset of Source's bytes. Only
50// value-independent metadata is copied; metadata describing the loaded value
51// (!range, !noundef, !nofpclass, !tbaa, ...) is dropped.
52void copyMetadataForWidenedLoad(LoadInst &Dest, const LoadInst &Source);
53
54// If GV is a named-barrier return its type. Otherwise return nullptr.
56
57/// \returns how many named barriers are declared by \p GV.
59 const GlobalVariable &GV);
60
61bool isDynamicLDS(const GlobalVariable &GV);
63
68
69/// Iterates over all GlobalVariables in \p M, and whenever \p Filter returns
70/// true, replace all constant users of the GV with instructions.
72 Module &M, function_ref<bool(const GlobalVariable &)> Filter);
73
74/// Finds uses of Global Variables on a per-function basis.
75/// \param CG \p M Call Graph
76/// \param M Module
77/// \param Filter Function that returns true for GVs that need to be considered.
78/// \param Kernels[out] Maps kernels to global variables used by that kernel.
79/// \param Functions[out] Maps functions to global variables used by that
80/// function.
81void getUsesOfGVByFunction(const CallGraph &CG, Module &M,
82 function_ref<bool(const GlobalVariable &)> Filter,
83 FunctionVariableMap &Kernels,
84 FunctionVariableMap &Functions);
85
86/// Collects all uses of Global Variables in \p M using
87/// \ref getUsesOfGVByFunction.
88/// \param CG \p M Call Graph
89/// \param M Module
90/// \param Filter Filter for \ref getUsesOfGVByFunction - only GVs for which the
91/// filter returns true will be considered.
92/// \returns Uses of GVs that were found within each function, sorted by
93/// direct and indirect accesses.
96 function_ref<bool(const GlobalVariable &)> Filter);
97
98/// Collects all uses of LDS Global Variables in \p M using
99/// \ref getUsesOfGVByFunction, with \ref isLDSVariableToLower as the filter.
100/// \param CG \p M Call Graph
101/// \param M Module
102/// \returns Uses of LDS GVs that need lowering that were found within each
103/// function, sorted by direct and indirect accesses.
105
106/// Strip FnAttr attribute from any functions where we may have
107/// introduced its use.
108void removeFnAttrFromReachable(CallGraph &CG, Function *KernelRoot,
109 ArrayRef<StringRef> FnAttrs);
110
111/// Given a \p Def clobbering a load from \p Ptr according to the MSSA check
112/// if this is actually a memory update or an artificial clobber to facilitate
113/// ordering constraints.
114bool isReallyAClobber(const Value *Ptr, MemoryDef *Def, AAResults *AA);
115
116/// Check is a \p Load is clobbered in its function.
118 AAResults *AA);
119
120/// The distinct address spaces supported by the AMDGPU target for
121/// atomic memory operation. Can be ORed together.
123 NONE = 0u,
124 GLOBAL = 1u << 0,
125 LDS = 1u << 1,
126 SCRATCH = 1u << 2,
127 GDS = 1u << 3,
128 OTHER = 1u << 4,
129
130 /// The address spaces that can be accessed by a FLAT instruction.
132
133 /// The address spaces that support atomic instructions.
135
136 /// All address spaces.
138
139 LLVM_MARK_AS_BITMASK_ENUM(/* LargestFlag = */ ALL)
140};
141
142/// \return Return a bit set of the address spaces accessed by \p AS.
144
145/// Reads \p I's MMRAs to parse the "amdgpu-synchronize-as" MMRA.
146/// If this tag isn't present, or if it has no meaningful values, returns
147/// \p ATOMIC, otherwise returns the address spaces specified by the MD.
148/// Does not diagnose unexpected MMRA tag suffixes.
150
151/// Parses the values for the "amdgpu-synchronize-as" MMRA.
152/// If this tag isn't present, or if it has no meaningful values, returns
153/// \p ATOMIC, otherwise returns the address spaces specified by the MD.
154/// If \p DiagFn is non-null, unexpected suffixes for the MMRA tag are reported
155/// as warnings to \p DiagFn's context, located at \p DL.
157 const Function *DiagFn = nullptr,
158 const DebugLoc &DL = {});
159
160} // end namespace AMDGPU
161
162} // end namespace llvm
163
164#endif // LLVM_LIB_TARGET_AMDGPU_UTILS_AMDGPUMEMORYUTILS_H
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
This file defines the DenseMap class.
This file defines the DenseSet and SmallDenseSet classes.
#define I(x, y, z)
Definition MD5.cpp:57
This file implements a map that provides insertion order iteration.
Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:40
The basic data container for the call graph of a Module of IR.
Definition CallGraph.h:72
A parsed version of the target data layout string in and methods for querying it.
Definition DataLayout.h:64
A debug info location.
Definition DebugLoc.h:126
An instruction for reading from memory.
Helper class to manipulate !mmra metadata nodes.
This class implements a map that also provides access to all stored values in a deterministic order.
Definition MapVector.h:39
Represents a read-write access to memory, whether it is a must-alias, or a may-alias.
Definition MemorySSA.h:369
Encapsulates MemorySSA, including all data associated with memory accesses.
Definition MemorySSA.h:689
A Module instance is used to store all the information related to an LLVM module.
Definition Module.h:68
Class to represent target extensions types, which are generally unintrospectable from target-independ...
LLVM Value Representation.
Definition Value.h:75
An efficient, type-erasing, non-owning reference to a callable.
Abstract Attribute helper functions.
Definition Attributor.h:166
GVUsesInfoTy getTransitiveUsesOfLDSForLowering(const CallGraph &CG, Module &M)
Collects all uses of LDS Global Variables in M using getUsesOfGVByFunction, with isLDSVariableToLower...
static constexpr unsigned NamedBarrierTypeSizeInBytes
SIAtomicAddrSpace toSIAtomicAddrSpace(unsigned LLVMAddrSpace)
bool isDynamicLDS(const GlobalVariable &GV)
void removeFnAttrFromReachable(CallGraph &CG, Function *KernelRoot, ArrayRef< StringRef > FnAttrs)
Strip FnAttr attribute from any functions where we may have introduced its use.
bool eliminateGVConstantExprUsesFromAllInstructions(Module &M, function_ref< bool(const GlobalVariable &)> Filter)
Iterates over all GlobalVariables in M, and whenever Filter returns true, replace all constant users ...
SIAtomicAddrSpace
The distinct address spaces supported by the AMDGPU target for atomic memory operation.
@ ATOMIC
The address spaces that support atomic instructions.
void getUsesOfGVByFunction(const CallGraph &CG, Module &M, function_ref< bool(const GlobalVariable &)> Filter, FunctionVariableMap &Kernels, FunctionVariableMap &Functions)
Finds uses of Global Variables on a per-function basis.
SIAtomicAddrSpace getSynchronizeAddrSpace(const MMRAMetadata &MMRA, const Function *DiagFn, const DebugLoc &DL)
Parses the values for the "amdgpu-synchronize-as" MMRA.
bool isReallyAClobber(const Value *Ptr, MemoryDef *Def, AAResults *AA)
Given a Def clobbering a load from Ptr according to the MSSA check if this is actually a memory updat...
MapVector< Function *, DenseSet< GlobalVariable * > > FunctionVariableMap
TargetExtType * isNamedBarrier(const GlobalVariable &GV)
bool isLDSVariableToLower(const GlobalVariable &GV)
Align getAlign(const DataLayout &DL, const GlobalVariable *GV)
unsigned getNumNamedBarriersDeclared(const DataLayout &DL, const GlobalVariable &GV)
DenseMap< GlobalVariable *, DenseSet< Function * > > VariableFunctionMap
unsigned getSyntheticApertureNumber(unsigned AS)
void copyMetadataForWidenedLoad(LoadInst &Dest, const LoadInst &Source)
bool isClobberedInFunction(const LoadInst *Load, MemorySSA *MSSA, AAResults *AA)
Check is a Load is clobbered in its function.
GVUsesInfoTy getTransitiveUsesOfGV(const CallGraph &CG, Module &M, function_ref< bool(const GlobalVariable &)> Filter)
Collects all uses of Global Variables in M using getUsesOfGVByFunction.
This is an optimization pass for GlobalISel generic memory operations.
@ Load
The value being inserted comes from a load (InsertElement only).
FunctionVariableMap DirectAccess
FunctionVariableMap IndirectAccess
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition Alignment.h:39