Skip to content

Commit 68919c9

Browse files
committed
Merge "Merge commit 'c897c13dde3b' into amd-staging" into amd-staging
2 parents dd0419e + fba30be commit 68919c9

File tree

2 files changed

+106
-0
lines changed

2 files changed

+106
-0
lines changed
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
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+
18+
#include "AMDGPUResourceUsageAnalysis.h"
19+
#include "MCTargetDesc/AMDGPUMCExpr.h"
20+
21+
namespace llvm {
22+
23+
class MCContext;
24+
class MCSymbol;
25+
class StringRef;
26+
class MachineFunction;
27+
28+
class MCResourceInfo {
29+
public:
30+
enum ResourceInfoKind {
31+
RIK_NumVGPR,
32+
RIK_NumAGPR,
33+
RIK_NumSGPR,
34+
RIK_PrivateSegSize,
35+
RIK_UsesVCC,
36+
RIK_UsesFlatScratch,
37+
RIK_HasDynSizedStack,
38+
RIK_HasRecursion,
39+
RIK_HasIndirectCall
40+
};
41+
42+
private:
43+
int32_t MaxVGPR = 0;
44+
int32_t MaxAGPR = 0;
45+
int32_t MaxSGPR = 0;
46+
47+
// Whether the MCResourceInfo has been finalized through finalize(MCContext
48+
// &). Should only be called once, at the end of AsmPrinting to assign MaxXGPR
49+
// symbols to their final value.
50+
bool Finalized = false;
51+
52+
void assignResourceInfoExpr(int64_t localValue, ResourceInfoKind RIK,
53+
AMDGPUMCExpr::VariantKind Kind,
54+
const MachineFunction &MF,
55+
const SmallVectorImpl<const Function *> &Callees,
56+
MCContext &OutContext);
57+
58+
// Assigns expression for Max S/V/A-GPRs to the referenced symbols.
59+
void assignMaxRegs(MCContext &OutContext);
60+
61+
public:
62+
MCResourceInfo() = default;
63+
void addMaxVGPRCandidate(int32_t candidate) {
64+
MaxVGPR = std::max(MaxVGPR, candidate);
65+
}
66+
void addMaxAGPRCandidate(int32_t candidate) {
67+
MaxAGPR = std::max(MaxAGPR, candidate);
68+
}
69+
void addMaxSGPRCandidate(int32_t candidate) {
70+
MaxSGPR = std::max(MaxSGPR, candidate);
71+
}
72+
73+
MCSymbol *getSymbol(StringRef FuncName, ResourceInfoKind RIK,
74+
MCContext &OutContext);
75+
const MCExpr *getSymRefExpr(StringRef FuncName, ResourceInfoKind RIK,
76+
MCContext &Ctx);
77+
78+
// Resolves the final symbols that requires the inter-function resource info
79+
// to be resolved.
80+
void finalize(MCContext &OutContext);
81+
82+
MCSymbol *getMaxVGPRSymbol(MCContext &OutContext);
83+
MCSymbol *getMaxAGPRSymbol(MCContext &OutContext);
84+
MCSymbol *getMaxSGPRSymbol(MCContext &OutContext);
85+
86+
/// AMDGPUResourceUsageAnalysis gathers resource usage on a per-function
87+
/// granularity. However, some resource info has to be assigned the call
88+
/// transitive maximum or accumulative. For example, if A calls B and B's VGPR
89+
/// usage exceeds A's, A should be assigned B's VGPR usage. Furthermore,
90+
/// functions with indirect calls should be assigned the module level maximum.
91+
void gatherResourceInfo(
92+
const MachineFunction &MF,
93+
const AMDGPUResourceUsageAnalysis::SIFunctionResourceInfo &FRI,
94+
MCContext &OutContext);
95+
96+
const MCExpr *createTotalNumVGPRs(const MachineFunction &MF, MCContext &Ctx);
97+
const MCExpr *createTotalNumSGPRs(const MachineFunction &MF, bool hasXnack,
98+
MCContext &Ctx);
99+
};
100+
} // namespace llvm
101+
102+
#endif // LLVM_LIB_TARGET_AMDGPU_AMDGPUMCRESOURCEINFO_H

revert_patches.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,3 +87,7 @@ Revert: breaks hipBlender*
8787
0e73bbd3450c [AMDGPU][PromoteAlloca] Don't stop when an alloca is too big to promote (#93466)
8888
contact: Pierre
8989
---
90+
Janek breaks aomp smoke red_bug_51. revert:
91+
c897c13dde3b [AMDGPU] Convert AMDGPUResourceUsageAnalysis pass
92+
---
93+

0 commit comments

Comments
 (0)