brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.8 KiB · 9ae3bb3 Raw
90 lines · c
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-exception6//7//===----------------------------------------------------------------------===//8//9/// \file10/// \brief Analyzes how many registers and other resources are used by11/// functions.12///13//===----------------------------------------------------------------------===//14 15#ifndef LLVM_LIB_TARGET_AMDGPU_AMDGPURESOURCEUSAGEANALYSIS_H16#define LLVM_LIB_TARGET_AMDGPU_AMDGPURESOURCEUSAGEANALYSIS_H17 18#include "llvm/ADT/SmallVector.h"19#include "llvm/CodeGen/MachineFunctionPass.h"20#include "llvm/IR/PassManager.h"21 22namespace llvm {23 24class GCNSubtarget;25class MachineFunction;26class GCNTargetMachine;27 28struct AMDGPUResourceUsageAnalysisImpl {29public: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 at34    // 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  SIFunctionResourceInfo50  analyzeResourceUsage(const MachineFunction &MF,51                       uint32_t AssumedStackSizeForDynamicSizeObjects,52                       uint32_t AssumedStackSizeForExternalCall) const;53};54 55struct AMDGPUResourceUsageAnalysisWrapperPass : public MachineFunctionPass {56  using FunctionResourceInfo =57      AMDGPUResourceUsageAnalysisImpl::SIFunctionResourceInfo;58  FunctionResourceInfo ResourceInfo;59 60public: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 74class AMDGPUResourceUsageAnalysis75    : public AnalysisInfoMixin<AMDGPUResourceUsageAnalysis> {76  friend AnalysisInfoMixin<AMDGPUResourceUsageAnalysis>;77  static AnalysisKey Key;78 79  const GCNTargetMachine &TM;80 81public:82  using Result = AMDGPUResourceUsageAnalysisImpl::SIFunctionResourceInfo;83  Result run(MachineFunction &MF, MachineFunctionAnalysisManager &MFAM);84 85  AMDGPUResourceUsageAnalysis(const GCNTargetMachine &TM_) : TM(TM_) {}86};87 88} // namespace llvm89#endif // LLVM_LIB_TARGET_AMDGPU_AMDGPURESOURCEUSAGEANALYSIS_H90