LLVM  13.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 "AMDGPU.h"
17 #include "llvm/ADT/DenseMap.h"
18 #include "llvm/IR/Constants.h"
19 
20 namespace llvm {
21 
22 class ConstantExpr;
23 
24 namespace AMDGPU {
25 
26 /// Collect reachable callees for each kernel defined in the module \p M and
27 /// return collected callees at \p KernelToCallees.
29  Module &M,
30  DenseMap<Function *, SmallPtrSet<Function *, 8>> &KernelToCallees);
31 
32 /// For the given LDS global \p GV, visit all its users and collect all
33 /// non-kernel functions within which \p GV is used and return collected list of
34 /// such non-kernel functions.
35 SmallPtrSet<Function *, 8> collectNonKernelAccessorsOfLDS(GlobalVariable *GV);
36 
37 /// Collect all the instructions where user \p U belongs to. \p U could be
38 /// instruction itself or it could be a constant expression which is used within
39 /// an instruction. If \p CollectKernelInsts is true, collect instructions only
40 /// from kernels, otherwise collect instructions only from non-kernel functions.
41 DenseMap<Function *, SmallPtrSet<Instruction *, 8>>
42 getFunctionToInstsMap(User *U, bool CollectKernelInsts);
43 
44 bool isKernelCC(const Function *Func);
45 
46 Align getAlign(DataLayout const &DL, const GlobalVariable *GV);
47 
48 /// \returns true if a given global variable \p GV (or its global users) appear
49 /// as an use within some instruction (either from kernel or from non-kernel).
50 bool hasUserInstruction(const GlobalValue *GV);
51 
52 /// \returns true if an LDS global requres lowering to a module LDS structure
53 /// if \p F is not given. If \p F is given it must be a kernel and function
54 /// \returns true if an LDS global is directly used from that kernel and it
55 /// is safe to replace its uses with a kernel LDS structure member.
56 bool shouldLowerLDSToStruct(const GlobalVariable &GV,
57  const Function *F = nullptr);
58 
59 std::vector<GlobalVariable *> findVariablesToLower(Module &M,
60  const Function *F = nullptr);
61 
62 SmallPtrSet<GlobalValue *, 32> getUsedList(Module &M);
63 
64 /// Replace all uses of constant \p C with instructions in \p F.
65 void replaceConstantUsesInFunction(ConstantExpr *C, const Function *F);
66 } // end namespace AMDGPU
67 
68 } // end namespace llvm
69 
70 #endif // LLVM_LIB_TARGET_AMDGPU_UTILS_AMDGPULDSUTILS_H
llvm::AMDGPU::findVariablesToLower
std::vector< GlobalVariable * > findVariablesToLower(Module &M, const Function *F)
Definition: AMDGPULDSUtils.cpp:306
llvm
---------------------— PointerInfo ------------------------------------—
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:151
DenseMap.h
F
#define F(x, y, z)
Definition: MD5.cpp:56
llvm::AMDGPU::getUsedList
SmallPtrSet< GlobalValue *, 32 > getUsedList(Module &M)
Definition: AMDGPULDSUtils.cpp:339
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:118
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:220
AMDGPU.h
llvm::AMDGPU::shouldLowerLDSToStruct
bool shouldLowerLDSToStruct(const GlobalVariable &GV, const Function *F)
Definition: AMDGPULDSUtils.cpp:248
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:195
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:111
llvm::AMDGPU::hasUserInstruction
bool hasUserInstruction(const GlobalValue *GV)
Definition: AMDGPULDSUtils.cpp:229
llvm::AMDGPU::isKernelCC
bool isKernelCC(const Function *Func)
Definition: AMDGPULDSUtils.cpp:191