LLVM  14.0.0git
AMDGPUResourceUsageAnalysis.h
Go to the documentation of this file.
1 //===- AMDGPUResourceUsageAnalysis.h ---- analysis of resources -*- 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 /// \file
10 /// \brief Analyzes how many registers and other resources are used by
11 /// functions.
12 ///
13 //===----------------------------------------------------------------------===//
14 
15 #ifndef LLVM_LIB_TARGET_AMDGPU_AMDGPURESOURCEUSAGEANALYSIS_H
16 #define LLVM_LIB_TARGET_AMDGPU_AMDGPURESOURCEUSAGEANALYSIS_H
17 
20 
21 namespace llvm {
22 
23 class GCNSubtarget;
24 class MachineFunction;
25 class TargetMachine;
26 
28  static char ID;
29 
30 public:
31  // Track resource usage for callee functions.
33  // Track the number of explicitly used VGPRs. Special registers reserved at
34  // the end are tracked separately.
35  int32_t NumVGPR = 0;
36  int32_t NumAGPR = 0;
37  int32_t NumExplicitSGPR = 0;
39  bool UsesVCC = false;
40  bool UsesFlatScratch = false;
42  bool HasRecursion = false;
43  bool HasIndirectCall = false;
44 
45  int32_t getTotalNumSGPRs(const GCNSubtarget &ST) const;
46  int32_t getTotalNumVGPRs(const GCNSubtarget &ST) const;
47  };
48 
50 
51  bool runOnSCC(CallGraphSCC &SCC) override;
52 
53  bool doInitialization(CallGraph &CG) override {
54  CallGraphResourceInfo.clear();
56  }
57 
58  void getAnalysisUsage(AnalysisUsage &AU) const override {
60  AU.setPreservesAll();
61  }
62 
64  auto Info = CallGraphResourceInfo.find(F);
65  assert(Info != CallGraphResourceInfo.end() &&
66  "Failed to find resource info for function");
67  return Info->getSecond();
68  }
69 
70 private:
71  SIFunctionResourceInfo analyzeResourceUsage(const MachineFunction &MF,
72  const TargetMachine &TM) const;
73  void propagateIndirectCallRegisterUsage();
74 
76 };
77 } // namespace llvm
78 #endif // LLVM_LIB_TARGET_AMDGPU_AMDGPURESOURCEUSAGEANALYSIS_H
llvm
---------------------— PointerInfo ------------------------------------—
Definition: AllocatorList.h:23
llvm::Function
Definition: Function.h:61
llvm::CallGraph
The basic data container for the call graph of a Module of IR.
Definition: CallGraph.h:73
llvm::GCNSubtarget
Definition: GCNSubtarget.h:31
llvm::AMDGPUResourceUsageAnalysis::SIFunctionResourceInfo::HasDynamicallySizedStack
bool HasDynamicallySizedStack
Definition: AMDGPUResourceUsageAnalysis.h:41
F
#define F(x, y, z)
Definition: MD5.cpp:56
llvm::AMDGPUResourceUsageAnalysis::doInitialization
bool doInitialization(CallGraph &CG) override
doInitialization - This method is called before the SCC's of the program has been processed,...
Definition: AMDGPUResourceUsageAnalysis.h:53
llvm::CallGraphSCCPass::doInitialization
virtual bool doInitialization(CallGraph &CG)
doInitialization - This method is called before the SCC's of the program has been processed,...
Definition: CallGraphSCCPass.h:48
llvm::CallGraphSCC
CallGraphSCC - This is a single SCC that a CallGraphSCCPass is run on.
Definition: CallGraphSCCPass.h:87
llvm::AnalysisUsage
Represent the analysis usage information of a pass.
Definition: PassAnalysisSupport.h:47
llvm::AMDGPUResourceUsageAnalysis::getResourceInfo
const SIFunctionResourceInfo & getResourceInfo(const Function *F) const
Definition: AMDGPUResourceUsageAnalysis.h:63
Info
Analysis containing CSE Info
Definition: CSEInfo.cpp:27
llvm::AMDGPUResourceUsageAnalysis::SIFunctionResourceInfo::HasRecursion
bool HasRecursion
Definition: AMDGPUResourceUsageAnalysis.h:42
uint64_t
llvm::MachineModuleInfoWrapperPass
Definition: MachineModuleInfo.h:279
llvm::ARM_MB::ST
@ ST
Definition: ARMBaseInfo.h:73
llvm::DenseMap
Definition: DenseMap.h:714
llvm::AMDGPUResourceUsageAnalysis::SIFunctionResourceInfo::NumAGPR
int32_t NumAGPR
Definition: AMDGPUResourceUsageAnalysis.h:36
assert
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
llvm::TargetMachine
Primary interface to the complete machine description for the target machine.
Definition: TargetMachine.h:79
MachineModuleInfo.h
llvm::MachineFunction
Definition: MachineFunction.h:230
llvm::AMDGPU::CPol::SCC
@ SCC
Definition: SIDefines.h:292
llvm::AMDGPUResourceUsageAnalysis::runOnSCC
bool runOnSCC(CallGraphSCC &SCC) override
runOnSCC - This method should be implemented by the subclass to perform whatever action is necessary ...
Definition: AMDGPUResourceUsageAnalysis.cpp:92
CallGraphSCCPass.h
llvm::AMDGPUResourceUsageAnalysis::SIFunctionResourceInfo::UsesVCC
bool UsesVCC
Definition: AMDGPUResourceUsageAnalysis.h:39
llvm::AMDGPUResourceUsageAnalysis::SIFunctionResourceInfo::NumExplicitSGPR
int32_t NumExplicitSGPR
Definition: AMDGPUResourceUsageAnalysis.h:37
llvm::AnalysisUsage::setPreservesAll
void setPreservesAll()
Set by analyses that do not transform their input at all.
Definition: PassAnalysisSupport.h:130
llvm::CallGraphSCCPass
Definition: CallGraphSCCPass.h:34
llvm::AMDGPUResourceUsageAnalysis::getAnalysisUsage
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - For this class, we declare that we require and preserve the call graph.
Definition: AMDGPUResourceUsageAnalysis.h:58
llvm::AMDGPUResourceUsageAnalysis::AMDGPUResourceUsageAnalysis
AMDGPUResourceUsageAnalysis()
Definition: AMDGPUResourceUsageAnalysis.h:49
llvm::AMDGPUResourceUsageAnalysis::SIFunctionResourceInfo::getTotalNumSGPRs
int32_t getTotalNumSGPRs(const GCNSubtarget &ST) const
Definition: AMDGPUResourceUsageAnalysis.cpp:78
llvm::AMDGPUResourceUsageAnalysis::SIFunctionResourceInfo::UsesFlatScratch
bool UsesFlatScratch
Definition: AMDGPUResourceUsageAnalysis.h:40
llvm::AMDGPUResourceUsageAnalysis::SIFunctionResourceInfo::getTotalNumVGPRs
int32_t getTotalNumVGPRs(const GCNSubtarget &ST) const
Definition: AMDGPUResourceUsageAnalysis.cpp:85
llvm::AMDGPUResourceUsageAnalysis
Definition: AMDGPUResourceUsageAnalysis.h:27
TM
const char LLVMTargetMachineRef TM
Definition: PassBuilderBindings.cpp:47
llvm::AMDGPUResourceUsageAnalysis::SIFunctionResourceInfo::PrivateSegmentSize
uint64_t PrivateSegmentSize
Definition: AMDGPUResourceUsageAnalysis.h:38
llvm::AnalysisUsage::addRequired
AnalysisUsage & addRequired()
Definition: PassAnalysisSupport.h:75
llvm::AMDGPUResourceUsageAnalysis::SIFunctionResourceInfo::NumVGPR
int32_t NumVGPR
Definition: AMDGPUResourceUsageAnalysis.h:35
llvm::AMDGPUResourceUsageAnalysis::SIFunctionResourceInfo
Definition: AMDGPUResourceUsageAnalysis.h:32
llvm::AMDGPUResourceUsageAnalysis::SIFunctionResourceInfo::HasIndirectCall
bool HasIndirectCall
Definition: AMDGPUResourceUsageAnalysis.h:43
llvm::AMDGPUResourceUsageAnalysis::ID
static char ID
Definition: AMDGPUResourceUsageAnalysis.h:28