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"
13#include "llvm/ADT/DenseMap.h"
14#include "llvm/ADT/DenseSet.h"
15#include "llvm/ADT/MapVector.h"
16
17namespace llvm {
18
19struct Align;
20class AAResults;
21class DataLayout;
22class GlobalVariable;
23class LoadInst;
24class MemoryDef;
25class MemorySSA;
26class Value;
27class Function;
28class CallGraph;
29class Module;
30class TargetExtType;
31
32namespace AMDGPU {
33
34static constexpr unsigned NamedBarrierTypeSizeInBytes = 16;
35
38
39Align getAlign(const DataLayout &DL, const GlobalVariable *GV);
40
41// Get the synthetic aperture number for the given address space, or None (0)
42// if the address space does not have one.
43unsigned getSyntheticApertureNumber(unsigned AS);
44
45// Copy metadata onto a load widened to read a superset of Source's bytes. Only
46// value-independent metadata is copied; metadata describing the loaded value
47// (!range, !noundef, !nofpclass, !tbaa, ...) is dropped.
48void copyMetadataForWidenedLoad(LoadInst &Dest, const LoadInst &Source);
49
50// If GV is a named-barrier return its type. Otherwise return nullptr.
52
53/// \returns how many named barriers are declared by \p GV.
55 const GlobalVariable &GV);
56
57bool isDynamicLDS(const GlobalVariable &GV);
59
64
65/// Iterates over all GlobalVariables in \p M, and whenever \p Filter returns
66/// true, replace all constant users of the GV with instructions.
68 Module &M, function_ref<bool(const GlobalVariable &)> Filter);
69
70/// Finds uses of Global Variables on a per-function basis.
71/// \param CG \p M Call Graph
72/// \param M Module
73/// \param Filter Function that returns true for GVs that need to be considered.
74/// \param Kernels[out] Maps kernels to global variables used by that kernel.
75/// \param Functions[out] Maps functions to global variables used by that
76/// function.
77void getUsesOfGVByFunction(const CallGraph &CG, Module &M,
78 function_ref<bool(const GlobalVariable &)> Filter,
79 FunctionVariableMap &Kernels,
80 FunctionVariableMap &Functions);
81
82/// Collects all uses of Global Variables in \p M using
83/// \ref getUsesOfGVByFunction.
84/// \param CG \p M Call Graph
85/// \param M Module
86/// \param Filter Filter for \ref getUsesOfGVByFunction - only GVs for which the
87/// filter returns true will be considered.
88/// \returns Uses of GVs that were found within each function, sorted by
89/// direct and indirect accesses.
92 function_ref<bool(const GlobalVariable &)> Filter);
93
94/// Collects all uses of LDS Global Variables in \p M using
95/// \ref getUsesOfGVByFunction, with \ref isLDSVariableToLower as the filter.
96/// \param CG \p M Call Graph
97/// \param M Module
98/// \returns Uses of LDS GVs that need lowering that were found within each
99/// function, sorted by direct and indirect accesses.
101
102/// Strip FnAttr attribute from any functions where we may have
103/// introduced its use.
104void removeFnAttrFromReachable(CallGraph &CG, Function *KernelRoot,
105 ArrayRef<StringRef> FnAttrs);
106
107/// Given a \p Def clobbering a load from \p Ptr according to the MSSA check
108/// if this is actually a memory update or an artificial clobber to facilitate
109/// ordering constraints.
110bool isReallyAClobber(const Value *Ptr, MemoryDef *Def, AAResults *AA);
111
112/// Check is a \p Load is clobbered in its function.
114 AAResults *AA);
115
116} // end namespace AMDGPU
117
118} // end namespace llvm
119
120#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.
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
An instruction for reading from memory.
This class implements a map that also provides access to all stored values in a deterministic order.
Definition MapVector.h:38
Represents a read-write access to memory, whether it is a must-alias, or a may-alias.
Definition MemorySSA.h:371
Encapsulates MemorySSA, including all data associated with memory accesses.
Definition MemorySSA.h:702
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:165
GVUsesInfoTy getTransitiveUsesOfLDSForLowering(const CallGraph &CG, Module &M)
Collects all uses of LDS Global Variables in M using getUsesOfGVByFunction, with isLDSVariableToLower...
static constexpr unsigned NamedBarrierTypeSizeInBytes
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 ...
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.
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