LLVM 24.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:
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 // Normalize a whole cyclic max/OR assignment. Fold constants, omit the
64 // symbol currently being assigned, and keep each unresolved outgoing symbol
65 // once. LocalValue is retained even if an unfamiliar shape needs a fallback.
66 const MCExpr *flattenedCycleExpr(MCSymbol *Sym, const MCExpr *Expr,
67 int64_t LocalValue, ResourceInfoKind RIK,
69 MCContext &OutContext);
70
71public:
72 MCResourceInfo() = default;
73 void addMaxVGPRCandidate(int32_t candidate) {
74 MaxVGPR = std::max(MaxVGPR, candidate);
75 }
76 void addMaxAGPRCandidate(int32_t candidate) {
77 MaxAGPR = std::max(MaxAGPR, candidate);
78 }
79 void addMaxSGPRCandidate(int32_t candidate) {
80 MaxSGPR = std::max(MaxSGPR, candidate);
81 }
82 void addMaxNamedBarrierCandidate(int32_t candidate) {
83 MaxNamedBarrier = std::max(MaxNamedBarrier, candidate);
84 }
85
87 MCContext &OutContext);
89 MCContext &Ctx);
90
91 void reset();
92
93 // Resolves the final symbols that requires the inter-function resource info
94 // to be resolved.
95 void finalize(MCContext &OutContext);
96
101
102 /// AMDGPUResourceUsageAnalysis gathers resource usage on a per-function
103 /// granularity. However, some resource info has to be assigned the call
104 /// transitive maximum or accumulative. For example, if A calls B and B's VGPR
105 /// usage exceeds A's, A should be assigned B's VGPR usage. Furthermore,
106 /// functions with indirect calls should be assigned the module level maximum.
107 ///
108 /// When link-time object linking is enabled, skip all call-transitive
109 /// propagation and emit concrete per-function values for every resource
110 /// symbol. Cross-TU aggregation is then the linker's responsibility.
112 const MachineFunction &MF,
114 MCContext &OutContext);
115
116 const MCExpr *createTotalNumVGPRs(const MachineFunction &MF, MCContext &Ctx);
117 const MCExpr *createTotalNumSGPRs(const MachineFunction &MF, bool hasXnack,
118 MCContext &Ctx);
119};
120} // namespace llvm
121
122#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:84
Base class for the full range of assembler expressions which are needed for parsing.
Definition MCExpr.h:31
MCResourceInfo()=default
MCSymbol * getMaxNamedBarrierSymbol(MCContext &OutContext)
void addMaxSGPRCandidate(int32_t candidate)
const MCExpr * getSymRefExpr(StringRef FuncName, ResourceInfoKind RIK, MCContext &Ctx)
MCSymbol * getMaxSGPRSymbol(MCContext &OutContext)
void addMaxNamedBarrierCandidate(int32_t candidate)
MCSymbol * getMaxAGPRSymbol(MCContext &OutContext)
const MCExpr * createTotalNumVGPRs(const MachineFunction &MF, MCContext &Ctx)
void addMaxAGPRCandidate(int32_t candidate)
MCSymbol * getMaxVGPRSymbol(MCContext &OutContext)
const MCExpr * createTotalNumSGPRs(const MachineFunction &MF, bool hasXnack, MCContext &Ctx)
MCSymbol * getSymbol(StringRef FuncName, ResourceInfoKind RIK, MCContext &OutContext)
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...
Represent a constant reference to a string, i.e.
Definition StringRef.h:56
This is an optimization pass for GlobalISel generic memory operations.
AMDGPUResourceUsageAnalysisImpl::SIFunctionResourceInfo FunctionResourceInfo