LLVM 22.0.0git
AMDGPUMCResourceInfo.h
Go to the documentation of this file.
1//===- AMDGPUMCResourceInfo.h ----- MC Resource Info --------------*- 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 MC infrastructure to propagate the function level resource usage
11/// info.
12///
13//===----------------------------------------------------------------------===//
14
15#ifndef LLVM_LIB_TARGET_AMDGPU_AMDGPUMCRESOURCEINFO_H
16#define LLVM_LIB_TARGET_AMDGPU_AMDGPUMCRESOURCEINFO_H
17
20
21namespace llvm {
22
23class MCContext;
24class MCSymbol;
25class StringRef;
26class MachineFunction;
27
29public:
41 };
42
43private:
44 int32_t MaxVGPR = 0;
45 int32_t MaxAGPR = 0;
46 int32_t MaxSGPR = 0;
47 int32_t MaxNamedBarrier = 0;
48
49 // Whether the MCResourceInfo has been finalized through finalize(MCContext
50 // &). Should only be called once, at the end of AsmPrinting to assign MaxXGPR
51 // symbols to their final value.
52 bool Finalized = false;
53
54 void assignResourceInfoExpr(int64_t localValue, ResourceInfoKind RIK,
56 const MachineFunction &MF,
58 MCContext &OutContext);
59
60 // Assigns expression for Max S/V/A-GPRs to the referenced symbols.
61 void assignMaxRegs(MCContext &OutContext);
62
63 // Take flattened max of cyclic function calls' knowns. For example, for
64 // a cycle A->B->C->D->A, take max(A, B, C, D) for A and have B, C, D have the
65 // propgated value from A.
66 const MCExpr *flattenedCycleMax(MCSymbol *RecSym, ResourceInfoKind RIK,
67 MCContext &OutContext);
68
69public:
70 MCResourceInfo() = default;
71 void addMaxVGPRCandidate(int32_t candidate) {
72 MaxVGPR = std::max(MaxVGPR, candidate);
73 }
74 void addMaxAGPRCandidate(int32_t candidate) {
75 MaxAGPR = std::max(MaxAGPR, candidate);
76 }
77 void addMaxSGPRCandidate(int32_t candidate) {
78 MaxSGPR = std::max(MaxSGPR, candidate);
79 }
80 void addMaxNamedBarrierCandidate(int32_t candidate) {
81 MaxNamedBarrier = std::max(MaxNamedBarrier, candidate);
82 }
83
85 MCContext &OutContext, bool IsLocal);
87 MCContext &Ctx, bool IsLocal);
88
89 void reset();
90
91 // Resolves the final symbols that requires the inter-function resource info
92 // to be resolved.
93 void finalize(MCContext &OutContext);
94
99
100 /// AMDGPUResourceUsageAnalysis gathers resource usage on a per-function
101 /// granularity. However, some resource info has to be assigned the call
102 /// transitive maximum or accumulative. For example, if A calls B and B's VGPR
103 /// usage exceeds A's, A should be assigned B's VGPR usage. Furthermore,
104 /// functions with indirect calls should be assigned the module level maximum.
106 const MachineFunction &MF,
108 MCContext &OutContext);
109
110 const MCExpr *createTotalNumVGPRs(const MachineFunction &MF, MCContext &Ctx);
111 const MCExpr *createTotalNumSGPRs(const MachineFunction &MF, bool hasXnack,
112 MCContext &Ctx);
113};
114} // namespace llvm
115
116#endif // LLVM_LIB_TARGET_AMDGPU_AMDGPUMCRESOURCEINFO_H
Analyzes how many registers and other resources are used by functions.
arc branch finalize
Context object for machine code objects.
Definition: MCContext.h:83
Base class for the full range of assembler expressions which are needed for parsing.
Definition: MCExpr.h:34
MCResourceInfo()=default
MCSymbol * getMaxNamedBarrierSymbol(MCContext &OutContext)
void addMaxSGPRCandidate(int32_t candidate)
MCSymbol * getMaxSGPRSymbol(MCContext &OutContext)
const MCExpr * getSymRefExpr(StringRef FuncName, ResourceInfoKind RIK, MCContext &Ctx, bool IsLocal)
void addMaxNamedBarrierCandidate(int32_t candidate)
MCSymbol * getMaxAGPRSymbol(MCContext &OutContext)
const MCExpr * createTotalNumVGPRs(const MachineFunction &MF, MCContext &Ctx)
MCSymbol * getSymbol(StringRef FuncName, ResourceInfoKind RIK, MCContext &OutContext, bool IsLocal)
void addMaxAGPRCandidate(int32_t candidate)
MCSymbol * getMaxVGPRSymbol(MCContext &OutContext)
const MCExpr * createTotalNumSGPRs(const MachineFunction &MF, bool hasXnack, MCContext &Ctx)
void addMaxVGPRCandidate(int32_t candidate)
void gatherResourceInfo(const MachineFunction &MF, const AMDGPUResourceUsageAnalysisWrapperPass::FunctionResourceInfo &FRI, MCContext &OutContext)
AMDGPUResourceUsageAnalysis gathers resource usage on a per-function granularity.
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition: MCSymbol.h:42
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Definition: SmallVector.h:574
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:55
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18