1 //===- AMDGPUResourceUsageAnalysis.h ---- analysis of resources -*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
10 /// \brief Analyzes how many registers and other resources are used by
13 //===----------------------------------------------------------------------===//
15 #ifndef LLVM_LIB_TARGET_AMDGPU_AMDGPURESOURCEUSAGEANALYSIS_H
16 #define LLVM_LIB_TARGET_AMDGPU_AMDGPURESOURCEUSAGEANALYSIS_H
18 #include "llvm/Analysis/CallGraphSCCPass.h"
19 #include "llvm/CodeGen/MachineModuleInfo.h"
20 #include "llvm/IR/ValueMap.h"
25 class MachineFunction
;
28 struct AMDGPUResourceUsageAnalysis
: public CallGraphSCCPass
{
32 // Track resource usage for callee functions.
33 struct SIFunctionResourceInfo
{
34 // Track the number of explicitly used VGPRs. Special registers reserved at
35 // the end are tracked separately.
38 int32_t NumExplicitSGPR
= 0;
39 uint64_t PrivateSegmentSize
= 0;
41 bool UsesFlatScratch
= false;
42 bool HasDynamicallySizedStack
= false;
43 bool HasRecursion
= false;
44 bool HasIndirectCall
= false;
46 int32_t getTotalNumSGPRs(const GCNSubtarget
&ST
) const;
47 int32_t getTotalNumVGPRs(const GCNSubtarget
&ST
) const;
50 AMDGPUResourceUsageAnalysis() : CallGraphSCCPass(ID
) {}
52 bool runOnSCC(CallGraphSCC
&SCC
) override
;
54 bool doInitialization(CallGraph
&CG
) override
{
55 CallGraphResourceInfo
.clear();
56 return CallGraphSCCPass::doInitialization(CG
);
59 void getAnalysisUsage(AnalysisUsage
&AU
) const override
{
60 AU
.addRequired
<MachineModuleInfoWrapperPass
>();
64 const SIFunctionResourceInfo
&getResourceInfo(const Function
*F
) const {
65 auto Info
= CallGraphResourceInfo
.find(F
);
66 assert(Info
!= CallGraphResourceInfo
.end() &&
67 "Failed to find resource info for function");
68 return Info
->getSecond();
72 SIFunctionResourceInfo
analyzeResourceUsage(const MachineFunction
&MF
,
73 const TargetMachine
&TM
) const;
74 void propagateIndirectCallRegisterUsage();
76 DenseMap
<const Function
*, SIFunctionResourceInfo
> CallGraphResourceInfo
;
79 #endif // LLVM_LIB_TARGET_AMDGPU_AMDGPURESOURCEUSAGEANALYSIS_H