[ORC] Add std::tuple support to SimplePackedSerialization.
[llvm-project.git] / llvm / lib / Target / AMDGPU / AMDGPUResourceUsageAnalysis.h
blob832e8119e4446a910df5b8f1e54b0af78dc5c257
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 //===----------------------------------------------------------------------===//
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"
22 namespace llvm {
24 class GCNSubtarget;
25 class MachineFunction;
26 class TargetMachine;
28 struct AMDGPUResourceUsageAnalysis : public CallGraphSCCPass {
29 static char ID;
31 public:
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.
36 int32_t NumVGPR = 0;
37 int32_t NumAGPR = 0;
38 int32_t NumExplicitSGPR = 0;
39 uint64_t PrivateSegmentSize = 0;
40 bool UsesVCC = false;
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>();
61 AU.setPreservesAll();
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();
71 private:
72 SIFunctionResourceInfo analyzeResourceUsage(const MachineFunction &MF,
73 const TargetMachine &TM) const;
74 void propagateIndirectCallRegisterUsage();
76 DenseMap<const Function *, SIFunctionResourceInfo> CallGraphResourceInfo;
78 } // namespace llvm
79 #endif // LLVM_LIB_TARGET_AMDGPU_AMDGPURESOURCEUSAGEANALYSIS_H