| 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 | |
| 21 | namespace llvm { |
| 22 | |
| 23 | class GCNSubtarget; |
| 24 | class MachineFunction; |
| 25 | class TargetMachine; |
| 26 | |
| 27 | struct AMDGPUResourceUsageAnalysis : public MachineFunctionPass { |
| 28 | public: |
| 29 | static char ID; |
| 30 | // Track resource usage for callee functions. |
| 31 | struct SIFunctionResourceInfo { |
| 32 | // Track the number of explicitly used VGPRs. Special registers reserved at |
| 33 | // the end are tracked separately. |
| 34 | int32_t NumVGPR = 0; |
| 35 | int32_t NumAGPR = 0; |
| 36 | int32_t NumExplicitSGPR = 0; |
| 37 | uint64_t CalleeSegmentSize = 0; |
| 38 | uint64_t PrivateSegmentSize = 0; |
| 39 | bool UsesVCC = false; |
| 40 | bool UsesFlatScratch = false; |
| 41 | bool HasDynamicallySizedStack = false; |
| 42 | bool HasRecursion = false; |
| 43 | bool HasIndirectCall = false; |
| 44 | SmallVector<const Function *, 16> Callees; |
| 45 | }; |
| 46 | |
| 47 | AMDGPUResourceUsageAnalysis() : MachineFunctionPass(ID) {} |
| 48 | |
| 49 | bool runOnMachineFunction(MachineFunction &MF) override; |
| 50 | |
| 51 | const SIFunctionResourceInfo &getResourceInfo() const { return ResourceInfo; } |
| 52 | |
| 53 | void getAnalysisUsage(AnalysisUsage &AU) const override { |
| 54 | AU.setPreservesAll(); |
| 55 | MachineFunctionPass::getAnalysisUsage(AU); |
| 56 | } |
| 57 | |
| 58 | private: |
| 59 | SIFunctionResourceInfo |
| 60 | analyzeResourceUsage(const MachineFunction &MF, |
| 61 | uint32_t AssumedStackSizeForDynamicSizeObjects, |
| 62 | uint32_t AssumedStackSizeForExternalCall) const; |
| 63 | SIFunctionResourceInfo ResourceInfo; |
| 64 | }; |
| 65 | } // namespace llvm |
| 66 | #endif // LLVM_LIB_TARGET_AMDGPU_AMDGPURESOURCEUSAGEANALYSIS_H |
| 67 | |