Skip to content

Commit 3c508bb

Browse files
committed
Factor out getAVGPRSAs*GPRsNum
Change-Id: Ia3b8507f95763079ee3c2224655990a299c8854d
1 parent 7361980 commit 3c508bb

File tree

1 file changed

+27
-12
lines changed

1 file changed

+27
-12
lines changed

llvm/lib/Target/AMDGPU/GCNRegPressure.h

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,24 @@ struct GCNRegPressure {
5757
return std::max(Value[VGPR] + Value[AVGPR], Value[AGPR]);
5858
}
5959

60+
inline static unsigned getAVGPRsAsVGPRsNum(unsigned NumArchVGPRs,
61+
unsigned NumAVGPRs,
62+
unsigned AddressableArchVGPR) {
63+
64+
return NumArchVGPRs < AddressableArchVGPR
65+
? std::min((AddressableArchVGPR - NumArchVGPRs), NumAVGPRs)
66+
: 0;
67+
}
68+
69+
inline static unsigned getAVGPRsAsAGPRsNum(unsigned NumArchVGPRs,
70+
unsigned NumAGPRs,
71+
unsigned NumAVGPRs,
72+
unsigned AddressableArchVGPR) {
73+
unsigned AVGPRsAsVGPRs =
74+
getAVGPRsAsVGPRsNum(NumArchVGPRs, NumAVGPRs, AddressableArchVGPR);
75+
return NumAVGPRs > AVGPRsAsVGPRs ? NumAVGPRs - AVGPRsAsVGPRs : 0;
76+
}
77+
6078
/// Returns the aggregated VGPR pressure, assuming \p NumArchVGPRs ArchVGPRs
6179
/// \p NumAGPRs AGPRS, and \p NumAVGPRs AVGPRs for a target with a unified
6280
/// VGPR file.
@@ -68,11 +86,10 @@ struct GCNRegPressure {
6886
// Until we hit the VGPRThreshold, we will assign AV as VGPR. After that
6987
// point, we will assign as AGPR.
7088
unsigned AVGPRsAsVGPRs =
71-
NumArchVGPRs < AddressableArchVGPR
72-
? std::min((AddressableArchVGPR - NumArchVGPRs), NumAVGPRs)
73-
: 0;
74-
unsigned AVGPRsAsAGPRs =
75-
NumAVGPRs > AVGPRsAsVGPRs ? NumAVGPRs - AVGPRsAsVGPRs : 0;
89+
getAVGPRsAsVGPRsNum(NumArchVGPRs, NumAVGPRs, AddressableArchVGPR);
90+
unsigned AVGPRsAsAGPRs = getAVGPRsAsAGPRsNum(
91+
NumArchVGPRs, NumAGPRs, NumAVGPRs, AddressableArchVGPR);
92+
NumAVGPRs > AVGPRsAsVGPRs ? NumAVGPRs - AVGPRsAsVGPRs : 0;
7693
return alignTo(NumArchVGPRs + AVGPRsAsVGPRs,
7794
AMDGPU::IsaInfo::getArchVGPRAllocGranule()) +
7895
NumAGPRs + AVGPRsAsAGPRs;
@@ -96,13 +113,11 @@ struct GCNRegPressure {
96113

97114
unsigned getVGPRTuplesWeight(unsigned AddressableArchVGPR) const {
98115
unsigned AVGPRsAsVGPRs =
99-
Value[TOTAL_KINDS + VGPR] < AddressableArchVGPR
100-
? std::min(AddressableArchVGPR - Value[TOTAL_KINDS + VGPR],
101-
Value[TOTAL_KINDS + AVGPR])
102-
: 0;
103-
unsigned AVGPRsAsAGPRs = Value[TOTAL_KINDS + AVGPR] > AVGPRsAsVGPRs
104-
? Value[TOTAL_KINDS + AVGPR] - AVGPRsAsVGPRs
105-
: 0;
116+
getAVGPRsAsVGPRsNum(Value[TOTAL_KINDS + VGPR],
117+
Value[TOTAL_KINDS + AVGPR], AddressableArchVGPR);
118+
unsigned AVGPRsAsAGPRs = getAVGPRsAsAGPRsNum(
119+
Value[TOTAL_KINDS + VGPR], Value[TOTAL_KINDS + AGPR],
120+
Value[TOTAL_KINDS + AVGPR], AddressableArchVGPR);
106121

107122
return std::max(Value[TOTAL_KINDS + VGPR] + AVGPRsAsVGPRs,
108123
Value[TOTAL_KINDS + AGPR] + AVGPRsAsAGPRs);

0 commit comments

Comments
 (0)