| 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 | |
| 18 | #include "llvm/ADT/SmallVector.h" |
| 19 | #include "llvm/CodeGen/MachineFunctionPass.h" |
| 20 | #include "llvm/IR/PassManager.h" |
| 21 | |
| 22 | namespace llvm { |
| 23 | |
| 24 | class GCNSubtarget; |
| 25 | class MachineFunction; |
| 26 | class GCNTargetMachine; |
| 27 | |
| 28 | struct AMDGPUResourceUsageAnalysisImpl { |
| 29 | public: |
| 30 | static char ID; |
| 31 | // Track resource usage for callee functions. |
| 32 | struct SIFunctionResourceInfo { |
| 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; |
| 38 | int32_t NumNamedBarrier = 0; |
| 39 | uint64_t CalleeSegmentSize = 0; |
| 40 | uint64_t PrivateSegmentSize = 0; |
| 41 | bool UsesVCC = false; |
| 42 | bool UsesFlatScratch = false; |
| 43 | bool HasDynamicallySizedStack = false; |
| 44 | bool HasRecursion = false; |
| 45 | bool HasIndirectCall = false; |
| 46 | SmallVector<const Function *, 16> Callees; |
| 47 | }; |
| 48 | |
| 49 | SIFunctionResourceInfo |
| 50 | analyzeResourceUsage(const MachineFunction &MF, |
| 51 | uint32_t AssumedStackSizeForDynamicSizeObjects, |
| 52 | uint32_t AssumedStackSizeForExternalCall) const; |
| 53 | }; |
| 54 | |
| 55 | struct AMDGPUResourceUsageAnalysisWrapperPass : public MachineFunctionPass { |
| 56 | using FunctionResourceInfo = |
| 57 | AMDGPUResourceUsageAnalysisImpl::SIFunctionResourceInfo; |
| 58 | FunctionResourceInfo ResourceInfo; |
| 59 | |
| 60 | public: |
| 61 | static char ID; |
| 62 | AMDGPUResourceUsageAnalysisWrapperPass() : MachineFunctionPass(ID) {} |
| 63 | |
| 64 | bool runOnMachineFunction(MachineFunction &MF) override; |
| 65 | |
| 66 | const FunctionResourceInfo &getResourceInfo() const { return ResourceInfo; } |
| 67 | |
| 68 | void getAnalysisUsage(AnalysisUsage &AU) const override { |
| 69 | AU.setPreservesAll(); |
| 70 | MachineFunctionPass::getAnalysisUsage(AU); |
| 71 | } |
| 72 | }; |
| 73 | |
| 74 | class AMDGPUResourceUsageAnalysis |
| 75 | : public AnalysisInfoMixin<AMDGPUResourceUsageAnalysis> { |
| 76 | friend AnalysisInfoMixin<AMDGPUResourceUsageAnalysis>; |
| 77 | static AnalysisKey Key; |
| 78 | |
| 79 | const GCNTargetMachine &TM; |
| 80 | |
| 81 | public: |
| 82 | using Result = AMDGPUResourceUsageAnalysisImpl::SIFunctionResourceInfo; |
| 83 | Result run(MachineFunction &MF, MachineFunctionAnalysisManager &MFAM); |
| 84 | |
| 85 | AMDGPUResourceUsageAnalysis(const GCNTargetMachine &TM_) : TM(TM_) {} |
| 86 | }; |
| 87 | |
| 88 | } // namespace llvm |
| 89 | #endif // LLVM_LIB_TARGET_AMDGPU_AMDGPURESOURCEUSAGEANALYSIS_H |
| 90 |