LLVM  14.0.0git
AMDGPULDSUtils.h
Go to the documentation of this file.
1 //===- AMDGPULDSUtils.h - LDS 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 // AMDGPU LDS related helper utility functions.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #ifndef LLVM_LIB_TARGET_AMDGPU_UTILS_AMDGPULDSUTILS_H
14 #define LLVM_LIB_TARGET_AMDGPU_UTILS_AMDGPULDSUTILS_H
15 
16 #include "llvm/ADT/DenseMap.h"
17 #include "llvm/IR/Constants.h"
18 
19 namespace llvm {
20 
21 class ConstantExpr;
22 
23 namespace AMDGPU {
24 
25 /// Collect reachable callees for each kernel defined in the module \p M and
26 /// return collected callees at \p KernelToCallees.
28  Module &M,
29  DenseMap<Function *, SmallPtrSet<Function *, 8>> &KernelToCallees);
30 
31 /// For the given LDS global \p GV, visit all its users and collect all
32 /// non-kernel functions within which \p GV is used and return collected list of
33 /// such non-kernel functions.
34 SmallPtrSet<Function *, 8> collectNonKernelAccessorsOfLDS(GlobalVariable *GV);
35 
36 /// Collect all the instructions where user \p U belongs to. \p U could be
37 /// instruction itself or it could be a constant expression which is used within
38 /// an instruction. If \p CollectKernelInsts is true, collect instructions only
39 /// from kernels, otherwise collect instructions only from non-kernel functions.
40 DenseMap<Function *, SmallPtrSet<Instruction *, 8>>
41 getFunctionToInstsMap(User *U, bool CollectKernelInsts);
42 
43 bool isKernelCC(const Function *Func);
44 
45 Align getAlign(DataLayout const &DL, const GlobalVariable *GV);
46 
47 /// \returns true if a given global variable \p GV (or its global users) appear
48 /// as an use within some instruction (either from kernel or from non-kernel).
49 bool hasUserInstruction(const GlobalValue *GV);
50 
51 /// \returns true if an LDS global requires lowering to a module LDS structure
52 /// if \p F is not given. If \p F is given it must be a kernel and function
53 /// \returns true if an LDS global is directly used from that kernel and it
54 /// is safe to replace its uses with a kernel LDS structure member.
55 bool shouldLowerLDSToStruct(const GlobalVariable &GV,
56  const Function *F = nullptr);
57 
58 std::vector<GlobalVariable *> findVariablesToLower(Module &M,
59  const Function *F = nullptr);
60 
61 SmallPtrSet<GlobalValue *, 32> getUsedList(Module &M);
62 
63 /// Replace all uses of constant \p C with instructions in \p F.
64 void replaceConstantUsesInFunction(ConstantExpr *C, const Function *F);
65 } // end namespace AMDGPU
66 
67 } // end namespace llvm
68 
69 #endif // LLVM_LIB_TARGET_AMDGPU_UTILS_AMDGPULDSUTILS_H
llvm::AMDGPU::findVariablesToLower
std::vector< GlobalVariable * > findVariablesToLower(Module &M, const Function *F)
Definition: AMDGPULDSUtils.cpp:312
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AllocatorList.h:23
llvm::AMDGPU::getFunctionToInstsMap
DenseMap< Function *, SmallPtrSet< Instruction *, 8 > > getFunctionToInstsMap(User *U, bool CollectKernelInsts)
Collect all the instructions where user U belongs to.
Definition: AMDGPULDSUtils.cpp:157
DenseMap.h
F
#define F(x, y, z)
Definition: MD5.cpp:56
llvm::AMDGPU::getUsedList
SmallPtrSet< GlobalValue *, 32 > getUsedList(Module &M)
Definition: AMDGPULDSUtils.cpp:345
Constants.h
C
(vector float) vec_cmpeq(*A, *B) C
Definition: README_ALTIVEC.txt:86
llvm::AMDGPU::collectNonKernelAccessorsOfLDS
SmallPtrSet< Function *, 8 > collectNonKernelAccessorsOfLDS(GlobalVariable *GV)
For the given LDS global GV, visit all its users and collect all non-kernel functions within which GV...
Definition: AMDGPULDSUtils.cpp:124
Align
uint64_t Align
Definition: ELFObjHandler.cpp:83
llvm::AMDGPU::replaceConstantUsesInFunction
void replaceConstantUsesInFunction(ConstantExpr *C, const Function *F)
Replace all uses of constant C with instructions in F.
Definition: AMDGPULDSUtils.cpp:226
llvm::AMDGPU::shouldLowerLDSToStruct
bool shouldLowerLDSToStruct(const GlobalVariable &GV, const Function *F)
Definition: AMDGPULDSUtils.cpp:254
DL
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
Definition: AArch64SLSHardening.cpp:76
Module
Machine Check Debug Module
Definition: MachineCheckDebugify.cpp:122
llvm::AMDGPU::getAlign
Align getAlign(DataLayout const &DL, const GlobalVariable *GV)
Definition: AMDGPULDSUtils.cpp:201
llvm::AMDGPU::collectReachableCallees
void collectReachableCallees(Module &M, DenseMap< Function *, SmallPtrSet< Function *, 8 >> &KernelToCallees)
Collect reachable callees for each kernel defined in the module M and return collected callees at Ker...
Definition: AMDGPULDSUtils.cpp:117
llvm::AMDGPU::hasUserInstruction
bool hasUserInstruction(const GlobalValue *GV)
Definition: AMDGPULDSUtils.cpp:235
llvm::AMDGPU::isKernelCC
bool isKernelCC(const Function *Func)
Definition: AMDGPULDSUtils.cpp:197